-
Notifications
You must be signed in to change notification settings - Fork 30.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
--test-name-pattern needing to come before filenames is hostile to npm scripts #51384
Comments
@nodejs/test_runner @MoLow wdyt? FWIW:
You can do this using |
I run into this all the time and if I could remove the script |
➜ ~ node -v
v22.1.0
➜ ~ NODE_OPTIONS="--test-name-pattern" node
node: --test-name-pattern is not allowed in NODE_OPTIONS
➜ ~ NODE_OPTIONS="--test-name-pattern=\"foo\"" node
node: --test-name-pattern= is not allowed in NODE_OPTIONS |
If anyone wants to pick this up, it would involve updating the test runner's
My feeling is that doing this might introduce more issues than it solves, but I wouldn't block anyone from doing it (others people might though). |
FWIW:
So I'm not sure if it's worth checking a whole new set of arguments when there are other ways to achieve this. |
I'll throw in my 2 cents—I'm only just learning about node's testing suite, but it is definitely misleading that both
{
"scripts": {
"build": "node --test tests/*.js"
}
} and use it like this: npm build -- --test-name-pattern=@foo --test-skip-pattern=@bar No idea what the technical/practical implications of this change would be though since I'm new here, just seems like a more logical interface. |
What is the problem this feature will solve?
It is common practice to set up npm scripts for testing. E.g.
However, this cannot be combined with
--test-name-pattern
. Attempting to do so, e.g.will not work, because this gets translated to
which, I believe, ends up passing
--test-name-pattern="my pattern"
as an argument to these test files, instead of passing it as an argument to the test runner. The correct invocation isbut this is impossible to do via npm scripts, it seems. (See alternatives considered.)
What is the feature you are proposing to solve the problem?
I don't know what a good solution to this would be. Some possible ideas:
Special-case command line processing such that when
--test
is present,node
grabs the--test-name-pattern
argument for itself instead of passing it to scripts?Introduce a new binary, e.g.
node_test
, which processes command-line arguments in such a way? I believe this is how most test runners behave.Introduce a file-based customization of the test runner, including which tests to run, so that I don't have to pass the test filenames as arguments to the test runner in a way that causes this problem?
Improve npm scripts to support a better method of passing arguments in the middle of the script? (See below.)
What alternatives have you considered?
I investigated how to get npm scripts to substitute in arguments you pass to
npm run
into the script command, so that the translation becomes the correct one. This is a well-studied problem, and the following two Stack Overflow posts have the best answers, as far as I can tell:None of them seem very satisfactory, unfortunately. In particular, if you want something that works cross-platform, you basically have to write a wrapper script.
As an alternative, I could continue using other test runners, which support npm scripts better.
The text was updated successfully, but these errors were encountered: