Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eslint jest/globals environment key unknown

Tags:

eslint

jestjs

I have a custom eslint-config that has several plugins for various packages, including jest. I have the main set to an index which just extends other files.

Long story I have a jest config file. That looks like.

module.exports = {
    plugins: ['jest'],
    rules: {
        'jest/no-disabled-tests': 'warn',
        'jest/no-focused-tests': 'error',
        'jest/no-identical-title': 'error',
        'jest/valid-expect': 'error',
        'jest/no-alias-methods': 'off',
        'jest/no-jest-import': 'error',
        'jest/no-large-snapshots': ['warn', {maxSize: 300}],
        'jest/no-test-prefixes': 'error',
        'jest/prefer-to-contain': 'warn',
        'jest/prefer-to-have-length': 'warn',
        'jest/valid-describe': 'error',
        'jest/valid-expect-in-promise': 'error',
        'jest/consistent-test-it': 'off',
        'jest/lowercase-name': 'off',
        'jest/no-hooks': 'off',
        'jest/no-jasmine-globals': 'off',
        'jest/no-test-callback': 'off',
        'jest/prefer-expect-assertions': 'off',
        'jest/prefer-to-be-null': 'off',
        'jest/prefer-to-be-undefined': 'off',
        'jest/require-tothrow-message': 'off',
        'jest/expect-expect': 'off',
        'jest/no-test-return-statement': 'off',
        'jest/prefer-inline-snapshots': 'off',
        'jest/prefer-strict-equal': 'off',
        'jest/prefer-spy-on': 'off',
        'jest/prefer-todo': 'warn',
        'jest/prefer-called-with': 'error',
        'jest/no-truthy-falsy': 'off',
        'jest/no-empty-title': 'error',
        'jest/no-mocks-import': 'error',
        'jest/no-commented-out-tests': 'warn',
    },
    env: {
        'jest/globals': true,
    },
}

When running a lint task I keep getting the error Environment key "jest/globals" is unknown. I've traced the config-validator as far as I can understand it but nothing jumps out. There are no open/closed issues on the eslint-plugin-jest board about this and I can't find anyone else with this same error.

Also for an added bonus I also have cypress plugin also installed which itself has a environment option cypress/globals: true which also throws the same error.

Has anyone encountered this and know why (in the last month or so) this has started happening. Note: I have had this config for some time now and this just started happening.

Edit: I just downgraded to eslint^6.1.0 and this issue is no longer present. Something between 6.1.0 and 6.4.0 is causing this issue.

like image 437
JeffBaumgardt Avatar asked Sep 23 '19 15:09

JeffBaumgardt


2 Answers

Follow this guide:

https://www.npmjs.com/package/eslint-plugin-jest

Basics is: npm i --save-dev eslint-plugin-jest

Add this to your .eslintrc file:

"plugins": ["jest"]

Then your env property "jest/globals": true should work.

like image 67
Ogglas Avatar answered Oct 12 '22 04:10

Ogglas


Putting it in extends solved this issue for me.

...
"extends": ["eslint:recommended", "plugin:jest/recommended"],
...
like image 19
toonsend Avatar answered Oct 12 '22 03:10

toonsend