Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions implementors/node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ Run the following command to run the tests:
$ npm run node:test
```

To run a specific test file, use the `--test-name-pattern` flag:
To run a specific test suite or file, use the `--test-name-pattern` flag:

```bash
$ NODE_OPTIONS=--test-name-pattern=js-native-api/test_constructor/test_null npm run node:test
$ NODE_OPTIONS=--test-name-pattern=test_constructor npm run node:test
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are test files with the same name in different folders, like js-native-api/2_function_arguments/test and js-native-api/3_callbacks/test. I think it is still helpful to be able to filter tests with a path.

```

The test names are their relative path to the `tests` folder, with file extensions.
The pattern matches against suite names (directory names) and test names (file names)
at any level of the hierarchy. When a suite matches, all tests inside it run.
The pattern can be a regular expression.
26 changes: 17 additions & 9 deletions implementors/node/run-tests.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
import path from "node:path";
import { test } from "node:test";
import { suite, test } from "node:test";

import { listDirectoryEntries, runFileInSubprocess } from "./tests.ts";

const ROOT_PATH = path.resolve(import.meta.dirname, "..", "..");
const TESTS_ROOT_PATH = path.join(ROOT_PATH, "tests");

function populateSuite(
dir: string
) {
function populateSuite(dir: string) {
const { directories, files } = listDirectoryEntries(dir);

for (const file of files) {
test(path.relative(TESTS_ROOT_PATH, path.join(dir, file)), () => runFileInSubprocess(dir, file));
test(file, () => runFileInSubprocess(dir, file));
}

for (const directory of directories) {
populateSuite(path.join(dir, directory));
suite(directory, () => {
populateSuite(path.join(dir, directory));
});
}
}

populateSuite(path.join(TESTS_ROOT_PATH, "harness"));
populateSuite(path.join(TESTS_ROOT_PATH, "js-native-api"));
populateSuite(path.join(TESTS_ROOT_PATH, "node-api"));
suite("harness", () => {
populateSuite(path.join(TESTS_ROOT_PATH, "harness"));
});

suite("js-native-api", () => {
populateSuite(path.join(TESTS_ROOT_PATH, "js-native-api"));
});

suite("node-api", () => {
populateSuite(path.join(TESTS_ROOT_PATH, "node-api"));
});
Loading