connor4312 / connor4312/nodejs-testing
[Windows only] Specifying a .bat or .cmd file as the pretest command causes the extension to hang before running tests
- Dominant language
- TypeScript
- Stars
- 67
- Forks
- 15
- PR merge metrics
- No merged PRs in 30d
Description
[This invocation of spawn()](https://github.com/connor4312/nodejs-testing/blob/ee39d460a353f2bbaa01f513f94f207738c37b3c/src/pretest.ts#L41C7-L41C13) will hang on Windows if the pretest command is a `.bat` or `.cmd` file.
The [node](https://nodejs.org/api/child_process.html#spawning-bat-and-cmd-files-on-windows) documentation indicates that in order for that scenario to work we need to pass the `shell` options set to `true`
```javascript
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](https://github.com/connor4312/nodejs-testing/blob/ee39d460a353f2bbaa01f513f94f207738c37b3c/src/pretest.ts#L25) 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](https://nodejs.org/api/child_process.html#subprocesskillsignal) on that reference on the next attempt to run pre-test
- spawn the pretest command [detached ](https://nodejs.org/api/child_process.html#optionsdetached) in order to be able to kill and child processes the pretest command started
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.