I'm trying to create a configuration in my launch.json which will run npm test in the folder in which the .js file resides. Running npm test manually in a terminal works fine, taking the relevant command from the scripts part of my package.json:
"scripts": {
"start": "node --experimental-json-modules nodeserver.js",
"test": "export MY_VAR=abc && node --experimental-json-modules nodeserver.js"
},
In particular, when running npm test directly in a terminal, the env var specified in the test script line takes effect and the --experimental-json-modules flag is passed to node.
This is my launch.json:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"command": "npm test",
"name": "Run npm test",
"request": "launch",
"type": "node-terminal"
}
]
}
This is pretty much as-is from one of the predefined options suggested in the editor, and is very similar to this.
But when I run this configuration on the nodeserver.js file, I get:
It seems to be running node without the flag I specified in the configuration? What am I misunderstanding about how this launch.json scheme works?
EDIT the more I've played around, the more it seems as if the configuration is just being completely ignored, so that it is using the default node.js configuration... I'm selecting the config from the drop-down and pressing the play icon:
Should that work?
Apart from running npm start in a terminal, the only "automatic" way of getting this to work is by opening the package.json and clicking on the little Debug button which appears by the scripts tag:
But I'd like to figure out how to use launch.json properly so that I can pass environments variables etc via that instead.


