-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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: do not require flags when executing a file #26858
Conversation
Instead of throwing an error in case a flag is missing, just start a `child_process` that includes all flags. This improves the situation for all developers in case they want to just plainly run a test. Co-authored-by: Rich Trott <[email protected]>
I often run tests in a little harness that reruns them if the test code changes, or the node executable rebuilds, and run them directly with ./out/Release/node (not tools/test.py, its waaaayyyy slow), so this would be quite helpful to me, thanks. |
I'm ambivalent about this change. On the one hand it's convenient. On the other it's "magic" and definatly not K.I.S.S...
Maybe put those lines in
Make it a bit more picky and you can add it to your |
@sam-github thanks for the review, I updated it similar to your suggestion. PTAL. CI https://ci.nodejs.org/job/node-test-pull-request/21847/
Everything around our flags is currently magical. This just makes it a lot more convenient to run the tests and it is especially significantly friendlier to newcomers. I also do not see that it makes the code more complex than it currently is, so is there any actual downside? @nodejs/testing PTAL |
I often run |
Our javascript unit tests files are intended to be runnable standalone, because depency of tests on external runners introduces complexity and difficulty in debugging. Usually they are runnable standalone, except sometimes they are only runnable with cooperation from a giant, undocumented, and difficult to understand glob of python (I say that as someone who has a half dozen times tried to figure out what some of its effectively undocumented command line arguments mean by reading the test.py source, unsucessfully). test.py seems to be the real black magic here. I like this pure-node approach so much I'd be in favour of the dependency of our javascript tests on the python runner being stripped out, and this way of running the tests becoming the default. As a developer friendly optimization, its great that the re-spawn of a child can be evaded when running with debuggers (gdb or inspector) by directly specifying the CLI options. This PR preserves that quality. 👍 |
My two cents: When debugging native code, I often use GDB with one of our tests and if I forget to specify flags, the test suite tells me. With this patch, when I forget to specify flags, I end up debugging the wrong process, and I don't think I'd notice that immediately (apart from "my breakpoints don't work"). Just a small concern, apart from that, it sounds like a great idea! |
@tniessen hm... I guess this is not a frequent use case for most users but it's definitely a very valid point. I guess we could have a blacklist for some environment variables or arguments that are used with GDB and the inspector. If anyone has a better idea, please let me know! |
I removed |
Challenge accepted 🔧
That's what I consider "magic". When the code tries to make non-trivial decisions for you... IMO the flag parsing could go into the stdlib, similar to |
@refack I don't think that parsing our test flags justifies adding another flag and it also contradicts the actual intention here: to reduce the overhead. All new developers would have to learn about the CLI flag and would always have to use it, that does not sound very user friendly. @tniessen I thought about it again and what about a very simple solution: adding a small user notification that the test is run with flags. That would a) remove the "magic" part as it's now clear what happens and b) everyone who forgot to add some flags while debugging native code would also realize that it's a different process. |
@BridgeAR I was about to propose a process warning but thought that might interfere with some tests. I like your idea! |
The hasCrypto check should be checked before anything else to prevent overhead in case it's not falsy. Otherwise the file would be read without any further benefit.
I added a comment. PTAL. |
Instead of throwing an error in case a flag is missing, just start a `child_process` that includes all flags. This improves the situation for all developers in case they want to just plainly run a test. Co-authored-by: Rich Trott <[email protected]> PR-URL: nodejs#26858 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
The hasCrypto check should be checked before anything else to prevent overhead in case it's not falsy. Otherwise the file would be read without any further benefit. PR-URL: nodejs#26858 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
Instead of throwing an error in case a flag is missing, just start a `child_process` that includes all flags. This improves the situation for all developers in case they want to just plainly run a test. Co-authored-by: Rich Trott <[email protected]> PR-URL: #26858 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
The hasCrypto check should be checked before anything else to prevent overhead in case it's not falsy. Otherwise the file would be read without any further benefit. PR-URL: #26858 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
Instead of throwing an error in case a flag is missing, just start a `child_process` that includes all flags. This improves the situation for all developers in case they want to just plainly run a test. Co-authored-by: Rich Trott <[email protected]> PR-URL: #26858 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Signed-off-by: Beth Griggs <[email protected]>
The hasCrypto check should be checked before anything else to prevent overhead in case it's not falsy. Otherwise the file would be read without any further benefit. PR-URL: #26858 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Signed-off-by: Beth Griggs <[email protected]>
Instead of throwing an error in case a flag is missing, just start
a
child_process
that includes all flags. This improves the situationfor all developers in case they want to just plainly run a test.
Co-authored-by: Rich Trott [email protected]
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes