vscode-jest icon indicating copy to clipboard operation
vscode-jest copied to clipboard

vscode-jest not finding snapshot when using custom jest snapshotResolver

Open tostringtheory opened this issue 5 years ago • 6 comments
trafficstars

Environment

  1. node -v: v12.14.0
  2. npm -v: 6.13.4
  3. npm ls jest or npm ls react-scripts (if you haven’t ejected): -- [email protected]
  4. your vscode-jest settings if customized:
    • jest.pathToJest? n/a
    • jest.pathToConfig? n/a
    • anything else that you think might be relevant?

in jest.config.js:

snapshotResolver: "<rootDir>/scripts/testing/snapshot-resolver.js"

in scripts/testing/snapshot-resolver.js:

module.exports = {
	testPathForConsistencyCheck: "some/example.spec.js",

	resolveSnapshotPath: (testPath, snapshotExtension) => testPath.replace(/\.spec\.([tj]sx?)/, `${snapshotExtension}.$1`),

	resolveTestPath: (snapshotFilePath, snapshotExtension) => snapshotFilePath.replace(snapshotExtension, ".spec")
};
  1. Operating system: Windows 10 v2004 build 19041.264

Prerequisite

  • are you able to run jest test from command line? Yes
  • how do you run your tests from command line? (for example: npm run test or node_modules/.bin/jest) npm run test, which executes: jest

Steps to Reproduce

Open repository: https://github.com/tostringtheory/vscode-jest-snapshot-bug Run yarn install | npm install

If you run yarn test / npm run test, then the test succeeds, and does not fail to resolve the snapshot. However, while the vscode-jest extension sees the test was successful, it still reports that the snapshot is missing:

image

Relevant Debug Info

Enabled the "jest.debugMode", yet there were no errors/issues. I tried to determine which repository would be the owner, but couldn't exactly see where the issue would lie. I see that the jest-community/jest-editor-support seems to reference the necessary property (snapshotResolver) in the project config. However, the vscode extension doesn't appear that it even looks for snapshots (at least when I searched the repository), so I'm not even sure that the issue belongs here. Instead of spinning my wheels hunting, I figured I'd put in an issue and see if someone with more experience/knowledge on this structure could identify the culprit.

Expected Behavior

The same functionality with default snapshot resolution in vscode-jest works with a custom snapshot-resolver. IE, the snapshot would not indicate that it is missing, and CodeLens would be able to peek to the definition.

Actual Behavior

The method call is decorated with a "snapshot missing" statement, even though the test is succeeding.

tostringtheory avatar May 23 '20 18:05 tostringtheory

Just checking in on this, could someone at least point me to whether this is an issue with this extension or the tools it builds upon? As mentioned above I tried to hunt it down but couldn't find it in my initial searches if this was relevant to this repository or the jest IDE integrations repository. I'm happy to create a PR myself in a repo resolving this.

tostringtheory avatar Jun 11 '20 20:06 tostringtheory

@tostringtheory it does look like it is a problem on our end, a quick investigate led me to believe that the SnapshotCodeLensProvider didn't pass jest config to the jest-editor-support that could find snapshot via snapshotResolver...

We have stopped parsing jest config a while back thinking there is really no need for it. But looks like you just found one use case! Maybe we need to revisit this decision 🤔 ...

connectdotz avatar Jun 12 '20 18:06 connectdotz

@connectdotz - ahh, that's why I was confused. I thought from what I was looking at in the jest-editor-support package that it should handle it, and didn't see anything specific to vscode-jest that needed it (looked like it was just consuming jest-editor-support). Didn't dawn on me that the issue would be not passing configuration. You appear to be correct too, the config looks to be the 3rd argument to the ctor.

I just checked in the SnapshotCodeLensProvider commit history, and actually don't see that the jest.pathToConfig was ever even passed to the Snapshot object.

Would you want me to try and take a crack at a PR for this? I've not done vscode extensions work so I might have some slight environment work to prep, but it looks trivial, unless there's caveat's i'm not aware of (dragons?).

tostringtheory avatar Jun 15 '20 20:06 tostringtheory

@tostringtheory sorry for the late reply, great spirit 👍 , yes I am open for discussing this fix ... just vaguely remembered that there were quite a few issues surrounding getting config from jest before, but maybe something has changed and it won't hurt to have a fresh perspective to reexamine this again.

connectdotz avatar Jul 02 '20 15:07 connectdotz

Any progress on this? I am facing the very same issue

luca-borrione avatar Jun 29 '21 22:06 luca-borrione

Having the same issue without a custom snapshotResolver here. Debug mode is not much help, only get errors like this ones:

image image

Yimiprod avatar Mar 06 '23 10:03 Yimiprod