Skip to content

Commit d556fb5

Browse files
feat: flattern tests allowing --test-name-pattern filter (#50)
Co-authored-by: Kræn Hansen <kraen@elevenlabs.io>
1 parent 943ad7f commit d556fb5

2 files changed

Lines changed: 35 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: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,25 @@
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

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

9-
async function populateSuite(
10-
testContext: TestContext,
9+
function populateSuite(
1110
dir: string
12-
): Promise<void> {
11+
) {
1312
const { directories, files } = listDirectoryEntries(dir);
1413

1514
for (const file of files) {
16-
await testContext.test(file, () => runFileInSubprocess(dir, file));
15+
test(path.relative(TESTS_ROOT_PATH, path.join(dir, file)), () => runFileInSubprocess(dir, file));
1716
}
1817

1918
for (const directory of directories) {
20-
await testContext.test(directory, async (subTest) => {
21-
await populateSuite(subTest, path.join(dir, directory));
22-
});
19+
populateSuite(path.join(dir, directory));
2320
}
2421
}
2522

26-
test("harness", async (t) => {
27-
await populateSuite(t, path.join(TESTS_ROOT_PATH, "harness"));
28-
});
29-
30-
test("js-native-api", async (t) => {
31-
await populateSuite(t, path.join(TESTS_ROOT_PATH, "js-native-api"));
32-
});
33-
34-
test("node-api", async (t) => {
35-
await populateSuite(t, path.join(TESTS_ROOT_PATH, "node-api"));
36-
});
23+
populateSuite(path.join(TESTS_ROOT_PATH, "harness"));
24+
populateSuite(path.join(TESTS_ROOT_PATH, "js-native-api"));
25+
populateSuite(path.join(TESTS_ROOT_PATH, "node-api"));

0 commit comments

Comments
 (0)