-
Notifications
You must be signed in to change notification settings - Fork 27.4k
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
Next/Jest : Cannot override transformIgnorePatterns #35634
Comments
I'm running into this issue as well for next.js/packages/next/build/jest/jest.ts Line 74 in acbd543
I'm working around it for now by overriding my settings in the jest config:
|
Looks like @kevva was on the money here: #34350 (comment) |
For your info, I worked around it by mocking them manually in the test files instead: jest.mock('path/to/image.svg', () => 'svg'); However, it'd be nice if we could override/extend the default values in |
Yeah, thanks to this comment #26749 (comment), I got to the same workaround for now. Thanks @kevva |
@kevva, did you end up creating an issue for the moduleNameMapper order? |
No, unfortunately not. I don't have time for writing a good issue with a good reproduction case atm. Feel free to go ahead and do it :). |
(Just to be clear, in my case I can't mock the module as a workaround, I do want to use it in my test) |
…ppings (#36312) Fixes #35634 This change doesn't require tests as importing svgs is not a supported feature, this just makes it slightly more ergonomic to override the matchers. ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `yarn lint`
I've moved the moduleNameMapper so that you can override the mapping. The case where you want to do anything else than is provided by default is explained well by @xveganxxxedgex's comment: #35634 (comment). That approach allows you to override any setting you'd want to tweak based on customizations you've done to the webpack config, those are not covered / supported by Next.js and as such are not specifically added as features to next/jest. |
The PR that closed this issue did not address OP's original use case, which was not related to The problem specifically has to do with jest 28 adding support for the exports field and jsdom's default environment being the browser. When the test environment is set to jsdom, any node module that exports esm will cause this error, which will only get more common as more packages add support for exports. It's not really a jest error, so I think the best way to address it is to allow for specific node modules to be transformed in the jest config, which means overriding Minimal reproduction: https://codesandbox.io/s/magical-chihiro-xf68kl Open a new terminal window and run Known workaround async function jestConfig() {
const nextJestConfig = await createJestConfig(customJestConfig)()
// /node_modules/ is the first pattern
nextJestConfig.transformIgnorePatterns[0] = '/node_modules/(?!uuid)/'
return nextJestConfig
}
module.exports = jestConfig Edit: Thinking about this more. I understand it's a breaking change to allow overrides to const customJestConfig = {
// ... other config
transformIgnorePatterns: (nextDefaultPatterns) => {
return [
...nextDefaultPatterns,
// Extend or override
]
}
} |
I'm still experiencing this issue in Next v12.1.6 with Jest v28.0.3. I'm currently using the solution proposed by @timmywil as a workaround. |
Rectify Jest configuration for renovate-bot #814 pull request. close #815 issue vercel/next.js#35634 issue vercel/next.js#36312
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Verify canary release
Provide environment information
Relevant in any environment
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Describe the Bug
The way
next/jest
is implemented, (See here), there is no way to force jest to transpile modules inside node_modules.When trying to import node_modules who need to be transpiled (e.g the openlayers module
ol
), jest throws the following error:The recommended way to fix this error is to add a
transformIgnorePatterns
regex, so that thejest.config.js
looks like this:BUT this does not work due to the way
next/jest
is implemented, (See here), thenode_module
element is impossible to remove from that array, and hence nonode_module
can be transpiled, ever, even if I override this in my ownjest.config.js
.Expected Behavior
Setting this in my own
jest.config.js
Would transpile
ol
, and I wouldn't have this error when I run tests:To Reproduce
npm install ol
jest.config.js
:my.test.ts
:The text was updated successfully, but these errors were encountered: