Skip to content

Commit 31034ca

Browse files
committed
[node:test] add setup and watch for RunOptions
1 parent 77b183c commit 31034ca

6 files changed

Lines changed: 56 additions & 1 deletion

File tree

types/node/test.d.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,11 @@
7676
*
7777
* If any tests fail, the process exit code is set to `1`.
7878
* @since v18.0.0, v16.17.0
79-
* @see [source](https://github.com/nodejs/node/blob/v20.2.0/lib/test.js)
79+
* @see [source](https://github.com/nodejs/node/blob/v20.4.0/lib/test.js)
8080
*/
8181
declare module 'node:test' {
8282
import { Readable } from 'node:stream';
83+
import { AsyncResource } from 'node:async_hooks';
8384
/**
8485
* ```js
8586
* import { tap } from 'node:test/reporters';
@@ -295,6 +296,23 @@ declare module 'node:test' {
295296
* For each test that is executed, any corresponding test hooks, such as `beforeEach()`, are also run.
296297
*/
297298
testNamePatterns?: string | RegExp | string[] | RegExp[];
299+
/**
300+
* A function that accepts the TestsStream instance and can be used to setup listeners before any tests are run.
301+
*/
302+
setup?: (root: Test) => void | Promise<void>;
303+
/**
304+
* Whether to run in watch mode or not. Default: false.
305+
*/
306+
watch?: boolean;
307+
}
308+
class Test extends AsyncResource {
309+
concurrency: number;
310+
nesting: number;
311+
only: boolean;
312+
reporter: TestsStream;
313+
runOnlySubtests: boolean;
314+
testNumber: number;
315+
timeout: number | null;
298316
}
299317
/**
300318
* A successful call to `run()` method will return a new `TestsStream` object, streaming a series of events representing the execution of the tests.`TestsStream` will emit events, in the

types/node/test/test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ run({
2020
timeout: 100,
2121
inspectPort: () => 8081,
2222
testNamePatterns: ['executed'],
23+
setup: (root) => {},
24+
watch: true
2325
});
2426

2527
// TestsStream should be a NodeJS.ReadableStream

types/node/ts4.8/test.d.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
*/
8181
declare module 'node:test' {
8282
import { Readable } from 'node:stream';
83+
import { AsyncResource } from 'node:async_hooks';
8384
/**
8485
* ```js
8586
* import { tap } from 'node:test/reporters';
@@ -295,6 +296,23 @@ declare module 'node:test' {
295296
* For each test that is executed, any corresponding test hooks, such as `beforeEach()`, are also run.
296297
*/
297298
testNamePatterns?: string | RegExp | string[] | RegExp[];
299+
/**
300+
* A function that accepts the TestsStream instance and can be used to setup listeners before any tests are run.
301+
*/
302+
setup?: (root: unknown) => void | Promise<void>;
303+
/**
304+
* Whether to run in watch mode or not. Default: false.
305+
*/
306+
watch?: boolean;
307+
}
308+
class Test extends AsyncResource {
309+
concurrency: number;
310+
nesting: number;
311+
only: boolean;
312+
reporter: TestsStream;
313+
runOnlySubtests: boolean;
314+
testNumber: number;
315+
timeout: number | null;
298316
}
299317
/**
300318
* A successful call to `run()` method will return a new `TestsStream` object, streaming a series of events representing the execution of the tests.`TestsStream` will emit events, in the

types/node/ts4.8/test/test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ run({
2020
timeout: 100,
2121
inspectPort: () => 8081,
2222
testNamePatterns: ['executed'],
23+
setup: (root) => {},
24+
watch: true
2325
});
2426

2527
// TestsStream should be a NodeJS.ReadableStream

types/node/v18/test.d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* @see [source](https://github.com/nodejs/node/blob/v18.x/lib/test.js)
44
*/
55
declare module 'node:test' {
6+
import { AsyncResource } from 'node:async_hooks';
67
/**
78
* Programmatically start the test runner.
89
* @since v18.9.0
@@ -178,6 +179,19 @@ declare module 'node:test' {
178179
* incremented from the primary's `process.debugPort`.
179180
*/
180181
inspectPort?: number | (() => number) | undefined;
182+
/**
183+
* A function that accepts the TestsStream instance and can be used to setup listeners before any tests are run.
184+
*/
185+
setup?: (root: Test) => void | Promise<void>;
186+
}
187+
class Test extends AsyncResource {
188+
concurrency: number;
189+
nesting: number;
190+
only: boolean;
191+
reporter: TestsStream;
192+
runOnlySubtests: boolean;
193+
testNumber: number;
194+
timeout: number | null;
181195
}
182196

183197
/**

types/node/v18/test/test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ run({
1818
signal: new AbortController().signal,
1919
timeout: 100,
2020
inspectPort: () => 8081,
21+
setup: (root) => {},
2122
});
2223

2324
// TestsStream should be a NodeJS.ReadableStream

0 commit comments

Comments
 (0)