-
Notifications
You must be signed in to change notification settings - Fork 238
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
Support @jest/globals
#556
Comments
Hmmm this should mainly be a matter of inverting I'll have a toy around sometime over the weekend. In saying that... On the one hand arguably we don't have to do much to support them because as long as the globals are around (and doubly so if they're the default) then we always have to assume what could be the globals are the globals (aka what we do now).
So we'd have to have a plugin setting for configuring if the global export is used 🤷 |
I think we should check for the globals regardless - if the user don't want the globals to be used they should remove the global config. Only reason for introducing a plugin config would be for perf optimization - skipping searching the scope for the global. I doubt that'd make a big difference, though. But yeah, in theory this should "just" be tweaking |
I don't get what you mean - the problem is that we can't check if globals have been configured from within rules, so we have no way to magically detect if the user is wanting to use i.e we figure out that I guess maybe we might be able to the actually a better way of framing it:
We can't detect that, as we don't have access to the global config at lint-time from within the rules. We only get passed the |
We shouldn't care what globals are configured for ESLint, we should always search for the globals Jest puts into the environment regardless of what ESLint considers as globals. |
Oh are you saying that we should implementing that behaviour, "and also btw" we'll need amend it to support when importing from |
Yup! I think that's reasonable |
This has shipped in 25.5. Messaging in https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/no-jest-import.md should probably account for this new package |
Apologies I havn't had the time to do much on this, but agree updating that documentation would be a good first step. |
Nothing to apologize for! That's just the way of FOSS 🙂 |
I'm not sure if this is related, (if not, i can start a new issue) but I'm finding that eslint isn't finding the globals defined in my ./test/setup.js import Enzyme, { configure, shallow, mount, render } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
configure({ adapter: new Adapter() });
// Make Enzyme functions available in all test files without importing
global.shallow = shallow;
global.render = render;
global.mount = mount;
export { shallow, mount, render };
export default Enzyme; But when I try to use
I've tried the following with no change: env: {
"jest/globals": true,
}, Is there some setting to configure this? |
You can tell ESLint about additional globals using the |
When this lands we should also have some way of not sticking eslint-plugin-jest/src/index.ts Line 57 in d16b84c
|
@SimenB just re-reviewing this issue - could you help me clarify what changes we are actually wanting to make? I know we'll need to adjust I think my main question I'd like to confirm is do you think we should be thinking about adjusting our I'm wondering if it's actually worth it, because it'd mean it would be harder to alias any of the methods (which arguably I think it would also make things more complicated when we try to have more support for custom names & settings (which I'm trying to do but am blocked somewhat by the current really poor way ESLint merges arrays, which has been fixed in the new config system). |
Jest will not (in the foreseeable future) change our defaults here (or even recommendations). Way too much code is written in the wild for that churn to be worth it. The big wrinkle here is native ESM - that has to use
Yes, I think so. Looking at the logic in Jest's babel plugin might help: https://github.com/facebook/jest/blob/03f4a6967b42ca390f036a8264ca65284acb27d3/packages/babel-plugin-jest-hoist/src/index.ts#L202-L234 Different AST and maybe helpers, but still |
🎉 This issue has been resolved in version 26.2.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
See jestjs/jest#9801.
We need to support finding
expect
,test
,it
etc when imported from@jest/globals
. Should be relatively simple for ESM syntax, possibly a bit more pain forrequire
. We need to support aliasing as wellimport { test as testFunction } from '@jest/globals'
Note that the feature hasn't been released yet (blocked by jestjs/jest#9806), but we can add support before it lands.
/cc @G-Rath
The text was updated successfully, but these errors were encountered: