Skip to content

Commit 5c4ead1

Browse files
committed
Add TestContext.workerId to node:test type definitions
Refs: nodejs/node#61394 Signed-off-by: Ali Hassan <[email protected]>
1 parent 5db8abf commit 5c4ead1

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

types/node/node-tests/test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ test(undefined, undefined, t => {
175175
t.error;
176176
// $ExpectType number
177177
t.attempt;
178+
// $ExpectType number | undefined
179+
t.workerId;
178180
});
179181

180182
// Test the subtest approach.

types/node/test.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,15 @@ declare module "node:test" {
983983
* @since v21.7.0, v20.12.0
984984
*/
985985
readonly attempt: number;
986+
/**
987+
* The unique identifier of the worker running the current test file.
988+
* When running tests with `--test-isolation=process` (the default), each test
989+
* file runs in a separate child process and is assigned a worker ID from 1 to N,
990+
* where N is the number of concurrent workers. When running with
991+
* `--test-isolation=none`, all tests run in the same process and the worker ID
992+
* is always 1. This value is `undefined` when not running in a test context.
993+
*/
994+
readonly workerId: number | undefined;
986995
/**
987996
* This function is used to set the number of assertions and subtests that are expected to run
988997
* within the test. If the number of assertions and subtests that run does not match the

types/node/v24/test.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,15 @@ declare module "node:test" {
989989
*/
990990
readonly assert: TestContextAssert;
991991
readonly attempt: number;
992+
/**
993+
* The unique identifier of the worker running the current test file.
994+
* When running tests with `--test-isolation=process` (the default), each test
995+
* file runs in a separate child process and is assigned a worker ID from 1 to N,
996+
* where N is the number of concurrent workers. When running with
997+
* `--test-isolation=none`, all tests run in the same process and the worker ID
998+
* is always 1. This value is `undefined` when not running in a test context.
999+
*/
1000+
readonly workerId: number | undefined;
9921001
/**
9931002
* This function is used to create a hook running before subtest of the current test.
9941003
* @param fn The hook function. The first argument to this function is a `TestContext` object.

0 commit comments

Comments
 (0)