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
  • Loading branch information
colinrotherham committed Nov 18, 2022
1 parent 8f4061e commit b6767cb
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,23 @@ const config = {
// See: https://jestjs.io/docs/ecmascript-modules
transform: {
'^.+\\.m?js$': ['babel-jest', { rootMode: 'upward' }]
}
},

// Enable Babel transforms for ESM-only node_modules
transformIgnorePatterns: [`<rootDir>/node_modules/(?!(${[
'del',
'slash',
// Including child dependencies
'aggregate-error',
'clean-stack',
'escape-string-regexp',
'globby',
'indent-string',
'is-path-cwd',
'is-path-inside',
'p-map'
].join('|')})/)`]
}

module.exports = {
Expand All @@ -25,7 +41,10 @@ module.exports = {
displayName: 'Gulp tasks',
testMatch: [
'**/gulp/**/*.test.{js,mjs}'
]
],

// No additional transforms needed
transformIgnorePatterns: ['<rootDir>/node_modules/']
},
{
...config,
Expand All @@ -37,7 +56,10 @@ module.exports = {
testEnvironment: './config/jest/environment/jsdom.mjs',
testMatch: [
'**/(*.)?template.test.{js,mjs}'
]
],

// No additional transforms needed
transformIgnorePatterns: ['<rootDir>/node_modules/']
},
{
...config,
Expand All @@ -63,6 +85,9 @@ module.exports = {
'!**/gulp/**'
],

// No additional transforms needed
transformIgnorePatterns: ['<rootDir>/node_modules/'],

// Web server required
globalSetup: './config/jest/server/start.mjs',
globalTeardown: './config/jest/server/stop.mjs'
Expand Down

0 comments on commit b6767cb

Please sign in to comment.