Skip to content

Conversation

@nickrobillard
Copy link

@nickrobillard nickrobillard commented Sep 6, 2021

In order to have more flexibility and control over the command that is run, I have made the following changes:

  • Instead of hardcoding npm command as first spawn() 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 with npm. The default command is still npm 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:

  1. npm
  2. run
  3. testDebug
  4. $FILE_PATH_LOCAL

Screen Shot 2021-09-05 at 7 19 14 PM

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/node to 12.

Addresses #27 and #24.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant