Skip to content

Commit

Permalink
build: use custom resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
mizdra committed Dec 28, 2021
1 parent f5f57f0 commit 9a33888
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions jest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export default {
// Map `./**/xxx.js` to `./**/xxx` (for ESM)
'^(\\.{1,2}/.*)\\.js$': '$1',
},
// for ESM
resolver: '<rootDir>/test/test-util/jest/resolver.cjs',
// do not transform `import` statements (for ESM)
transform: {},
collectCoverageFrom: ['<rootDir>/src/**/*.{ts,tsx}', '!**/*.d.ts'],
Expand Down
17 changes: 17 additions & 0 deletions test/test-util/jest/resolver.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// ref: https://github.com/facebook/jest/issues/9771#issuecomment-974750103
const importResolver = require('enhanced-resolve').create.sync({
conditionNames: ['import', 'node', 'default'],
extensions: ['.js', '.json', '.node', '.ts'],
});
const requireResolver = require('enhanced-resolve').create.sync({
conditionNames: ['require', 'node', 'default'],
extensions: ['.js', '.json', '.node', '.ts'],
});

module.exports = function (request, options) {
let resolver = requireResolver;
if (options.conditions?.includes('import')) {
resolver = importResolver;
}
return resolver(options.basedir, request);
};

0 comments on commit 9a33888

Please sign in to comment.