-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Inline Snapshots with non literal can't be found #6744
Comments
Looking into it. If you change the test to say |
Can't reproduce, even with an e2e test: |
Hmm. I wonder why I was hitting this in our test suite at Facebook then with that same error Do you have any debugging recommendations? |
You want to determine why this line is not matching. It could be related to source maps, or a flow parser bug reporting an incorrect location for an AST node. |
* upstream/master: (122 commits) fix: don't report promises as open handles (jestjs#6716) support serializing `DocumentFragment` (jestjs#6705) Allow test titles to include array index (jestjs#6414) fix `toContain` suggest to contain equal message (jestjs#6810) fix: testMatch not working with negations (jestjs#6648) Add test cases for jestjs#6744 (jestjs#6772) print stack trace on calls to process.exit (jestjs#6714) Updates SnapshotTesting.md to provide more info. on snapshot scope (jestjs#6735) Mark snapshots as obsolete when moved to an inline snapshot (jestjs#6773) [Docs] Clarified the use of literal values as property matchers in toMatchSnapshot() (jestjs#6807) Update CHANGELOG.md (jestjs#6799) fix changelog entry that is not in 23.4.2 (jestjs#6796) Fix --coverage with --findRelatedTests overwriting collectCoverageFrom options (jestjs#6736) Update testURL default value from about:blank to localhost (jestjs#6792) fix: `matchInlineSnapshot` when prettier dependencies are mocked (jestjs#6776) Fix retryTimes and add e2e regression test (jestjs#6762) Release v23.4.2 Docs/ExpectAPI: Correct docs for `objectContaining` (jestjs#6754) chore(packages/babel-jest) readme (jestjs#6746) docs: noted --coverage aliased by --collectCoverage (jestjs#6741) ...
works ( 1 snapshot updated. )
doesn't work ( Jest: Couldn't locate all inline snapshots. ) |
Debugging where @azz indicated I found the column value to be the mismatch. Changing the config to use tabWidth 2 fixed this so looks like generator is not picking up values from the prettier config in my case tabWidth. |
I just ran into this again with:
Adding a
which points to the On this line:
It looks like that data flows in from this code: https://github.com/facebook/jest/blob/master/packages/jest-snapshot/src/State.js#L93-L95 It is creating a
I'm not familiar with what is responsible for the line numbers that get calculated for error stack frames so my debugging ends there. Any ideas? |
I'm also getting the error The interesting thing is that the inline snapshot works when rendering a component with |
Sourcemaps must be setup correctly, then it's https://github.com/evanw/node-source-map-support |
I'm still experiencing this issue on a fresh install of I've only added the ...
"jest": {
"preset": "react-native",
"transform": {
"^.+\\.(js)$": "<rootDir>/node_modules/react-native/jest/preprocessor.js"
}
}
|
@karlmarxlopez mind setting up a quick repository we could pull down and check? |
@SimenB I don't have a minimal repro yet. I can reproduce it in react's codebase though:
Produces
Applying diff --git a/packages/react-devtools-shared/src/__tests__/treeContext-test.js b/packages/react-devtools-shared/src/__tests__/treeContext-test.js
index 3f97970d63..55265dd911 100644
--- a/packages/react-devtools-shared/src/__tests__/treeContext-test.js
+++ b/packages/react-devtools-shared/src/__tests__/treeContext-test.js
@@ -943,7 +943,7 @@ describe('TreeListContext', () => {
);
utils.act(() => TestRenderer.create(<Contexts />));
- expect({state, store}).toMatchInlineSnapshot();
+ expect({ state: state, store: store }).toMatchInlineSnapshot();
selectNextErrorOrWarning();
let statefulStore = {state, store}; Fixes the issue. So it looks like the stack trace is based on the code after transpilation (particularly after |
Finding myself here again, having gotten burned by this issue while trying to rewrite some other React DevTools tests to use inline snapshots. They're so much better (when they work!) |
As far as I can tell the cause of #6744 (comment) is missing source-maps. React's jest config has a custom preprocessor that transpiles the files without source maps. So I could fix #6744 (comment) with diff --git a/scripts/jest/preprocessor.js b/scripts/jest/preprocessor.js
index f57005c940..32836141a3 100644
--- a/scripts/jest/preprocessor.js
+++ b/scripts/jest/preprocessor.js
@@ -86,7 +86,10 @@ module.exports = {
return babel.transform(
src,
Object.assign(
- {filename: path.relative(process.cwd(), filePath)},
+ {
+ filename: path.relative(process.cwd(), filePath),
+ sourceMaps: isTestFile ? 'inline' : false,
+ },
babelOptions,
{
plugins, But I don't understand how jest creates accurate frames for other cases. For example |
What helped for me with Jest 27 and typescript is to add
|
I'm seeing this problem as well: Jest: 27.4.7 repo and branch with error : https://github.com/rkesters/typescript-json-validator/tree/rkesters/deps2 run: npx jest index I have sourceMap set to true. Error Message: FAIL src/tests/index.test.ts
|
@SimenB can you look at my comment? |
Another repro with the same symptoms: https://github.com/eps1lon/types-react-codemod/tree/jest-inline-snapshot-repro describe("transform deprecated-react-type", () => {
test("named import", () => {
expect(`
import { ReactType } from 'react';
ReactType;
`).toMatchInlineSnapshot(`
"import { ElementType } from 'react';
ElementTye;"
`);
});
}); Here the fix is easier by removing "resolutions": {
"source-map": "^0.8.0-beta.0"
}, from the package.json. The resolution is required to get a fix for mozilla/source-map#432 i.e. make So it seems like this issue is caused by source-map. It's not really about a mismatch as far as I can tell since |
That sounds like nodejs/node#42638, and separate from OP |
Not really since their beta resolves that particular issue. However, forcing their beta as the single version in the dependency tree will break jests inline snapshots. |
source-map being broken with global fetch is that. However, Jest doesn't pull in the broken 0.7 version, so shouldn't matter. At least I think so 😅 What's the dependency chain in your repo? |
Upgrading to jest 28 allowed removing the source-map beta resolution. With jest 27 I got "Error: You must provide the URL of lib/mappings.wasm by calling SourceMapConsumer.initialize({ 'lib/mappings.wasm': ... }) before using SourceMapConsumer" in eps1lon/types-react-codemod@ So Jest 28 is fine. Jest 27 + Node 18 requires source-map beta which breaks --updateSnapshot with inline snapshots. |
If you use v8 coverage provider, jest@27 is broken with global Babel coverage (the default) should work fine in either version |
@rkesters the branch from #6744 (comment) seems to be deleted - do you still have it somewhere? I somehow missed a reproduction being posted, sorry! 😬 |
This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days. |
This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
🐛 Bug Report
When I try to add a test with an inline snapshot:
I get this error:
I can't repro this in repl.it because that version does not have inline snapshots yet:
I cloned the github repo and added a test to inline_snapshots.test.js
and this reproes the issue:
The text was updated successfully, but these errors were encountered: