-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
chore: migrate @jest/transform to TypeScript #7918
Conversation
92e3d03
to
d1c361c
Compare
Codecov Report
@@ Coverage Diff @@
## master #7918 +/- ##
==========================================
- Coverage 65.49% 65.42% -0.08%
==========================================
Files 255 255
Lines 9930 9949 +19
Branches 965 1038 +73
==========================================
+ Hits 6504 6509 +5
- Misses 3192 3193 +1
- Partials 234 247 +13
Continue to review full report at Codecov.
|
6cb7e7a
to
6809772
Compare
b8f59c8
to
31718fd
Compare
@@ -22,12 +23,18 @@ const THIS_FILE = fs.readFileSync(__filename); | |||
const jestPresetPath = require.resolve('babel-preset-jest'); | |||
const babelIstanbulPlugin = require.resolve('babel-plugin-istanbul'); | |||
|
|||
// Narrow down the types |
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.
quite happy with how this turned out. By using an interface, we can narrow down the type, and it'll tell us here if we break Transform
's contract, and not just a local one. It also narrows down options
of the factory to babel's options instead of any
And importers of babel-jest
directly will see that createTransformer
is always there - it's not possibly undefined. Pretty nice!
@@ -58,18 +65,15 @@ const createTransformer = ( | |||
return babelConfig; | |||
} | |||
|
|||
return { | |||
const transformer: BabelJestTransformer = { |
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.
setting the type here allows us to not type all of the args explicitly
canInstrument: true, | ||
createTransformer, |
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.
this was the solution to the FIXME
below 🙂
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.
This broke all usages of createTransformer
(vs using the transformer that's already created by Jest) because the object createTransformer
returns also has a createTransformer
property, which is checked in @babel/transform
to use that instead of the passed one: https://github.com/facebook/jest/blob/master/packages/jest-transform/src/ScriptTransformer.ts#L157
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.
Oh, oops! 😛 Good catch!
31718fd
to
3f1dcd8
Compare
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.
👌
let scriptCacheKey = null; | ||
let instrument = false; | ||
let result = ''; | ||
let result: TransformResult | string | undefined = ''; |
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.
Can it be really undefined?
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.
Yes, due to this._cache.transformedFiles.get(scriptCacheKey)
below. We cannot return undefined
from this method though.
But your comment made me look, and we don't actually return strings either, so was able to make it a bit stricter
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
Test plan
Green CI