Skip to content

Commit

Permalink
🐛 Fix the jest resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
elbywan committed Jul 3, 2022
1 parent 69c1e35 commit 3a1f7b8
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"resolver": "<rootDir>/test/resolver.cjs",
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"moduleFileExtensions": [
"ts",
Expand All @@ -124,7 +125,7 @@
],
"globals": {
"ts-jest": {
"tsConfig": "test/tsconfig.tests.json"
"tsconfig": "test/tsconfig.json"
}
},
"collectCoverage": true,
Expand Down
9 changes: 9 additions & 0 deletions test/resolver.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const path = require("path")
const srcDir = path.resolve(__dirname, "..", "src")

module.exports = (path, options) => {
if (options.basedir.startsWith(srcDir) && path.endsWith(".js")) {
return options.defaultResolver(path.substring(0, path.length - 3) + ".ts", options);
}
return options.defaultResolver(path, options);
};
20 changes: 20 additions & 0 deletions test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"target": "es5",
"lib": [
"es2015",
"dom"
],
"module": "commonjs",
"noImplicitAny": false,
"sourceMap": true,
"allowJs": true,
"types": [
"node",
"jest"
]
},
"include": [
"./node/**/*.spec.ts"
]
}
14 changes: 0 additions & 14 deletions test/tsconfig.tests.json

This file was deleted.

0 comments on commit 3a1f7b8

Please sign in to comment.