-
Notifications
You must be signed in to change notification settings - Fork 12
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
Migration to ES Modules broke Jest unit testing #16
Comments
@joaosamouco thanks for reaching out. One of the motivations for the full migration to ES modules is that the CommonJS entrypoint in this package was already not functioning properly, because some of the sub-dependencies were already not CommonJS compatible; such as d3-scale for example. Thus, it wasn't a major version bump because in fact the feature was already broken, and the package was falsely advertising that it could be safely bound as a CommonJS module. In your case I'd suggest pinning to Is the Jest (experimental) ESM support not functioning well enough in this case? |
Hi!
This won't work since
After some trial and error I was finally to make it work, I will leave the instructions in case it is helpful to someone else.
npm i -D @babel/core babel-jest @babel/plugin-transform-modules-commonjs
module.exports = {
env: {
test: {
plugins: ['@babel/plugin-transform-modules-commonjs'],
},
},
};
// jest.config.js
module.exports = () => ({
...
transform: {
...
// support for ES Modules
'node_modules/(float-tooltip|kapsule|icicle-chart|accessor-fn)/.+\\.m?jsx?$': 'babel-jest',
},
// ignore all node_modules except the ones we are transforming
transformIgnorePatterns: [
'node_modules/(?!(float-tooltip|kapsule|icicle-chart|accessor-fn)/)',
],
}); |
@joaosamouco I'm surprised you didn't already have this issue with all the |
Oh, I see. For // jest.config.js
module.exports = () => ({
...
moduleNameMapper: {
...,
'^d3-(.*)$':
'<rootDir>/node_modules/d3-$1/dist/d3-$1.min.js'
'^(icicle-chart|float-tooltip|kapsule|accessor-fn)$':
'<rootDir>/node_modules/$1/dist/$1.min.js',
},
}); |
Describe the bug
The most recent change to this and other packages like
kapsule
,accessor-fn
,float-tooltip
, and probably some more, broke my unit-tests pipeline that uses Jest. Jest support for ES Modules is still in experimental phase so things are expected to break.It's okay to migrate to ES Modules but if you are dropping support for CommonJS I believe that the best thing to do is to publish a new major version since this is most likely a breaking change.
Also, if someone knows how to fix this so that Jest is able to process these modules, please let me know.
The text was updated successfully, but these errors were encountered: