nodejs-testing
nodejs-testing copied to clipboard
Support for multi-root workspaces?
I have a monorepo setup which uses a VS Code Multi-root Workspace. In this project I have two subprojects, one for a backend NodeJS service and one for a React UI. I use node's test runner for the backend project but for the UI tests I use other tools. My project setup in case it helps: https://github.com/pfaffle/armada-analyzer/blob/main/armada-analyzer.code-workspace
At the moment, the extension detects my backend tests twice, once as a subdirectory of the root project and once as a subdirectory of the "service" project which is a bit confusing and unnecessary.
I would like to be able to configure this extension on a per-subproject level and use it only for the backend subproject and disable it for the UI one and for the root project (which has no code of its own). Is there a good way to do that now? VS Code only seems to allow me to configure it in the root project.
You could set "nodejs-testing.extensions": [] in the folder you want to disable it in (in .vscode/settings.json within that folder)
I added
{ "nodejs-testing.extensions": [] }
to /.vscode/settings.json in the subproject folder, but VS Code says that it won't apply here:
I'm able to get the behavior I want if I set
"nodejs-testing.include": ["./dist/tests"]
in my root workspace's config, because the only project where that's a valid path is the one I want it to scan, but I can see that it's actually applying that setting to each workspace in my project individually because if I create tests under that path in one of the other workspace directories, they show up too in VS Code.
Since there is not way to redefine rules on folder level like noted in https://github.com/connor4312/nodejs-testing/issues/59#issuecomment-2542577281, I have to use ".code-workspace" settings file to define different settings for different folders in my monorepo. But it doesn't work fine too, because look like first array's elem (extensions.paramenters[0]) overwrites second one (extensions.paramenters[1]). I basically can't apply different node parameters for different folders.
My config:
"nodejs-testing.extensions": [
{
"extensions": ["ts"],
"parameters": [
"--import", "tsx",
"--import", "./tests/setup/init-env.ts",
"--import", "dotenv/config",
],
"filePatterns": [
"backend-api/tests/**/*.test.ts",
],
},
{
"extensions": ["ts"],
"parameters": [
"--experimental-strip-types",
"--disable-warning=ExperimentalWarning",
],
"filePatterns": [
"shared/lib/tests/**/*.ts",
],
},
],