Add flexibility to run any command (with current file path placeholders)
In order to have more flexibility and control over the command that is run, I have made the following changes:
- Instead of hardcoding
npmcommand as firstspawn()arg, I have made it so that any command can be used. This allows one to use any custom command - like docker commands or anything else that does not begin withnpm. The default command is stillnpm test. Along with this comes the security implication that any malicious command could do serious damage. - Includes command placeholders for current file path so that you can just target the current file you are editing.
Due to the nature of spawn(), I have replaced the current "testScript" config textfield with an array of strings named "testCommandArray". Array item 0 is used as the first spawn() arg, and the rest are passed into spawn() arg 2.
Here is an example with placeholders. The following configuration is an array of 4 strings:
- npm
- run
- testDebug
- $FILE_PATH_LOCAL
Which has this JSON representation:
"nodeTdd.testCommandArray": [
"npm",
"run",
"testDebug",
"$FILE_PATH_LOCAL"
]
The command that is run looks like: npm run testDebug test/something.test.js. If your test runner requires other command line args like a -- before the file path arg, you have the flexibility to add that. I tried using docker & docker-compose exec/run commands using this approach and it works as long as you do not allocate a TTY (see -t and -T flags).
Just a note about the changes:
-
.vscode/tasks.json- these were made automatically by VSCode. -
package.json- I updated the deps to latest versions. These changes are probably not required, and may affect older Node version (8?) compatibility. I updated@types/nodeto 12.
Addresses https://github.com/prashaantt/node-tdd/issues/27 and https://github.com/prashaantt/node-tdd/issues/24.