NodeJS Test Runner Dry Run/Discovery? #4791
JustinGrote
started this conversation in
Ideas
Replies: 0 comments 1 reply
-
Without running tests, you'll likely need to parse the source code of the tests, much like the nodejs-testing VSCode extension does. If you're okay with a dry run approach that skips tests but runs everything outside of them. import { resolve } from 'node:path';
import { run } from 'node:test';
const events = run({
files: [resolve('sample.test.js')],
testNamePatterns: /^(?=a)b/, // skip all tests since there are no matches
});
const tests = [];
for await (const event of events) {
if (event.type !== 'test:start') continue;
tests.push(event.data);
}
console.log(tests);
// [
// {
// nesting: 0,
// name: 'test 1',
// line: 3,
// column: 1,
// file: 'file:///.../sample.test.js'
// },
// {
// nesting: 0,
// name: 'test 2',
// line: 5,
// column: 1,
// file: 'file:///.../sample.test.js'
// }
// ]
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
CC @targos
Is it possible programattically to discover what NodeJS tests are available but not actually run them?
I'm working on a Visual Studio Code extension to integrate the node test runner into the Testing API, however I can't really see a way to currently "dry run" or "discover" tests without actually executing them.
Beta Was this translation helpful? Give feedback.
All reactions