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 Oct 6, 2023
1 parent b3ef4ed commit bfa70a4
Show file tree
Hide file tree
Showing 3 changed files with 635 additions and 409 deletions.
22 changes: 22 additions & 0 deletions jest.config.js
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 bfa70a4

Please sign in to comment.