nodejs-testing icon indicating copy to clipboard operation
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

Open ifeanyiecheruo opened this issue 3 months ago • 1 comments

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

  • Hold reference to the return value of spawn and call .kill on that reference on the next attempt to run pre-test
  • spawn the pretest command detached in order to be able to kill and child processes the pretest command started

ifeanyiecheruo avatar Aug 17 '25 20:08 ifeanyiecheruo