This repository has been archived by the owner on May 1, 2024. It is now read-only.
How to pass arguments to the node:test runner with npm test
?
#1069
Unanswered
Malvineous
asked this question in
CLI
Replies: 2 comments
-
I don't think there's any solution short of a script, unless node wants to change its test runner to work with the existing npm facilities. |
Beta Was this translation helpful? Give feedback.
0 replies
-
With Yarn (and only Yarn at this time, being a special syntax) you'd write this to interpolate arguments in the middle of the command: {
"scripts": {
"test": "node --test $@ **/*.test.js"
}
} That said, it feels like options should be accepted anywhere in the command line. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Node 18 introduced a new test runner, which allows
package.json
scripts like this:The problem is, if you want to pass additional options to the test runner, such as
--test-name-pattern="My test"
then it doesn't work:This is because Node requires all these parameters to be specified before the filenames on its command line, whereas npm adds them onto the end of the command line. This means you have to copy the command out of
package.json
and run it manually:What is the preferred solution for having the parameters passed to
npm
put before the filenames in the final node command?I have seen workarounds using various shell features and environment variables but they all appear to be platform-specific rather than a single solution that runs everywhere npm does.
Given that unit testing is now part of Node itself, it would be good to be able to make use of it with the existing npm facilities if possible.
Beta Was this translation helpful? Give feedback.
All reactions