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

[node:test] Support for file path patterns in run() #48609

Closed
mdrobny opened this issue Jun 30, 2023 · 6 comments · Fixed by #51912
Closed

[node:test] Support for file path patterns in run() #48609

mdrobny opened this issue Jun 30, 2023 · 6 comments · Fixed by #51912
Labels
feature request Issues that request new features to be added to Node.js. never-stale Mark issue so that it is never considered stale test_runner Issues and PRs related to the test runner subsystem.

Comments

@mdrobny
Copy link
Contributor

mdrobny commented Jun 30, 2023

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:

node --test src/**/*.test.js

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()

node runTests.mjs src/**/*.test.js

but I would like to define file name patterns in runTests.mjs file, based on different conditions.

My use case is to differentiate between unit and integration tests in runTests.mjs

What is the feature you are proposing to solve the problem?

Add new option to run() function

filePathPatterns or filePatterns or testFilePathPatterns - to specify which files test runner should run by glob pattern, like in CLI

  • type: Array<string>
  • example 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 Glob implementation has an exclude option so that's what I am talking about

What alternatives have you considered?

Using only CLI for running tests, avoid using run()

@mdrobny mdrobny added the feature request Issues that request new features to be added to Node.js. label Jun 30, 2023
@atlowChemi atlowChemi added the test_runner Issues and PRs related to the test runner subsystem. label Jun 30, 2023
@MoLow
Copy link
Member

MoLow commented Jul 2, 2023

What you are really asking for is glob being exposed on fs, so you can run

run({ files: fs.glob("**/*.test.js") });

I am +1 on exposing glob, but that requires some more work, with making mini-match more primordials friendly

@rluvaton
Copy link
Member

rluvaton commented Jul 2, 2023

an alternative is to use some glob npm package and pass the paths to the files property

@mdrobny
Copy link
Contributor Author

mdrobny commented Jul 3, 2023

@MoLow

What 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 expose glob in Node.js FS API since agreeing on "the best" API for this function is difficult 😄

I was positively surprised seeing that node:test already uses internal Glob functionality so I thought it will be rather easy and even consistent to use it in run() function also, same as in CLI options

@mdrobny
Copy link
Contributor Author

mdrobny commented Jul 3, 2023

@rluvaton

an 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

@jbergstroem
Copy link
Member

This would also help the typescript case where you pass a --loader but since you can't tell the test runner how to discover files you're left doing the globbing part on your own.

Copy link
Contributor

github-actions bot commented Jan 1, 2024

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.

@github-actions github-actions bot added the stale label Jan 1, 2024
@MoLow MoLow added never-stale Mark issue so that it is never considered stale and removed stale labels Jan 2, 2024
@MoLow MoLow linked a pull request Feb 28, 2024 that will close this issue
@RedYetiDev RedYetiDev moved this from Awaiting Triage to Done in Node.js feature requests Jun 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js. never-stale Mark issue so that it is never considered stale test_runner Issues and PRs related to the test runner subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants
@jbergstroem @mdrobny @MoLow @rluvaton @atlowChemi and others