Skip to content
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-reporter and --test-reporter-destination flags are ignored if provided after script files #48177

Closed
piranna opened this issue May 25, 2023 · 9 comments
Labels
test_runner Issues and PRs related to the test runner subsystem.

Comments

@piranna
Copy link
Contributor

piranna commented May 25, 2023

Version

v20.2.0

Platform

Linux executive 5.19.0-42-generic #43-Ubuntu SMP PREEMPT_DYNAMIC Tue Apr 18 18:21:28 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

test runner

What steps will reproduce the bug?

Exec the test runner with the --test-reporter after specifying some scripts in the CLI, like node --experimental-test-coverage test.js dist/test.js --test-reporter=@mafalda-sfu/test-reporter-json.

How often does it reproduce? Is there a required condition?

Always.

What is the expected behavior? Why is that the expected behavior?

Provided reporter should be used.

What do you see instead?

Flag is ignored, and default spec reporter is being used.

Additional information

When provided the flag before the scripts, like in node --experimental-test-coverage --test-reporter=@mafalda-sfu/test-reporter-json test.js dist/test.js, reporter is being properly used.

@cjihrig
Copy link
Contributor

cjihrig commented May 25, 2023

This is basically the difference between process.execArgv and process.argv.

If anyone decides to work on this, it will likely either require changes to Node's internal command line argument parser to support this use case (which I would not advise), or doing another pass of command line argument parsing in the test runner itself on process.argv. The second option would be fine in most cases, but if any of the re-parsed CLI flags are used in C++ code via env->options(), I don't think it will work as is. I believe --experimental-test-coverage is the only test runner flag actually used in C++ at this point.

@kvakil kvakil added the test_runner Issues and PRs related to the test runner subsystem. label May 25, 2023
@piranna
Copy link
Contributor Author

piranna commented May 25, 2023

I believe --experimental-test-coverage is the only test runner flag actually used in C++ at this point.

I don't know, but I've found it also happens with --test-reporter-destination flag too.

@piranna piranna changed the title --test-reporter flag ignored if provided after script files --test-reporter and --test-reporter-destination flags are ignored if provided after script files May 25, 2023
@MoLow
Copy link
Member

MoLow commented May 28, 2023

how is this different that any other node flag? running node file.js --inspect will not start a inspector session, and node index.js --no-warnings can still emit warnings. so I don't really think this is an issue with these flags or if it is an issue at all.

@piranna
Copy link
Contributor Author

piranna commented May 29, 2023

how is this different that any other node flag? running node file.js --inspect will not start a inspector session, and node index.js --no-warnings can still emit warnings. so I don't really think this is an issue with these flags or if it is an issue at all.

Then maybe the issue is in the flags parser? That all of them should be accepted after the files?

@MoLow
Copy link
Member

MoLow commented May 29, 2023

I think the separation is necessary.
I would not want a CLI tool implemented in node to be limited in the flag names it can use.
just as an example - imagine a CLI tool that accepts an --eval flag, according to your suggestion - it will never work since node will execute --eval instead of the entry file at argv[1]

@MoLow MoLow closed this as not planned Won't fix, can't repro, duplicate, stale May 29, 2023
@piranna
Copy link
Contributor Author

piranna commented May 29, 2023

I think the separation is necessary.
I would not want a CLI tool implemented in node to be limited in the flag names it can use.
just as an example - imagine a CLI tool that accepts an --eval flag, according to your suggestion - it will never work since node will execute --eval instead of the entry file at argv[1]

I don't remember the exact details, but I think it's not working that way, that the -- string is used to split the Node.js args from the script ones, so your example doesn't apply.

My particular use case and the reason why I open this issue, is because I like to have a npm test script that's intented to be used by humans, and later be called it from Github Actions with npm test -- --test-reporter=@mafalda-sfu/test-reporter-json to change the output format for a computer processable one, but if npm test script ends with some files, the --test-reporter is being ignored without reason. If that's not the intended usage, please provide an example or reopen this issue or create a new one if it doesn't correspond to the test runner but the args parser, but I think usage of the NODE_OPTIONS environment variable is an anti-pattern here.

@MoLow
Copy link
Member

MoLow commented May 29, 2023

I think it's not working that way, that the -- string is used to split the Node.js args from the script ones, so your example doesn't apply.

no, it's simply the first positional argument (the main file name) that makes the distinction.

My particular use case and the reason why I open this issue, is because I like to have a npm test script that's intended to be used by humans, and later be called it from Github Actions

you can write a script that prases args and passes them to node, or use NODE_OPTIONS

@piranna
Copy link
Contributor Author

piranna commented May 29, 2023

it's simply the first positional argument (the main file name) that makes the distinction.

Is there any CLI arg to define the script file(s), or just only positional arguments? That could be another alternative, so no positional arguments are provided.

@piranna
Copy link
Contributor Author

piranna commented Jul 27, 2023

or use NODE_OPTIONS

This did the trick, thanks :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test_runner Issues and PRs related to the test runner subsystem.
Projects
None yet
Development

No branches or pull requests

5 participants
@piranna @cjihrig @MoLow @kvakil and others