-
-
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
Add configuration to configure Jest test methods in global environment #10481
Comments
For the time being I have added an ESLint configuration to give lint errors when Jest globals are used. I'm also using eslint-plugin-jest, but that doesn't have such a rule as far as I've seen. rules: {
'no-restricted-globals': [
'error',
/**
* From Jest global environment.
* https://github.com/facebook/jest/blob/v26.4.2/packages/jest-globals/src/index.ts#L16-L27
*/
'it',
'test',
'fit',
'xit',
'xtest',
'describe',
'xdescribe',
'fdescribe',
'beforeAll',
'beforeEach',
'afterEach',
'afterAll',
],
}, |
Just pushed up the branch I had locally. Rebased it, but no other changes since April. I don't really remember the state of it. Missing tests and docs, but beyond that. I don't even remember if it runs correctly 😛 https://github.com/SimenB/jest/tree/no-inject-globals |
As for the eslint plugin, we might wanna consider not adding to globals by default: jest-community/eslint-plugin-jest#556 (comment) |
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. |
🚀 Feature Proposal
Add configuration to configure whether Jest test methods and objects are put into the global environment.
Motivation
Please outline the motivation for the proposal.
The
@jest/globals
package was added in #9801, but Jest still sets the globals, which isn't needed when using@jest/globals
. PR #9306 described a proposal and some work to add a configuration (noJestGlobals
) that allows users to explicitly disable Jest adding to the globals. This is a way of forcing the use of@jest/globals
and thus ensuring that the functions are explicitly imported and can't accidentally be used in other (non-test) code for example. I've read most of the conversation sin #9306, #9801 and some of the referenced tickets and didn't find an issue that is tracking this feature.I don't know how hard this is to implement but I'd be happy to help on this even though I have zero knowledge/familiarity with the Jest code base.
Example
Please provide an example for how this feature would be used.
Configuration added.
addGlobalEnvironment
[boolean]Default:
true
Indicates whether Jest test methods and objects are put into the global environment. By setting this to
false
, explicit import, likeimport { describe, test } from '@jest/globals
are required to use the Jest test methods and objects.Pitch
Why does this feature belong in the Jest core platform?
To allow users to consistently require explicit Jest imports.
The text was updated successfully, but these errors were encountered: