-
Notifications
You must be signed in to change notification settings - Fork 240
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
Auto detection of Jest version not working in 24.1.0 #686
Comments
@RobTheFiveNine can you provide more detail on the structure of your project - do you have 24 made |
Sure - the version of Jest I am using is Here is the full file (with unrelated metadata like descriptions etc. removed): {
"devDependencies": {
"eslint": "^7.11.0",
"eslint-config-airbnb-base": "^14.2.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^24.1.0",
"jest": "^26.5.2"
},
"dependencies": {
"dotenv": "^8.2.0",
"mongoose": "^5.10.9",
"uuid": "^8.3.1"
},
"jest": {
"setupFilesAfterEnv": [
"<rootDir>/jest.setup.js"
],
"testEnvironment": "node"
}
} Edit: also, the package manager I am using is yarn (in case it is checking any lock files) |
I think I have found what is causing it (and not sure if this is something that can be resolved, may need to be written off as an environmental issue). On line 45 of My project structure is like this:
And the folder I have open in vscode is Edit: Yup, I just added some logging into my copy of eslint-plugin-jest to print the CWD when the error is being thrown, and the CWD at the time the error is thrown is in the parent directory of |
Yeah, this looks like the case where you'll need to provide the version of jest explicitly, as it looks for jest in the folder eslint is being run from, which in this case is In your setup, everyone (including the vscode extension) is operating correctly: you've opened You'll find similar problems with things like if you have two different versions of You can resolve this by using the mono-repo pattern of having a top-level |
I'm going to close this off as it's not a bug in our end. |
That's a good point - I hadn't considered that if there's multiple copies of eslint that it would need to ultimately just pick one to use. Thanks for the tip on the mono-repo config; I usually split into separate repos, which probably explains how I've never run into this before! |
A workaround for this issue is to specify the version via
|
@fschaeffler that'll cause it to not error, but also effectively disables the rule because it's not supported; in fact, ideally we'd error on that so I wouldn't rely on it. |
This fixes a problem where format-on-save had stopped working for me, probably after updating vscode-eslint. I'd been getting this error: ``` Error: Error while loading rule 'jest/no-deprecated-functions': Unable to detect Jest version - please ensure jest package is installed, or otherwise set version explicitly Occurred while linting /Users/chrisbobbe/dev/zulip-mobile/src/compose/ComposeMenu.js at detectJestVersion (/Users/chrisbobbe/dev/zulip-mobile/node_modules/eslint-plugin-jest/lib/rules/no-deprecated-functions.js:38:9) at create (/Users/chrisbobbe/dev/zulip-mobile/node_modules/eslint-plugin-jest/lib/rules/no-deprecated-functions.js:61:256) [...] ``` Now I don't get that error, and format-on-save works again. See these issues: - jest-community/eslint-plugin-jest#686 - microsoft/vscode-eslint#1145
This fixes a problem where format-on-save had stopped working for me, probably after updating vscode-eslint. I'd been getting this error: ``` Error: Error while loading rule 'jest/no-deprecated-functions': Unable to detect Jest version - please ensure jest package is installed, or otherwise set version explicitly Occurred while linting /Users/chrisbobbe/dev/zulip-mobile/src/compose/ComposeMenu.js at detectJestVersion (/Users/chrisbobbe/dev/zulip-mobile/node_modules/eslint-plugin-jest/lib/rules/no-deprecated-functions.js:38:9) at create (/Users/chrisbobbe/dev/zulip-mobile/node_modules/eslint-plugin-jest/lib/rules/no-deprecated-functions.js:61:256) [...] ``` Now I don't get that error, and format-on-save works again. See these issues: - jest-community/eslint-plugin-jest#686 - microsoft/vscode-eslint#1145
It seems, another fix for this is const jestPath = require.resolve('jest/package.json', {
paths: [process.cwd(), __dirname],
});
So they both match now. Where as before, it thrown an error. |
eslint-config-preactがjestの設定に依存していて、その中のひとつがjestのバージョンを読もうとする。 今回は入れないのでdisableにする。 preactjs/eslint-config-preact#19 jest-community/eslint-plugin-jest#686
When using version 23.10.0 and extending
plugin:jest/recommended
, eslint loads without issue.When using version 24.1.0, the following output can be seen:
After explicitly setting the version, as per the error message, eslint runs without issue; however, it seems like it's a bug (unless version 23.x wasn't using any of the rules that required the version detection?).
If it helps, see below my
.eslintrc.js
file:Here are also the eslint* packages I am using:
The text was updated successfully, but these errors were encountered: