Skip to content

Commit

Permalink
test: Workaround for Jest ESM issues
Browse files Browse the repository at this point in the history
To prevent issues with Jest and ESM
we transform all ESM dependencies to CJS while testing.
  • Loading branch information
joachimvh committed Jun 16, 2023
1 parent b2da5f2 commit ae25ce4
Show file tree
Hide file tree
Showing 3 changed files with 508 additions and 389 deletions.
22 changes: 22 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,36 @@ function jestGithubRunnerSpecs() {
};
}

// ESM libraries that need to be transformed so Jest can handle them
const esModules = [
'oidc-provider',
'nanoid',
'got',
'quick-lru',
'@sindresorhus/is',
'p-cancelable',
'@szmarczak/http-timer',
'cacheable-request',
'normalize-url',
'responselike',
'lowercase-keys',
'mimic-response',
'form-data-encoder',
'cacheable-lookup',
];

module.exports = {
transform: {
'^.+\\.ts$': [ 'ts-jest', {
tsconfig: '<rootDir>/tsconfig.json',
diagnostics: false,
isolatedModules: true,
}],
// This transformer converts ESM packages to CJS
'^.+node_modules.+\\.js$': 'jest-esm-transformer-2',
},
// By default, node_modules are not transformed, but we want to transform the ESM packages
transformIgnorePatterns: [`/node_modules/(?!(${esModules.join('|')})/)`],
testRegex: '/test/(unit|integration)/.*\\.test\\.ts$',
moduleFileExtensions: [
'ts',
Expand Down

0 comments on commit ae25ce4

Please sign in to comment.