vscode-mocha-test-adapter
vscode-mocha-test-adapter copied to clipboard
Is there a way to use experimental-loader
Hello and thanks a lot for this extension. It seems to make working with tests more fun!
At work we need to use an experimental loader to load our tests because we are using an old module system (YUI). The loader walks thru all the imported modules and loads the dependencies.
To load launch the tests we usually call, but I would like to use Mocha test explorer instead :-)
MOJITO_AFFINITY=${npm_config_mojito_affinity:-server} mocha --no-warnings --experimental-modules --experimental-specifier-resolution=node --experimental-loader=./test/unit/loader.mjs --require=./test/unit/index.mjs --exit "**/*.${npm_config_mojito_affinity:-server}.test.mjs"
I am able to implement require, but have not figured out how to implement experimental-loader. Is there a way to do that?
These options are actually Node.js options that Mocha detects and passes on. This is currently not supported by this extension, but I plan to add support for Node.js options soon.
Thanks a lot for the reply @hbenl. Then I will keep my eyes and this issue open until then. Looking forward to that feature.
I have just published version 2.13.0 which lets you specify command line arguments for node using mochaExplorer.nodeArgv
.
Note that while you can define these options in your mocha configuration file (where they are picked up by mocha if you call it directly on the command line), this extension will currently not pick up node options from mocha config files, you'll have to add them to your VSCode settings with the mochaExplorer.nodeArgv
option.
Please tell me if this works for you.
I have tried using mochaExplorer.nodeArgv
with "--loader ts-node/esm"
but then configReader.js/readConfig()
fails when it tries to creates a child process to execute loadConfig.js
it would be nice if we could include a loader
parameter in mocha config file like this and have the loader parameter passed to mocha
package.json
{
"type": "module",
(...)
"mocha": {
"loader": "ts-node/esm", <------ this
"extension": "ts",
"spec": "test/**/*.test.ts"
}
}
I can run my tests just calling mocha
using this settings but can not get them to run using the extension
@saviski did you set mochaExplorer.nodeArgv
to ["--loader ts-node/esm"]
or ["--loader", "ts-node/esm"]
? The latter should be correct.
@saviski did you set
mochaExplorer.nodeArgv
to["--loader ts-node/esm"]
or["--loader", "ts-node/esm"]
? The latter should be correct.
["--loader ts-node/esm"]
I have debugged the extension to make some tests locally,
setting "mochaExplorer.nodeArgv": ["--loader ts-node/esm"]
readOptsUsingMocha function from optsReader.js calls https://github.com/hbenl/vscode-mocha-test-adapter/blob/070e170d583b029e1c2740c4baa89a3729587d78/src/optsReader.ts#L128
with the correct nodeArgv
but then this child process fails
["--loader ts-node/esm"]
is not the correct nodeArgv: it passes "--loader ts-node/esm"
as one argument to node, but when you run node --loader ts-node/esm
in a shell, the shell will pass 2 arguments ("--loader"
and "ts-node/esm"
) to node. Try setting mochaExplorer.nodeArgv
to ["--loader", "ts-node/esm"]
.
I have tried using nodeArgv
option as described above with testdouble
/quibble
loader and while the loader works just fine when executed from command line, the Test Explorer (original and native one) stays in infinite loop of refreshing test view. The output view shows this log:
[2021-11-20 09:42:41.009] [INFO] Loading test files of /Volumes/src/front/project
[2021-11-20 09:42:41.011] [DEBUG] Using working directory: /Volumes/src/front/project/server
[2021-11-20 09:42:41.011] [DEBUG] Using nodePath: /Users/user/.nvm/versions/node/v16.13.0/bin/node
[2021-11-20 09:42:41.550] [DEBUG] Using Mocha options: {"ui":"bdd","timeout":2000,"retries":0,"requires":["source-map-support/register"],"delay":false,"fullTrace":false,"exit":false,"asyncOnly":false,"parallel":false}
[2021-11-20 09:42:41.550] [DEBUG] Looking for test files ["server/test/**/*.test.js"] in /Volumes/src/front/project
[2021-11-20 09:42:41.552] [DEBUG] Found test files ["/Volumes/src/front/project/server/test/unit/lib/file1.test.js","/Volumes/src/front/project/server/test/unit/slp/file2.test.js","/Volumes/src/front/project/server/test/unit/slp/file3.test.js"]
[2021-11-20 09:42:41.552] [DEBUG] Using environment variables from config: {"NODE_ENV":"development"}
[2021-11-20 09:42:41.552] [DEBUG] Reading environment variables from /Volumes/src/front/project/server/config/test.env
[2021-11-20 09:42:41.555] [DEBUG] Spawning /Users/user/.vscode/extensions/hbenl.vscode-mocha-test-adapter-2.13.0/out/worker/bundle.js with IPC options {}
And that's it. That spawned process stays idling until it is killed:
1498677202 90810 89551 0 11:42AM ?? 0:00.29 /Users/user/.nvm/versions/node/v16.13.0/bin/node --loader quibble --no-warnings /Users/user/.vscode/extensions/hbenl.vscode-mocha-test-adapter-2.13.0/out/worker/bundle.js {}
Extension config has this line:
"mochaExplorer.nodeArgv": ["--loader", "quibble", "--no-warnings"],
Is it the issue with quibble
loader or some bug in this extension?
I have the same behavior with testdouble/quibble and mocha test explorer. On the command line the same thing works as intended. A solution or a workaround would be very appreciated.