Skip to content

Commit 4755ba4

Browse files
committed
feat: flattern tests allowing --test-name-pattern filter
1 parent 86d68d3 commit 4755ba4

2 files changed

Lines changed: 36 additions & 19 deletions

File tree

implementors/node/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Harness of Node.js
2+
3+
## Build addons
4+
5+
To build the addons, run the following command:
6+
7+
```bash
8+
$ npm run addons:configure
9+
$ npm run addons:build
10+
```
11+
12+
## Running tests
13+
14+
Run the following command to run the tests:
15+
16+
```bash
17+
$ npm run node:test
18+
```
19+
20+
To run a specific test file, use the `--test-name-pattern` flag:
21+
22+
```bash
23+
$ NODE_OPTIONS=--test-name-pattern=js-native-api/test_constructor/test_null npm run node:test
24+
```
25+
26+
The test names are their relative path to the `tests` folder, with file extensions.
27+
The pattern can be a regular expression.

implementors/node/run-tests.ts

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import path from "node:path";
2-
import { test, type TestContext } from "node:test";
2+
import { test } from "node:test";
33

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

@@ -19,31 +19,21 @@ const LOAD_ADDON_MODULE_PATH = path.join(
1919
"load-addon.js"
2020
);
2121

22-
async function populateSuite(
23-
testContext: TestContext,
22+
23+
function populateSuite(
2424
dir: string
25-
): Promise<void> {
25+
) {
2626
const { directories, files } = listDirectoryEntries(dir);
2727

2828
for (const file of files) {
29-
await testContext.test(file, () => runFileInSubprocess(dir, file));
29+
test(path.relative(TESTS_ROOT_PATH, path.join(dir, file)), () => runFileInSubprocess(dir, file));
3030
}
3131

3232
for (const directory of directories) {
33-
await testContext.test(directory, async (subTest) => {
34-
await populateSuite(subTest, path.join(dir, directory));
35-
});
33+
populateSuite(path.join(dir, directory));
3634
}
3735
}
3836

39-
test("harness", async (t) => {
40-
await populateSuite(t, path.join(TESTS_ROOT_PATH, "harness"));
41-
});
42-
43-
test("js-native-api", async (t) => {
44-
await populateSuite(t, path.join(TESTS_ROOT_PATH, "js-native-api"));
45-
});
46-
47-
test("node-api", async (t) => {
48-
await populateSuite(t, path.join(TESTS_ROOT_PATH, "node-api"));
49-
});
37+
populateSuite(path.join(TESTS_ROOT_PATH, "harness"));
38+
populateSuite(path.join(TESTS_ROOT_PATH, "js-native-api"));
39+
populateSuite(path.join(TESTS_ROOT_PATH, "node-api"));

0 commit comments

Comments
 (0)