-
Notifications
You must be signed in to change notification settings - Fork 239
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
feat: support @jest/globals
#1094
Conversation
Yay! Will review tomorrow (currently at a concert) if you want @G-Rath. I see it's draft and red ci, so might not be ready for review? |
Yeah it's not quite ready for a complete review - I tagged you so you knew it was coming incase you were planning on doing a new major soon (since Jest v28 is out) and we spoke about dropping the Now that I know you've seen it, I'll remove your review and re-add once it is actually ready for review 😄 |
Haha, sounds good! |
(no offense, but a Tool concert is more fun than code 🤘) |
@SimenB I'm getting some weird behaviour when trying to generate a coverage report for
If I run the whole test suite with coverage ( I can reproduce this on |
3e1ac37
to
660c04d
Compare
The changing path is jestjs/jest#7176, would be great to fix that. Unsure of the error, tho... |
660c04d
to
3601ceb
Compare
Ok I think this should ready for review - couple of things:
Having written all that up, I think really this is only half of the work required to really close #556, because supporting This actually makes me think it might be best to go with my original plan of trying to land support for "true" global scope/reference first, and then follow it up with adding support for @SimenB what do you think? I'm happy to split this up into a couple of different PRs and also land it via |
huh maybe we don't have any rules that actually check for those - just ones that suggest using them.... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fantastic stuff! 👏
const hooks = ['beforeAll', 'beforeEach', 'afterEach', 'afterAll']; | ||
|
||
ruleTester.run('hooks', rule, { | ||
valid: [...hooks, 'beforeAll.each(() => {})'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
beforeAll.each
isn't valid. But I guess the eslint plugin can just ignore it
} | ||
|
||
const describeImportDefAsImport = ( | ||
def: TSESLint.Scope.Definitions.ImportBindingDefinition, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def: TSESLint.Scope.Definitions.ImportBindingDefinition, | |
definition: TSESLint.Scope.Definitions.ImportBindingDefinition, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A little on the fence about this - I went with def
because that's what the underlying runtime property that's passed in is called
}; | ||
|
||
const describeVariableDefAsImport = ( | ||
def: TSESLint.Scope.Definitions.VariableDefinition, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def: TSESLint.Scope.Definitions.VariableDefinition, | |
definition: TSESLint.Scope.Definitions.VariableDefinition, |
* If it's neither of these, `null` is returned to indicate that the definition | ||
* is not describable as an import of any kind. | ||
*/ | ||
const describePossibleImportDef = (def: TSESLint.Scope.Definition) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const describePossibleImportDef = (def: TSESLint.Scope.Definition) => { | |
const describePossibleImportDef = (definition: TSESLint.Scope.Definition) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great stuff 👍
e09c7eb
to
8660f44
Compare
# [26.2.0](v26.1.5...v26.2.0) (2022-05-13) ### Features * support `@jest/globals` ([#1094](#1094)) ([84d7a68](84d7a68))
🎉 This PR is included in version 26.2.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Turns out this isn't completely right because
So while the logic is correct, it only works correctly in
whereas in the rules we're doing:
I think for now I'm just going to replace all uses of |
Also @SimenB I just realised we should be doing this for |
Yeah, all globals plus |
Yeah but I'm pretty sure these + expect are the only ones we actually check for right now 😁 |
I think the core logic is pretty much done - just need to shore it up with tests (including coverage for TS-specific imports), switch over all the rules to use it, and implement support for
require
.I'm considering landing this in two parts: 1. just switching us over to checking if references are globals, then 2. (re)implementing the special casing of imports from
@jest/globals
, since they are really two different features and that might make it a bit nicer to list in changelogs etc; but will see how the PR ends up looking.Resolves #556