Repository navigation
[node:test] Support for file path patterns in run() #48609
Description
Activity
- addedfeature requestIssues requesting new Node.js features.Issues requesting new Node.js features.
on Jun 30, 2023 - addedtest_runnerIssues and PRs related to the test runner subsystem.Issues and PRs related to the test runner subsystem.
on Jun 30, 2023 What you are really asking for is
globbeing exposed on fs, so you can runrun({ files: fs.glob("**/*.test.js") });
I am +1 on exposing glob, but that requires some more work, with making mini-match more primordials friendly
an alternative is to use some glob npm package and pass the paths to the files property
Reacted by Michał DrobniakWhat you are really asking for is glob being exposed on fs
That would mostly solve my problem indeed.
But I know it will be rather difficult to exposeglobin Node.js FS API since agreeing on "the best" API for this function is difficult 😄I was positively surprised seeing that
node:testalready uses internal Glob functionality so I thought it will be rather easy and even consistent to use it inrun()function also, same as in CLI optionsReacted by Moshe Atlowan alternative is to use some glob npm package and pass the paths to the files property
yep, I mentioned that in the initial description
I need to use e.g. [glob package](https://github.com/isaacs/node-glob) to find files:)but that slightly defeats one of the goals of built-in Node.js test runner - to not install external dependencies to run your tests
Reacted by AyushThis would also help the typescript case where you pass a
--loaderbut since you can't tell the test runner how to discover files you're left doing the globbing part on your own.There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment.
For more information on how the project manages feature requests, please consult the feature request management document.
- addedstaleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.Issues and PRs marked stale due to inactivity and scheduled for automatic closure.
on Jan 1, 2024 - addednever-staleIssues and PRs exempt from automated stale handling.Issues and PRs exempt from automated stale handling.and removedstaleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.Issues and PRs marked stale due to inactivity and scheduled for automatic closure.
on Jan 2, 2024 - linked a pull request that will close this issuefs: expose glob and globSync #51912
on Feb 28, 2024
What is the problem this feature will solve?
It's quite difficult to run test files matching a "file name pattern" when using
run()function.It's easy when using CLI, for example:
It's difficult because it only allows to pass file paths in files option which means I need to use e.g. glob package to find files when I want to replicate the same behaviour when using CLI.
I see it's possible to still provide test file name pattern as command option when when using
run()but I would like to define file name patterns in
runTests.mjsfile, based on different conditions.My use case is to differentiate between unit and integration tests in
runTests.mjsWhat is the feature you are proposing to solve the problem?
Add new option to
run()functionfilePathPatternsorfilePatternsortestFilePathPatterns- to specify which files test runner should run by glob pattern, like in CLIArray<string>filePathPatterns: ['src/**/*.integration.test.js']Additional option to ignore
It would be great to be able to also ignore some tests by file path pattern
so another option like
filePathIgnorePatterns- to specify which files should be ignored by test runner to allow running only selected set of tests (e.g. only integration tests)I see that internal
Globimplementation has an exclude option so that's what I am talking aboutWhat alternatives have you considered?
Using only CLI for running tests, avoid using
run()