hbenl / vscode-mocha-test-adapter

Mocha Test Adapter for the VS Code Test Explorer
MIT License
91 stars 31 forks source link

Typescript and ts-node/esm loader #189

Closed ludekvodicka closed 2 years ago

ludekvodicka commented 2 years ago

Hi, I would like to ask for help. I'm trying to find a way how to configure mocha test explorer to be able to execute a custom ts-node/esm loader.

this is my test script configuerd in package.json as same as in launch.json/tasks.json where wors fine:

"mocha -r ts-node/register --loader=ts-node/esm --no-warnings=ExperimentalWarning --experimental-specifier-resolution=node --timeout 999999 --colors --recursive './**/*.test.ts' --ignore './**/node_modules/**'

Unfortunately, I didn't find a way how to configure the same settings also to Mocha test explorer.

I tried to use nodeArgv configuration:

"mochaExplorer.nodeArgv": [
        "--loader=ts-node/esm",
        "--no-warnings=ExperimentalWarning",
        "--experimental-specifier-resolution=node"
],

but this causes frozen (probably) freezing of worker\bundle.js :

[2022-01-28 16:34:06.001] [INFO] Configuration changed
[2022-01-28 16:34:06.006] [INFO] Reloading tests because mochaExplorer.nodeArgv changed
[2022-01-28 16:34:06.006] [INFO] Loading test files of q:\Development\TypeScript
[2022-01-28 16:34:06.006] [DEBUG] Using working directory: Q:\Development\TypeScript
[2022-01-28 16:34:06.169] [DEBUG] Using nodePath: C:\Program Files\nodejs\node.exe
[2022-01-28 16:34:06.608] [DEBUG] Using Mocha options: {"ui":"bdd","timeout":10000,"retries":0,"requires":[],"delay":false,"fullTrace":false,"exit":false,"asyncOnly":false,"parallel":false}
[2022-01-28 16:34:06.608] [DEBUG] Looking for test files ["test/**/*.js"] in q:\Development\TypeScript
[2022-01-28 16:34:06.608] [DEBUG] Found test files []
[2022-01-28 16:34:06.609] [DEBUG] Using environment variables from config: {}
[2022-01-28 16:34:06.609] [DEBUG] Spawning .vscode\extensions\hbenl.vscode-mocha-test-adapter-2.13.0\out\worker\bundle.js with IPC options {}

Don't you have any example how to make this work, please?

Thanks

ludekvodicka commented 2 years ago

I found out that this can be easily solved by source-map support.

In case anyone else would need it:

Just install source-map-support: npm i source-map-support,

allow sourceMap in tsconfig.json: "sourceMap": true,

and configure support in settings.json file:

"mochaExplorer.files": "build/**/*.test.js",
"mochaExplorer.require": "source-map-support/register",
"mochaExplorer.watch": "build/**/*.test.js",

And done ;-)