-
Notifications
You must be signed in to change notification settings - Fork 143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jest plugin doesn't support inline snapshots #667
Comments
Hi @fdc-viktor-luft , thanks for flagging, I just tried it out and I agree that it's an issue. It looks like this was probably caused by #661 , where I changed the Jest plugin to include a source map as part of the output. I just tried downgrading to From my digging so far, it looks like here's what's happening: For some background, Sucrase is intentionally careful to have each line of output exactly match the same line of input, so e.g. line 53 in the transformed code is line 53 in the source code and stack traces give helpful results even if you haven't set up source maps. Originally, Sucrase didn't include source maps at all because they weren't necessary, especially if you're only care about line numbers (e.g. when setting debugger breakpoints). However, some tools like WebStorm want to see some source map for transformed code, or else they don't let you set breakpoints at all (because they assume the line number would be wrong). To help support these cases, Sucrase is able to generate a simple source map where the start of each line in the output file is mapped to the start of that same line in the input file, basically an "identity" source map. In order for Jest's inline snapshot feature to work, it needs to know where it can write the snapshot. From my digging so far, it looks like it works by catching the exception and using the stack trace information to figure out the line and column where the updated snapshot text should be placed. In order for the stack trace information to work right, Jest automatically uses the I'm not totally sure on the best fix, but a few ideas come to mind:
Downgrading the Jest plugin certainly should work as a stopgap, but I can take a look at the |
This is now fixed with #759 (an implementation of the third bullet point in my previous comment), just released in Sucrase 3.32.0. |
Issue
When using
expect(foo).toMatchInlineSnapshot()
in some test suite, jest complains in the moment it tries to inline the snapshot at the correct position of the code with:Jest: Couldn't locate all inline snapshots.
Relations
The issue is very likely related to jestjs/jest#6744.
Further investigations
expect(foo).toMatchSnapshot()
works without any problems (since Jest doesn't mutate the original code)expect(foo).toMatchInlineSnapshot(`whatever`)
works until you would tell Jest to update the snapshotEnvironment
Package versions
Node version
16.13.0
The text was updated successfully, but these errors were encountered: