Closed
Labels
feature requestIssues requesting new Node.js features.Issues requesting new Node.js features.test_runnerIssues and PRs related to the test runner subsystem.Issues and PRs related to the test runner subsystem.
Description
What is the problem this feature will solve?
The builtin node:test functionality does not accommodate Custom ESM Loaders for specifying tests. The documented test-runner-execution-mode only matches .js | .cjs | .mjs extension files.
What is the feature you are proposing to solve the problem?
Ideally, the test-runner-execution-mode would allow for registered Custom ESM Loaders automatically. If not possible, specifying allowed file extensions via environment variable would work.
What alternatives have you considered?
Current workaround is a manual shim -- using a standard file extension and importing the Custom ESM modules from there.
Reacted by Fardjad Davari, mori yuta, Steven, Scott Moore and Daniel Perez
Metadata
Metadata
Assignees
Labels
feature requestIssues requesting new Node.js features.Issues requesting new Node.js features.test_runnerIssues and PRs related to the test runner subsystem.Issues and PRs related to the test runner subsystem.
Activity
aduh95 commentedon Jan 21, 2023
FWIW here's the workaround I'm using on a project of mine:
And I have this in my
package.json:{ "scripts": { "test": "node --loader '#ts-loader' test/index.ts", "test-only": "node --test-only --loader '#ts-loader' test/index.ts" } }The above "just works" if you're using
node:test(or any other test lib btw).You can also specify custom loader hooks in the
NODE_OPTIONSenv variable, which is then used bynode --testwhen loading sub-files.But I guess what you meant was asking for a solution to provide custom file extensions / file name patterns for
--testCLI flag, which I agree would be nice and doesn't have a solution yet. There have been discussions around adding a config file for Node.js entrypoint to specify those kind of things (file name patterns for--test, custom loader hooks, etc.) but no one is championing this AFAIK. I personally kind of wish that userland would come up with ad-hoc solutions and we would just have to pick the most popular one so we know the API is aligned with what the community needs/wants.shanewholloway commentedon Jan 23, 2023
Thanks for the concise and helpful
findTestFilesworkaround code.Yes, I'm advocating for direct support of custom loader files in the test suite. It would allow for leveraging features like parallelization in the new
node:testrunner. As it is now, I'm excited to have a builtin test system, file watcher, and custom loaders!MoLow commentedon Jan 24, 2023
Ideally I would love if the test runner can support a glob expression, that will require glob support in core
robcresswell commentedon Jul 1, 2023
In case anyone else is following this, I think this is solved by #47653 from @MoLow as referenced above; it was somewhat difficult for me to understand because the CI seems to use some kind of magic and "closes" PRs instead of "merging" them