-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
WP Scripts: Syntax error when running Jest #43132
Comments
Well, my fix worked locally but isn't working in github actions, so you can see the broken tests here. |
@tyxla, it looks like using ESM code in 3rd party packages is more complicated with Jest than we anticipated. I’m wondering what next steps we should take. As a short term solution we can enable transformation for this package in Jest preset. Technically speaking, we could use a different package, but it’s rather a more general issue that will come back as ESM becomes more popular. The most challenging part is that ESM isn’t fully supported by Jest. See jestjs/jest#9430 and https://jestjs.io/docs/ecmascript-modules. They use some special vm API for ESM that is still experimental in Node according to nodejs/node#37648. |
Thanks for reporting this, @ryelle! Yeah, this was expected to happen, and it's a bummer that we have limited options to fix it. As you mentioned, a quick workaround for now is to move the transform ignore rule to the default jest preset, and that way it will be considered by the scripts package. Let me file a PR. |
Here's a PR that should solve the problem: #43179. Once we merge it, we'll only need to publish new minor versions of the affected packages. |
#43179 should be available on npm in a few minutes. It should resolve the issue. |
The Jest config was a workaround for this issue: WordPress/gutenberg#43132 — now that this is fixed in @wordpress/scripts 23.7.1, it's not necessary.
Weird, I have a project were I still get this error, even after updating // eslint-disable-next-line import/no-extraneous-dependencies
const defaults = require('@wordpress/scripts/config/jest-unit.config');
module.exports = {
...defaults,
clearMocks: true,
coveragePathIgnorePatterns: [
'<rootDir>/lib/',
'<rootDir>/node_modules/',
],
}; The error is
Specifying Anybody any ideas? Sorry to bother you with this, I assume I missed something.. UPDATE: If I delete |
Doesn't seem to work for me either, but maybe I'm missing something. Parsely/wp-parsely#1027 |
@tyxla, I think the regular expression used should match the last occurrence of the
We don't care here about the |
@tyxla thank you for working on this. I can indeed confirm that it's working fine with your new regex! to be sure I directly replaced it in |
Thanks for confirming so quickly, @herndlm! |
Excellent! Thank you for providing a fix so quickly. I will publish it to npm tomorrow. |
New |
Description
After updating packages, I'm getting a syntax error in my project when running
wp-scripts test-unit-js
.Step-by-step reproduction instructions
Run
wp-scripts test-unit-js
on a project that, somewhere along the way, imports theis-plain-obj
package.I've fixed it for now by creating a local
jest.config.js
file with the following. I copiedtransformIgnorePatterns
out of the gutenberg jest.config.js. I think adding that line to the jest-unit.config.js file in @wordpress/scripts would fix the issue without requiring custom code.Screenshots, screen recording, code snippet
No response
Environment info
@wordpress/scripts 23.7.0
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
N/A
The text was updated successfully, but these errors were encountered: