Skip to content

Commit

Permalink
Fix TS tests not working in ESM project. (#3974)
Browse files Browse the repository at this point in the history
  • Loading branch information
garg3133 committed Dec 11, 2023
1 parent 33e6b6e commit c15c002
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/runner/cli/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,13 @@ class CliRunner {
const usingESM = packageInfo.type === 'module';

const usingTS = Utils.fileExistsSync(CliRunner.CONFIG_FILE_TS);
if (usingTS) {
return path.resolve(CliRunner.CONFIG_FILE_TS);
}

if (usingESM) {
return path.resolve(CliRunner.CONFIG_FILE_CJS);
}
if (usingTS) {
return path.resolve(CliRunner.CONFIG_FILE_TS);
}

return path.resolve(CliRunner.CONFIG_FILE_JS);
}
Expand Down
7 changes: 6 additions & 1 deletion lib/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,12 @@ class Utils {
require('ts-node').register({
esm: false,
transpileOnly: true,
project: projectTsFile
project: projectTsFile,
// Always compile and execute .ts files as CommonJS,
// even in ESM projects.
moduleTypes: {
'**/*.ts': 'cjs'
}
});
} catch (err) {
if (err.code === 'MODULE_NOT_FOUND') {
Expand Down

0 comments on commit c15c002

Please sign in to comment.