-
-
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
feat: extract 'createTransformer' and use type predicates #12407
Conversation
82013ba
to
2ac8aca
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.
yay!
Hmm ... after seeing
The transform package does (now) have that type exported and I can see it in |
Note that you need to export |
ad4a528
to
4bcdf9a
Compare
04aebac
to
e8125a8
Compare
Finally builds every (*) integration test 🥳 Trang fødsel, as we say. This "simple doc update" did end up touching the transform, repl and babel-jest projects, along with various e2e tests, so you might want to have a look to see if you agree with the changes done to the tests. I think the only thing that might validate a change is my question on the wording of what is required to implement, as I was a bit unsure myself what you really meant here.
|
e8125a8
to
91a8f0e
Compare
Trang fødsel, indeed 😀 Both of those tests are somewhat flaky (I just pushed some retrying to |
@@ -9,6 +9,8 @@ import type {TransformOptions as BabelTransformOptions} from '@babel/core'; | |||
import type {TransformOptions as JestTransformOptions} from '@jest/transform'; | |||
import babelJest from '../index'; | |||
|
|||
const {getCacheKey} = babelJest.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.
why is this needed?
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.
Well, it was either that or const babelJestTransformer = babelJest.createTransformer();
and babelJestTransformer.getCacheKey(...)
(or something similar).
Since we have no other exports than createTransformer, you would otherwise need to write babelJest.createTransformer().getCacheKey(...)
in every location that used babelJest.getCacheKey(...)
previously.
Not sure what you prefer. Since the transformer was not used for anything besides calling its getCacheKey()
method, I thought removing it and just keeping the method through destructuring was fine.
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.
why not babelJest.getCacheKey
? It should be on the default export, no?
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.
Since removing all but the factory method was part of this change.
I can of course revert it, but then those exports would just be for the sake of the tests (AFAIK?); the jest-transform
package will not touch any of those exports when it sees createTransformer
and neither will the CLI, so I thought keeping test-only exports did not make sense from that perspective. I might be wrong, of course 😄
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.
Hope to have addressed all non-code related feedback. Mostly used your suggested prose, apart from introducing some full stops and minor adjustments to make the sentences shorter and easier to read.
With regards to the code changes you wondered about, which mostly stems from the fact that exports that are not used outside of tests have been removed, I am not sure if you think I should revert any of those or if it made sense.
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.
Thanks! What I'm alluding to here is that babelJest.getCacheKey
should work fine, there's not need to call createTransformer
first (I think!)
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.
And I am saying that functionality was removed in this PR 😄 Sorry if being unclear! See https://github.com/facebook/jest/pull/12407/files#diff-5f463bc5dbe428998302335614e9bbed3b4eb3310a6075767e1b432c161d9e71L273
It used to be:
const transformer: SyncTransformer<TransformOptions> = {
...createTransformer(),
createTransformer
}
export default transformer;
Note the ...createTransformer()
. That is what ensures that babelJest.getCacheKey
exists.
All of the fields from ...createTransformer()
would be ignored by Jest itself when it sees createTransformer
. Since they are not used in any actual non-test code, I thought it did not make sense to expose them, since you could always just instantiate a new transformer in the tests. Once their use is gone from tests, no code would use them. So that's the reasoning behind removing them. I could keep them, of course, which would keep the tests unchanged, but what point is there in testing exports that will never be used?
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.
Thanks a bunch for thorough feedback.
@@ -9,6 +9,8 @@ import type {TransformOptions as BabelTransformOptions} from '@babel/core'; | |||
import type {TransformOptions as JestTransformOptions} from '@jest/transform'; | |||
import babelJest from '../index'; | |||
|
|||
const {getCacheKey} = babelJest.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.
Well, it was either that or const babelJestTransformer = babelJest.createTransformer();
and babelJestTransformer.getCacheKey(...)
(or something similar).
Since we have no other exports than createTransformer, you would otherwise need to write babelJest.createTransformer().getCacheKey(...)
in every location that used babelJest.getCacheKey(...)
previously.
Not sure what you prefer. Since the transformer was not used for anything besides calling its getCacheKey()
method, I thought removing it and just keeping the method through destructuring was fine.
Basically conclusions from a discussion in jestjs#12403
fcc5574
to
940c43d
Compare
Sorry, missed the last push! |
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.
thanks! veeeeeery close 😀
My last general question is if we should use admonitions int the docs? I feel like they might help break up the text a bit and make it more digestible? might be wrong, tho!
Co-authored-by: Simen Bekkhus <[email protected]>
I am change blind 🙈 Can someone do that in a separate PR? I think I am blind to what is better, more clear, etc at this point. And especially whether or not to add some color blocks and where to put them 🤷 |
Yeah, no problem 👍 |
Hmm ... this is stale, but I am not sure why 🤷 Should I address something or are we good ⬆️? |
Should be good - I've been away on vacation, so haven't had time to properly review |
Totally understandable; I was just not sure if this was blocking due to me or not, since it seemed everything substantial had been addressed. |
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.
thanks!
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
See discussion in #12403. These changes make the interfaces more self-documenting and the intent clearer.
Test plan
Type checks
Unit tests
This failed on some integration tests (differed on runs), but not due to my changes?