Skip to content

[Windows only] Specifying a .bat or .cmd file as the pretest command causes the extension to hang before running tests #73

@ifeanyiecheruo

Description

@ifeanyiecheruo

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions