Closed danbeam closed 8 months ago
Interesting! Thanks for another contribution! I just read quickly through this, and here is my feedback.
Note that we have similar code for this for all the transformations – in the CLI you can pick what we internal call standaloneMode
if this you say no to "Will you be using Jest on Node.js as your test runner?". This is done here: https://github.com/skovhus/jest-codemods/blob/main/src/utils/finale.ts#L25 Not sure how many people use this feature... It seems we might want to use @jest/globals
instead of jest-mock
and expect
as we do right now. Also rather poorly documented here: https://github.com/skovhus/jest-codemods#test-environment-jest-on-nodejs-or-other
We also have a bunch of import helpers defined here, that could be useful for this PR. Maybe they handle more corner cases than you do, or maybe you handle additional corner cases: https://github.com/skovhus/jest-codemods/blob/main/src/utils/imports.ts
Currently all codemods converts from one test runner to another, this one is different. I guess it shouldn't be exposed in the CLI or? But the transformation here could just be exposed directly as these: https://github.com/skovhus/jest-codemods#usage-jscodeshift
@skovhus sorry for the lag on this; do you want the content of this PR (a @jest/globals
codemod)? It wasn't clear from your previous response.
If "yes", I can probably find some time to e.g. update to utils/imports.ts
or something along those lines. But I kinda wanted to know whether you actually want the content first 😅 .
If "no": I can close.
Currently all codemods converts from one test runner to another, this one is different. I guess it shouldn't be exposed in the CLI or? But the transformation here could just be exposed directly as these: https://github.com/skovhus/jest-codemods#usage-jscodeshift
I don't have strong feelings here; whatever you prefer.
This is great. Let us just document it in the README and then I think we are good to go.
This is great. Let us just document it in the README and then I think we are good to go.
I can add more prose about this codemod, but it seems fairly discretionary about what you'd like to say (e.g. do you want another sentence before the status images? I don't know that this is worth highlighting like that.)
@skovhus anything else you'd like me to do here?
I haven't quite figured out how to CI checks passing (I'm getting different results locally, I think?).
Note: when I tried updating the lock file, the format was different and I don't think the CI checks passed then either (but I think perhaps it was a different error at least?).
hey @skovhus 👋
just following up again here: anything I can do to get this done? it's not particularly urgent, I'm just hoping to tie up loose ends by getting this in eventually! (when it's right by you)
let me know if you can! (if you're on holiday or something no sweat.)
All modified and coverable lines are covered by tests :white_check_mark:
Comparison is base (
a94e2b5
) 92.38% compared to head (dce4d86
) 92.59%. Report is 28 commits behind head on main.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Thanks for adding support for this!
I recently had to convert a bit of code that used jest globals (e.g.
describe()
,it()
,expect()
) to explicitly importing these APIs from@jest/globals
.Before:
After:
While doing that manually I thought: this would make a good codemod!
So I wrote a fairly simple one that actually scrapes the exports from the
@jest/globals
package itself[1], finds global usage, and adds imports.[1] I don't use
require.resolve()
nor actuallyimport
it cuz both are enforcedly disallowed, which is a mild bummer, but overall I think it's still kinda slick. If you know a better way, let me know!