vscode-mocha-test-adapter
vscode-mocha-test-adapter copied to clipboard
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension “.ts”
Mocha Test Explorer only seems to work with commonjs.
Attempts to make it work with ES Module always ended up with
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension “.ts”
Feel free to try it out using this demo project.
My configurations:
node v16.8.0 VSCode v1.66.0 Mocha Test Explorer v2.13.3
package.json
{
"type": "module"
}
tsconfig.json
{
"compilerOptions": {
"module": "esnext",
"target": "esnext",
"esModuleInterop": true,
}
}
settings.json of VSCode
{
"mochaExplorer.require": [
"ts-node/register",
"esm"
]
}
I have also been encountering this while evaluating @web/web-test-runner from here and here.
I have a .mocharc.yaml like so:
extension: [ 'ts' ]
package: './package.json'
reporter: 'spec'
require: 'ts-node/register'
spec:
- 'tests/**/*.spec.ts'
timeout: 10000
A sample test
import { expect } from "@esm-bundle/chai";
describe("index test suite", () => {
it("registers tests", () => {
expect(true).to.be.true;
});
});
This is using @tsconfig/node16 as it's tsconfig.json (node 16.14.0 as of this comment :smile: )
vscode 1.66.2 Mocha Test Explorer 2.13.5
I have the same problem. .mocharc.json (or even .vscode/settings.json/mochaExplorer.nodeArgv) should be read before running mocha but that does not appear to be the case.
Adding this to .vscode/settings.json (even though those values are available in my .mocharc.json) enabled test adapter to continue and read my .mocharc.json and load correctly.
"mochaExplorer.nodeArgv": [
"--loader=ts-node/esm",
"--no-warnings=ExperimentalWarning",
"--experimental-specifier-resolution=node"
]
@chriskuech Thank you! Your suggestion fixed the problem!
Also had this issue, should be documented or fixed. thank you
I have the same problem. .mocharc.json (or even .vscode/settings.json/mochaExplorer.nodeArgv) should be read before running mocha but that does not appear to be the case.
Adding this to .vscode/settings.json (even though those values are available in my .mocharc.json) enabled test adapter to continue and read my .mocharc.json and load correctly.
"mochaExplorer.nodeArgv": [ "--loader=ts-node/esm", "--no-warnings=ExperimentalWarning", "--experimental-specifier-resolution=node" ]
This fixed the issue for me too
Same problem, adding "nodeArgv" was not enough in my case. It failed on loading my mocharc.cjs (that does not contain relevant config for Explorer anyway) and displayed same error as in https://github.com/hbenl/vscode-mocha-test-adapter/issues/92.
Finally i made it working with:
settings.json
"mochaExplorer.envPath": "./mochaExplorer.env",
"mochaExplorer.nodeArgv": [
"--loader=ts-node/esm"
],
"mochaExplorer.configFile": "",
mochaExplorer.env
TS_NODE_PROJECT = tsconfig.test.json
TS_NODE_FILES = true