Description
What is the problem this feature will solve?
It's interesting to see node:test
in core, and I wanted to investigate building a VS Code extension for it using our testing API so that users could run it from their UI (e.g. vitest).
Currently, running tests can solely be provided by modifying code with only
. This is quite problematic, since there are many UI gestures--in any test UI, not just VS Code--which rely on running specific tests. For example, clicking on a single test to debug, or more advanced actions like re-run failed tests. From my understanding of the docs, these cannot be implemented without requiring changes to code itself.
What is the feature you are proposing to solve the problem?
I request some way to narrow tests from the command line. The means of this are negotiable -- mocha has a "-g" option that allows grepping for full test names. However, this is based on having side-effect-free suite
s that allow tests to be enumerated and then grepped on, which node:test
does not have.
Instead, perhaps an argument like --test-only-paths="<json>"
, where <json>
is an array of test paths, such as:
[
["top level test", "subtest 1"],
["top level test", "subtest 2"]
]
Not very human-friendly, but easy for machines to deal with.
What alternatives have you considered?
We could alter the source code on disk to pass only
parameters to test()
. But this is pretty dangerous, if the transformation goes wrong or if the UI crashes before the transformation is rolled back. The closest we can get today is narrowing down to a single test file to run rather than the entire project, but this is still not a good experience.
Alternatively, we could use proxyquire or similar to wrap node:test
and inject our own "only" running. This is quite complicated, however, and I don't think it would work with ES modules.