Skip to content
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: improve how jest function calls are resolved to account for import aliases #1122

Merged
merged 20 commits into from
May 28, 2022

Conversation

G-Rath
Copy link
Collaborator

@G-Rath G-Rath commented May 28, 2022

Resolves #1106 and #1119, and has highlighted a few other improvements (like that prefer-todo ignores x prefixed methods even though it applies to .skip'd methods, and the ability to support context as an alias of describe).

This overhauls how we parse jest methods to leverage the redesign of how to check if something is a jest method that was landed via #1094 so that rules can handle aliased functions.

Because of how this turned out I've ended up doing away with most of the utils tests as they're now covered by tests in rules - I have only brought them back to cover cases that are not specific to one particular rule.

I've kept this to being just focused on implementing #1106 even though I could also do a few more things like add support for failing (#1118), support parsing expect, remove support for invalid concurrent call chains, etc. I'll be doing follow up PRs straight away for these so that they have their own changelog.

Support for parsing expect calls in particular will be my next focus as I've got that mostly done already but realised a little bit of extra thinking needs to be done because expect usage is generally inverse to other methods since it goes expect(..).property.call(...) - I would like to merge the existing parser/api into this new one, but need to decide on a pattern to represent the difference between expect calls where expect itself is called (which is what the current parser handles) and expect calls where it's not (which is what the new parser is really looking for, in all cases except for expect).

I also realised while doing this that spyOn and co are still accessed via jest even when using @jest/globals - you just import jest (e.g. it's import { jest } from '@jest/globals';, not import { spyOn } from '@jest/globals';)

Also also while not super important, this makes lib ~4kb smaller which I think is a good sign that it's on the right track :D

@G-Rath G-Rath requested a review from SimenB May 28, 2022 03:27
@G-Rath G-Rath force-pushed the support-resolving-source-method-final branch from ba4b8df to e6c3360 Compare May 28, 2022 03:38
@G-Rath G-Rath changed the title Support resolving source method final feat: improve how jest function calls are resolved to account for import aliases May 28, 2022
Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woah, amazing!

@@ -6,6 +6,7 @@ import {
TSESTree,
} from '@typescript-eslint/utils';
import { version } from '../../package.json';
import { isTypeOfJestFnCall } from './utils/parseJestFnCall';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename this file to utils/index.ts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was planning on moving everything else in a follow-up PR, as I'll split things across a few more files but wanted to wait until I'd refactored expect parsing since that represents about 1/3rd of the file.

@G-Rath G-Rath merged commit 781f00e into main May 28, 2022
@G-Rath G-Rath deleted the support-resolving-source-method-final branch May 28, 2022 18:30
github-actions bot pushed a commit that referenced this pull request May 28, 2022
# [26.4.0](v26.3.0...v26.4.0) (2022-05-28)

### Features

* improve how jest function calls are resolved to account for import aliases ([#1122](#1122)) ([781f00e](781f00e))
@github-actions
Copy link

🎉 This PR is included in version 26.4.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support resolving underlying @jest/globals method from import
2 participants