Repository navigation
[node:test] Infinite loop occurs when files is empty #48823
Description
Activity
- addedtest_runnerIssues and PRs related to the test runner subsystem.Issues and PRs related to the test runner subsystem.
on Jul 18, 2023 I am not sure I would consider this a bug, you should either specify
filesor name the root file in some way that the default execution model won't detect it as a test file.
and, due to the fact the the default will change to be a glob pattern starting node 21 - I don't think it should be excluded in any wayDoes it mean that the
filesshould be specified? Or does it mean that it should not be excluded own file path?I don't think it should be excluded in any way
Would you prefer to modify the document in that case?
Default is written astest runner execution model
the file calling
runshould not be excludedSo, I think
Default matchingin the document should be removed. What do you think about it?why? it is still correct
Reacted by Benjamin GruenbaumI think
Defaultis the initial value that works that way if not specified.
For example, the initial values forconcurrencyandinspectPort,timeoutare described in the document.
However,fileswill not work if it is excluded.
I think this is different compared to otherDefault.So I think it should state that it cannot be omitted instead of
Default.How do I call the default file pattern like
node --testforrun?run({file: undefined})or justrun({})will use the default behaviorWhen I run
run({file: undefined})orrun({}), it's occurs Infinite loop. I want to solve it.So, I think
options.fileshas bug orDefaultin doc is not correct, when i create this issue.Could you please exec this code?
$ node -v v20.4.0 $ tree . └── run.js $ cat run.js require('node:test').run({ files: undefined }).compose(require('node:test/reporters').tap).pipe(process.stdout) # this code occurs infinite loop $ node run.js
run.jsis included inprocess.argvincreateFilesif i setfiles: undefined. It seems to refer to itself.
https://github.com/nodejs/node/blob/99881304c47138e09a06e6b2bd876cfdf840047e/lib/internal/test_runner/runner.js#L89C1-L93This happens with any file name.
My first sample code with a file name starting withtest-was bad. sorry.Reacted by Vladimir Grenaderovrun({file: undefined})or justrun({})will use the default behaviorIs that mean that 'node run.js' (which files: undefined) is equal to 'node --test run.js', as @koh110 explained? I don't think that such 'expected' behaviour is really expected. We should have note in docs, or some asserts in test-runner code to brake the loop.
Reacted by Kohta Ito@koh110 if you experience an infinate loop - that means the file called by
runhas a name that is detected as a test file (as described here - https://nodejs.org/api/test.html#test-runner-execution-model it probably has the wordtestin its name.
you can avoid that by changing the file name or not using the default files argument@MoLow It occurs with any file name. Could you please run this sample?
#48823 (comment)
This sample file is namedrun.jsand it is located in the root directory.
I think this is not part of the pattern.runcallcreateTestFileListwhenoptions.filesis empty.let testFiles = files ?? createTestFileList();
But
hasUserSuppliedPatternincreateTestFileListis always true whennode --test run.js.function createTestFileList() { const cwd = process.cwd(); const hasUserSuppliedPattern = process.argv.length > 1; const patterns = hasUserSuppliedPattern ? ArrayPrototypeSlice(process.argv, 1) : [kDefaultPattern];
process.argvcannot be empty when trying to call a file containingrun.So, I think
createTestFileListalways returns path ofrunthat named likeroot/a.js,root/b.js...2 remaining items
One way we could address this with a semver major change is to make
options.filesa required option. That would eliminate any surprise behavior.Reacted by Aranđel Šarenac@cjihrig Do you mean that the default file pattern like
node --testcannot be called fromrun?
#48823 (comment)Correct. Although we could expose an API to get that list.
@cjihrig Thanks. I understand thanks to your answer.
I look forward to seeing this issue resolved.Should I send a PR to require options.files in the docs?
Should I send a PR to require options.files in the docs?
Making it a required argument would also require a code change, but first let's see how other collaborators feel. There isn't really a rush because it's a breaking change so it wouldn't be released until October anyway.
OK, thanks.
I would like to create a draft PR how other collaborators feel. Is it more appropriate to create new issue?Should I send a PR to require options.files in the docs?
Making it a required argument would also require a code change, but first let's see how other collaborators feel. There isn't really a rush because it's a breaking change so it wouldn't be released until October anyway.
the next semver release will include glob support, and until we expose
fs.glob(wich I am working on doing) - I dont think we should make this requiredReacted by Colin Ihrighoever we can easily detect if
runis being called whenprocess.env.NODE_TEST_CONTEXTis set and warn/stop the executionReacted by Mert Can AltinIt's sounds good for me. If you give me the sample, I will make a PR.
hoever we can easily detect if run is being called when process.env.NODE_TEST_CONTEXT is set and warn/stop the execution
I would like to work on this.
makingoptions.filesa required option inrun()seems a good solution for this (ref).
WDYT @MoLow.It should not be required - it has a default value
- added a commit that references this issue
on Dec 10, 2023 - added a commit that references this issue
on Dec 15, 2023 - added a commit that references this issue
on Mar 25, 2024
Version
v20.4.0
Platform
Darwin MacBook-Pro.local 22.5.0 Darwin Kernel Version 22.5.0: Thu Jun 8 22:22:20 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T6000 arm64
Subsystem
No response
What steps will reproduce the bug?
This code occurs infinite loop.
How often does it reproduce? Is there a required condition?
everytime
What is the expected behavior? Why is that the expected behavior?
Default is written as
test runner execution model. But it does not work.https://nodejs.org/api/test.html#runoptions
It seems that tests that are run during
node --testshould be run whenfilesis empty.What do you see instead?
https://github.com/koh110/minimum-nodejs-test
Additional information
createTestFileListgets its own file path.It seems that it have to exclude own file path when executing in
run.node/lib/internal/test_runner/runner.js
Lines 90 to 92 in 9988130
node/lib/internal/test_runner/runner.js
Lines 473 to 477 in 9988130