Skip to content

Commit

Permalink
Jest transform workaround for ESM-only packages
Browse files Browse the repository at this point in the history
Enables Babel transform for ESM-only packages (to CommonJS) until Jest supports ESM https://jestjs.io/docs/ecmascript-modules

Babel ignores `node_modules` by default
  • Loading branch information
colinrotherham committed Nov 29, 2022
1 parent 1fbc982 commit 9495171
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions jest.config.js → jest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,19 @@ const config = {
// See: https://jestjs.io/docs/ecmascript-modules
transform: {
'^.+\\.m?js$': ['babel-jest', { rootMode: 'upward' }]
}
},

// Enable Babel transforms for ESM-only node_modules
// See: https://jestjs.io/docs/ecmascript-modules
transformIgnorePatterns: [
`<rootDir>/node_modules/(?!${[
'del',
'slash'
].join('|')}/)`
]
}

module.exports = {
export default {
collectCoverageFrom: ['./src/**/*.{js,mjs}'],
projects: [
{
Expand Down

0 comments on commit 9495171

Please sign in to comment.