-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix line number preservation for Jest transform (#608)
This is a follow-up from #540 (review) For the Jest transform, rather than actually moving the `jest.mock` invocations, it's better to transform them in-place and wrap them in functions, then call those functions from the top of the file. That guarantees that line numbers are preserved before and after so that the source map can be correct. I also added the jest transform to the website so that it's easier to manually test. It may be possible to hook up the ts-jest version of the transform to the TypeScript output on the website, but I left that off for now. To test, I made a simple Jest project and mocked a function that returns a number. Without the jest tranform, putting the mock call below the import doesn't work, and with the jest transform it works. Before this change, breakpoints further down in the file (e.g. in the test) didn't work because line numbers were wrong. After this change, breakpoints work. I also manually tested this line to ensure that the chaining transform doesn't break other uses of the `jest` object: ```javascript console.log(jest.spyOn({foo() {}}, 'foo').getMockName()); ```
- Loading branch information
1 parent
6277a20
commit 04cb7c4
Showing
6 changed files
with
89 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters