Skip to content

Commit fb45b72

Browse files
test: explicitly require ts-node/register from both mocharcs
Mocha 10.5+ takes an ESM import() path for .ts spec files on some Node versions (observed failing on Node 16 with mocha 10.8.2, ERR_UNKNOWN_FILE_EXTENSION). The ESM path bypasses ts-node/register which was previously only loaded via nyc.config.js — that only patches require(), not import(). Adding `require: ['ts-node/register']` to both mocharcs forces mocha to require the ts-node hook before resolving any specs, which keeps the CJS loader path active for .ts files regardless of which Node version is in use. No impact on published package — tests/ is excluded by .npmignore. Co-authored-by: Isaac Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>
1 parent 58a497c commit fb45b72

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

tests/e2e/.mocharc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@ const argvSpecs = process.argv.slice(4);
77
module.exports = {
88
spec: argvSpecs.length > 0 ? argvSpecs : allSpecs,
99
timeout: '300000',
10+
// Force the CommonJS loader path so .ts specs go through ts-node's
11+
// require hook. See tests/unit/.mocharc.js for context.
12+
require: ['ts-node/register'],
1013
};

tests/unit/.mocharc.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,10 @@ const argvSpecs = process.argv.slice(4);
66

77
module.exports = {
88
spec: argvSpecs.length > 0 ? argvSpecs : allSpecs,
9+
// Force the CommonJS loader path so .ts specs go through ts-node's
10+
// require hook. Mocha 10.5+ otherwise picks the ESM import() path
11+
// for .ts files on some Node versions, which bypasses
12+
// ts-node/register (set in nyc.config.js) and fails with
13+
// ERR_UNKNOWN_FILE_EXTENSION.
14+
require: ['ts-node/register'],
915
};

0 commit comments

Comments
 (0)