question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Auto detection of Jest version not working in 24.1.0

See original GitHub issue

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:

[Info  - 23:45:50] ESLint server is starting
[Info  - 23:45:50] ESLint server running in node v12.14.1
[Info  - 23:45:50] ESLint server is running.
[Info  - 23:45:51] ESLint library loaded from: PROJECT_PATH/node_modules/eslint/lib/api.js
[Info  - 23:45:51] 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 PROJECT_PATH/.eslintrc.js

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:

module.exports = {
  env: {
    commonjs: true,
    es2021: true,
    node: true,
  },
  extends: [
    'plugin:jest/recommended',
    'airbnb-base',
  ],
  parserOptions: {
    ecmaVersion: 12,
  },
  plugins: [
    'jest',
  ],
  rules: {
  },
  settings: {
    jest: {
      version: 26,
    },
  },
};

Here are also the eslint* packages I am using:

{
  "devDependencies": {
    "eslint": "^7.11.0",
    "eslint-config-airbnb-base": "^14.2.0",
    "eslint-plugin-import": "^2.22.1",
    "eslint-plugin-jest": "^24.1.0"
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10

github_iconTop GitHub Comments

3reactions
fschaefflercommented, Dec 5, 2020

A workaround for this issue is to specify the version via latest as most ESLint versions are back-wards compatible in the .eslintrc.

"settings": {
    "jest": {
        "version": "latest"
    }
}
0reactions
WORMSScommented, Aug 10, 2021

It seems, another fix for this is

const jestPath = require.resolve('jest/package.json', {
      paths: [process.cwd(), __dirname],
    });

blank finds C:\Development\alloy-web2\projects\web-core-unit-test\node_modules\jest\package.json paths: [process.cwd(), __dirname] finds C:\Development\alloy-web2\projects\web-core-unit-test\node_modules\jest\package.json

So they both match now. Where as before, it thrown an error.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest passing tests but --covering option not picking up files
I have tested covering with some simple examples found on github and those were working so the problem is not from my environment....
Read more >
How to resolve create-react-app babel-jest Error. - Medium
1)Manually installing incompatible versions is known to cause hard-to-debug issues.If you would prefer to ignore this check, add ...
Read more >
jest | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >
babel-jest - NPM Package Overview - Socket.dev
Jest plugin to use babel for transformation. Version: 24.9.0 was published by scotthovestadt. Start using Socket to analyze babel-jest and ...
Read more >
Test with Jest - devmio
Today there is hardly a developer who does not have these design patterns in mind and automatically applies them in his daily work....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found