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(no-deprecated-functions): support jest version setting #564

Merged
merged 2 commits into from May 9, 2020

Conversation

G-Rath
Copy link
Collaborator

@G-Rath G-Rath commented May 5, 2020

This is pretty cool, if I do say so myself.

For now while it's implemented all as util functions, I've lumped them in no-deprecated-functions as utils is getting pretty big & I'd rather have this reviewed first since it's easy to move them out.

I've tested this locally against a few projects, including @typescript-eslint, and nothing went wrong.

fixes #561

@G-Rath G-Rath requested a review from SimenB May 5, 2020 05:59
@G-Rath
Copy link
Collaborator Author

G-Rath commented May 5, 2020

@SimenB I think I might break utils up into a set of grouped ts files, barrelled in utils/; something like:

utils/index.ts
utils/misc.ts
utils/getNodeName.ts
utils/parseExpectCall.ts
utils/followTypeAssertionChain.ts
...etc...

version: JestVersion;
}

const detectJestVersion = (): JestVersion => {
Copy link
Member

@SimenB SimenB May 5, 2020

Choose a reason for hiding this comment

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

could we make this so that once we've found the version it's cached? so we don't do extra fs per test file.

For the test you might need jest.resetModules() so it'll be recalculated. Or move the detection to a separate file and just mock it 🙂

Copy link
Collaborator Author

@G-Rath G-Rath May 5, 2020

Choose a reason for hiding this comment

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

For now I've just gone with a one line _clearCachedJestVersion function, as jest.resetModules didn't work, and so we'd have to have that function even if it was in another file.

I'll break it out into another file later :)

Copy link
Member

Choose a reason for hiding this comment

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

you'd need to re-import the file after clearing so you don't hold on to a reference to the old module.

no biggie, tho

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.

this is great, thank you!

}
} catch {}

throw new Error(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@SimenB I just remembered: I originally used toThrowErrorMatchingInlineSnapshot, but it kept complaining the snapshot was different everytime due to missing indentation at the start & end.

I'll try and put it into a reproduction 🐛

): Promise<string> => {
const jestPackageJson: JSONSchemaForNPMPackageJsonFiles = {
name: 'jest',
version: `${jestVersion}.0.0`,
Copy link
Member

Choose a reason for hiding this comment

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

we might add new "better" versions in minors, but this is fine for now 👍

@G-Rath G-Rath merged commit 05f20b8 into master May 9, 2020
@G-Rath G-Rath deleted the support-version-setting branch May 9, 2020 00:01
@G-Rath G-Rath mentioned this pull request May 9, 2020
github-actions bot pushed a commit that referenced this pull request May 9, 2020
# [23.10.0](v23.9.0...v23.10.0) (2020-05-09)

### Features

* **no-deprecated-functions:** support jest `version` setting ([#564](#564)) ([05f20b8](05f20b8))
@github-actions
Copy link

github-actions bot commented May 9, 2020

🎉 This PR is included in version 23.10.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@@ -9,10 +9,20 @@ of majors, eventually they are removed completely.
## Rule details
Copy link
Member

Choose a reason for hiding this comment

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

Should this mention that it respects/varies based on jest version?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You mean something like this?

(But could be improved by mentioning the actual setting, or at least linking back to that section in the readme)

Copy link
Member

Choose a reason for hiding this comment

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

Linking back or something yeah, so people can be explicit

@@ -22,13 +78,27 @@ export default createRule({
},
defaultOptions: [],
create(context) {
const jestVersion =
(context.settings as ContextSettings)?.jest?.version ||
Copy link
Member

Choose a reason for hiding this comment

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

Can we do something so we don't need the type cast?

Copy link
Collaborator Author

@G-Rath G-Rath May 9, 2020

Choose a reason for hiding this comment

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

No, as context.settings is just type object - it ideally should take a generic, but it's already two that are heavily inferred which means a generic would be unwieldy without support for a sigil to indicate partial type argumentation inference

(Actually technically "yes": we could do a typeguard, but that would be a subtle cast)

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

Successfully merging this pull request may close these issues.

[no-deprecated-functions] support jest version setting
2 participants