Skip to content

Commit 900de5c

Browse files
committed
feat(cli): expose the test name via t.name in the test runner
1 parent 62f4d90 commit 900de5c

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

packages/cli/src/testing/runner.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { AssertionError, deepStrictEqual } from "assert";
22
import { url } from "inspector";
3-
import { isNil, newLogger } from "@compas/stdlib";
3+
import { AppError, isNil, newLogger } from "@compas/stdlib";
44
import { markTestFailuresRecursively } from "./printer.js";
55
import { setTestTimeout, state, testLogger, timeout } from "./state.js";
66

@@ -138,6 +138,7 @@ function createRunnerForState(testState, abortSignal) {
138138
},
139139
}),
140140
signal: abortSignal,
141+
name: testState.name,
141142
ok: ok.bind(undefined, testState),
142143
notOk: notOk.bind(undefined, testState),
143144
equal: equal.bind(undefined, testState),
@@ -170,9 +171,10 @@ function mutateRunnerEnablingWarnings(runner) {
170171
const implementation = runner[method];
171172

172173
runner[method] = (...args) => {
173-
runner.log.error(
174-
`warning: called 't.${method}' on parent 't'. Accept 't' as argument in the callback of 't.test(msg, callback)'.`,
175-
);
174+
runner.log.error({
175+
message: `warning: called 't.${method}' on parent 't'. Accept 't' as argument in the callback of 't.test(msg, callback)'.`,
176+
stackTrace: AppError.format(AppError.serverError({})),
177+
});
176178

177179
implementation(...args);
178180
};

packages/cli/src/testing/runner.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import { runTestsRecursively } from "./runner.js";
66
mainTestFn(import.meta);
77

88
test("cli/testing/runner", (t) => {
9+
t.test("my test name", (t) => {
10+
t.equal(t.name, "my test name");
11+
});
12+
913
t.test(
1014
"runTestsRecursively - catch assertion errors strictEqual",
1115
async (t) => {

packages/cli/types/advanced-types.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ export interface TestRunner {
77
*/
88
log: import("@compas/stdlib").Logger;
99

10+
/**
11+
* The test name as provided as the first argument to 'test' or 't.test'
12+
*/
13+
name: string;
14+
1015
/**
1116
* Configurable timeout used for sub tests
1217
*/

0 commit comments

Comments
 (0)