From ceaeda3ca77137555cf93d08318b4b2d93fc7858 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kr=C3=A6n=20Hansen?= Date: Sun, 26 Apr 2026 00:02:03 +0200 Subject: [PATCH] refactor: use suite/test for hierarchical test structure Replace flat test() calls with suite/test nesting so test output shows the directory hierarchy while still supporting --test-name-pattern filtering at any level (suite or leaf test). Co-Authored-By: Claude Opus 4.6 --- implementors/node/README.md | 7 ++++--- implementors/node/run-tests.ts | 26 +++++++++++++++++--------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/implementors/node/README.md b/implementors/node/README.md index d6aca27..7bd0e9f 100644 --- a/implementors/node/README.md +++ b/implementors/node/README.md @@ -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 ``` -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. diff --git a/implementors/node/run-tests.ts b/implementors/node/run-tests.ts index 3656981..c405690 100644 --- a/implementors/node/run-tests.ts +++ b/implementors/node/run-tests.ts @@ -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")); +});