-
-
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
fix: Allow updating inline snapshots when test includes JSX #12760
Conversation
4fd47bd
to
586ac6e
Compare
586ac6e
to
23ce2ca
Compare
I take it there's no workaround possible in the meantime? |
37ec078
to
e8f607f
Compare
if (error.message.includes('@babel/plugin-syntax-jsx')) { | ||
try { | ||
const jsxSyntaxPlugin: PluginItem = [ | ||
require.resolve('@babel/plugin-syntax-jsx'), | ||
{}, | ||
// unique name to make sure Babel does not complain about a possible duplicate plugin. | ||
'JSX syntax plugin added by Jest snapshot', | ||
]; | ||
ast = parseSync(sourceFile, { | ||
filename: sourceFilePath, | ||
plugins: [...plugins, jsxSyntaxPlugin], | ||
presets, | ||
root: rootDir, | ||
}); |
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.
{}, | ||
// unique name to make sure Babel does not complain about a possible duplicate plugin. | ||
'JSX syntax plugin added by Jest snapshot', |
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.
probably don't need this as the error is due to this plugin missing
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.
finally 🙂
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
Closes #11561
Note that the fix by @SimenB does not fix the added test because the test passes the babel config directly to babel-jest instead of being declared in a babel.config.js.
It seems to me that
saveSnapshotsForFile
should ultimately ensure it transforms the source with the same transformer that was passed to Jest. It looks like it's currently assuming Babel with pre-defined plugins.Though we can't actually accept any transformer since their AST format may differ and we currently use the AST to find
toMatchInlineSnapshot
calls.I guess for now we focus on fixing this when using Babel and keep the old behavior when Babel isn't used?
Test plan
yarn jest toMatchInlineSnapshotWithJSX