-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
fix(cli-plugin-unit-jest): When using TS & Babel, make ts-jest use babelConfig #3107
Conversation
global: !api.hasPlugin('babel') ? undefined : { | ||
'ts-jest': { | ||
// we need babel to transpile JSX | ||
babelConfig: true |
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.
According to ts-jest
this option will:
ts-jest will try to find a .babelrc, .babelrc.js file or a babel section in the package.json ...
But vue-cli generates a babel.config.js
, a relatively new way to configure babel.
ts-jest
lets you specify the path like so:
'ts-jest': {
babelConfig: 'babel.config.js'
}
}
Maybe that would work.
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, but true
actually worked like a charm in a vue-cli project I tried it with. So I don'T think we need to specifiy a path./filename
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.
huh, awesome. I wonder why that worked. Good to hear!
This comment has been minimized.
This comment has been minimized.
When using Typescript and Babel, ts-jest should use babel to transform result for correct JSX transforms close #3100
ca44b2a
to
70293a3
Compare
Tested locally, works fine. Not sure I should add a test, the jest generator tests that currently exist don't cover much details either. @sodatea ? |
previous way could end up with ugly `global: undefined` when not using babel
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.
Yeah I think we should add tests. Otherwise it would be hard to track down when a major version bump happens.
I got warning message
|
@mortyccp Ahhhhh you are right, thanks! We should definitely add a test for this. |
Oh damn, I'm sorry for messing this up :/ |
tsconfig.json is set to preserve jsx:
Because Typescript can't compile JSX into Vue-style render functions, only React-style.
But that means:
build
andserve
if we also use babel to conmplie the JSX afterwards. But in Jest, we can only pick one transform, we can't chain them.This PR is meant to fix the first issue: ts-jest should use babel to transform result for correct JSX transforms by setting its
babelConfig
option.close #3100
Sidenote: The second issue still exists, and likely isn't resolable. We should probably document it, though, and also mention in the prompt messages.