nodejs-testing
nodejs-testing copied to clipboard
[Windows only] Specifying a .bat or .cmd file as the pretest command causes the extension to hang before running tests
This invocation of spawn() will hang on Windows if the pretest command is a .bat or .cmd file.
The node documentation indicates that in order for that scenario to work we need to pass the shell options set to true
const cp = spawn(cmd[0], cmd.slice(1), { stdio: "pipe", cwd, shell: true });
This matters because my pretest command is ["npm.cmd", "run-script", "pretest"].
["npm", "run-script", "pretest"] fails with ENOENT on Windows because npm is implemented as a .cmd script.
Ironically using { shell: true } will make ["npm", "run-script", "pretest"] work correctly.
Out of scope but additionally this logic guarantees that if the above hang happens, you will never be able to launch any other pretest command until you restart vscode. It may be worthwhile to