Problem statement
The default set of test extensions includes .ts, which also matches any .d.ts file. This causes an error at load time.
Show error message
# ts-node-test\\node_modules\\ts-node\\src\\index.ts:1085
# throw new TypeError(
# ^
# TypeError: Unable to require file: test\\foo.d.ts
# This is usually the result of a faulty configuration or import. Make sure there is a `.js`, `.json` or other executable extension with loader attached before `ts-node` available.
# at getOutput (ts-node-test\\node_modules\\ts-node\\src\\index.ts:1085:17)
# at Object.compile (ts-node-test\\node_modules\\ts-node\\src\\index.ts:1433:41)
# at transformSource (ts-node-test\\node_modules\\ts-node\\src\\esm.ts:400:37)
# at ts-node-test\\node_modules\\ts-node\\src\\esm.ts:278:53
# at async addShortCircuitFlag (ts-node-test\\node_modules\\ts-node\\src\\esm.ts:409:15)
# at async nextLoad (node:internal/modules/esm/loader:163:22)
# at async ESMLoader.load (node:internal/modules/esm/loader:605:20)
# at async ESMLoader.moduleProvider (node:internal/modules/esm/loader:457:11)
# at async link (node:internal/modules/esm/module_job:68:21)
# Subtest: test\\foo.d.ts
not ok 1 - test\\foo.d.ts
---
duration_ms: 889.4078
failureType: 'testCodeFailure'
exitCode: 1
error: 'test failed'
code: 'ERR_TEST_FAILURE'
...
Proposed solution
I see two options:
- Hard-code a rule to not include
.d.ts files in the match
- Add generic syntax for excluding extensions, and configure the default set of extensions to exclude
.d.ts.
The latter would be preferred. An example how this could look:
const DEFAULT_TEST_EXTENSIONS = ['.js', '.mjs', '.cjs', '.ts', '.mts', '.cts', '!.d.ts', '!.d.mts', '!.d.cts']
Unfortunately, this doesn't play nice with TypeScript 5.0's allowArbitraryExtensions feature. Yet, this would likely be fine, as type declaration files for non-JS code inside of the test directory would be a rare occasion. Affected users could simply add e.g. !.d.css.ts to their TEST_EXTENSIONS environment variable.
Disadvantage: This increases parsing complexity significantly, and brings us near the realm of glob matching, without actually giving us glob matching.
Alternatives
I'm open for alternative suggestions.
Problem statement
The default set of test extensions includes
.ts, which also matches any.d.tsfile. This causes an error at load time.Show error message
Proposed solution
I see two options:
.d.tsfiles in the match.d.ts.The latter would be preferred. An example how this could look:
Unfortunately, this doesn't play nice with TypeScript 5.0's
allowArbitraryExtensionsfeature. Yet, this would likely be fine, as type declaration files for non-JS code inside of the test directory would be a rare occasion. Affected users could simply add e.g.!.d.css.tsto theirTEST_EXTENSIONSenvironment variable.Disadvantage: This increases parsing complexity significantly, and brings us near the realm of glob matching, without actually giving us glob matching.
Alternatives
I'm open for alternative suggestions.