aws-delivlib 15.4.0 → 15.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/custom-resource-handlers/src/certificate-signing-request.tsbuildinfo +1 -1
- package/lib/custom-resource-handlers/src/pgp-secret.tsbuildinfo +1 -1
- package/lib/custom-resource-handlers/src/private-key.tsbuildinfo +1 -1
- package/lib/package-integrity/handler/validate.bundle.js +11361 -9248
- package/lib/publishing/github/node_modules/.yarn-integrity +5 -5
- package/lib/publishing/github/node_modules/@types/aws-lambda/README.md +1 -1
- package/lib/publishing/github/node_modules/@types/aws-lambda/package.json +2 -2
- package/lib/publishing/github/node_modules/@types/aws-lambda/trigger/api-gateway-proxy.d.ts +2 -2
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/README.md +3 -3
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/assert/strict.d.ts +13 -56
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/assert.d.ts +189 -190
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/async_hooks.d.ts +151 -43
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/buffer.buffer.d.ts +12 -13
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/buffer.d.ts +103 -237
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/child_process.d.ts +40 -155
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/cluster.d.ts +238 -384
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/console.d.ts +45 -404
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/constants.d.ts +3 -10
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/crypto.d.ts +1019 -1600
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/dgram.d.ts +133 -81
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/diagnostics_channel.d.ts +277 -59
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/dns/promises.d.ts +9 -15
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/dns.d.ts +136 -183
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/domain.d.ts +12 -32
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/events.d.ts +872 -840
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/ffi.d.ts +500 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/fs/promises.d.ts +256 -85
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/fs.d.ts +865 -525
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/globals.d.ts +12 -34
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/globals.typedarray.d.ts +63 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/http.d.ts +433 -312
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/http2.d.ts +548 -893
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/https.d.ts +64 -243
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/index.d.ts +25 -7
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/inspector/promises.d.ts +35 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/inspector.d.ts +70 -58
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/inspector.generated.d.ts +764 -410
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/module.d.ts +54 -219
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/net.d.ts +224 -226
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/os.d.ts +41 -49
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/package.json +13 -18
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/path/posix.d.ts +8 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/path/win32.d.ts +8 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/path.d.ts +119 -141
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/perf_hooks.d.ts +339 -690
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/process.d.ts +390 -205
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/punycode.d.ts +3 -31
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/querystring.d.ts +3 -16
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/quic.d.ts +2191 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/readline/promises.d.ts +3 -6
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/readline.d.ts +66 -152
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/repl.d.ts +101 -109
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/sea.d.ts +1 -116
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/sqlite.d.ts +486 -68
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/stream/consumers.d.ts +91 -15
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/stream/iter.d.ts +449 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/stream/promises.d.ts +136 -15
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/stream/web.d.ts +197 -454
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/stream.d.ts +603 -491
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/string_decoder.d.ts +3 -43
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/test/reporters.d.ts +60 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/test.d.ts +585 -292
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/timers/promises.d.ts +3 -18
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/timers.d.ts +3 -141
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/tls.d.ts +180 -267
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/trace_events.d.ts +3 -97
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/ts5.6/buffer.buffer.d.ts +7 -8
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/ts5.6/compatibility/float16array.d.ts +71 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/ts5.6/globals.typedarray.d.ts +2 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/ts5.6/index.d.ts +26 -6
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/ts5.7/compatibility/float16array.d.ts +72 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/ts5.7/index.d.ts +118 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/tty.d.ts +61 -43
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/url.d.ts +156 -584
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/util/types.d.ts +558 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/util.d.ts +173 -1099
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/v8.d.ts +175 -36
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/vfs.d.ts +211 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/vm.d.ts +293 -209
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/wasi.d.ts +24 -74
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/web-globals/abortcontroller.d.ts +27 -2
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/web-globals/blob.d.ts +23 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/web-globals/console.d.ts +9 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/web-globals/crypto.d.ts +39 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/web-globals/domexception.d.ts +15 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/web-globals/encoding.d.ts +11 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/web-globals/events.d.ts +9 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/web-globals/fetch.d.ts +14 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/web-globals/importmeta.d.ts +13 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/web-globals/messaging.d.ts +23 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/web-globals/navigator.d.ts +3 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/web-globals/performance.d.ts +45 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/web-globals/streams.d.ts +97 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/web-globals/timers.d.ts +44 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/web-globals/url.d.ts +24 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/worker_threads.d.ts +260 -407
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/zlib/iter.d.ts +131 -0
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/zlib.d.ts +782 -165
- package/lib/publishing/github/node_modules/semver/classes/range.js +2 -2
- package/lib/publishing/github/node_modules/semver/internal/constants.js +30 -0
- package/lib/publishing/github/node_modules/semver/internal/trim-comparator-whitespace.js +438 -0
- package/lib/publishing/github/node_modules/semver/package.json +1 -1
- package/lib/publishing/github/node_modules/undici-types/agent.d.ts +12 -13
- package/lib/publishing/github/node_modules/undici-types/api.d.ts +26 -26
- package/lib/publishing/github/node_modules/undici-types/balanced-pool.d.ts +13 -12
- package/lib/publishing/github/node_modules/undici-types/cache-interceptor.d.ts +179 -0
- package/lib/publishing/github/node_modules/undici-types/client-stats.d.ts +15 -0
- package/lib/publishing/github/node_modules/undici-types/client.d.ts +63 -37
- package/lib/publishing/github/node_modules/undici-types/connector.d.ts +5 -2
- package/lib/publishing/github/node_modules/undici-types/cookies.d.ts +3 -1
- package/lib/publishing/github/node_modules/undici-types/diagnostics-channel.d.ts +18 -10
- package/lib/publishing/github/node_modules/undici-types/dispatcher.d.ts +136 -139
- package/lib/publishing/github/node_modules/undici-types/dispatcher1-wrapper.d.ts +7 -0
- package/lib/publishing/github/node_modules/undici-types/env-http-proxy-agent.d.ts +4 -3
- package/lib/publishing/github/node_modules/undici-types/errors.d.ts +92 -54
- package/lib/publishing/github/node_modules/undici-types/eventsource.d.ts +9 -4
- package/lib/publishing/github/node_modules/undici-types/fetch.d.ts +51 -25
- package/lib/publishing/github/node_modules/undici-types/formdata.d.ts +7 -7
- package/lib/publishing/github/node_modules/undici-types/global-dispatcher.d.ts +4 -4
- package/lib/publishing/github/node_modules/undici-types/global-origin.d.ts +5 -5
- package/lib/publishing/github/node_modules/undici-types/h2c-client.d.ts +73 -0
- package/lib/publishing/github/node_modules/undici-types/handlers.d.ts +10 -9
- package/lib/publishing/github/node_modules/undici-types/header.d.ts +162 -1
- package/lib/publishing/github/node_modules/undici-types/index.d.ts +69 -47
- package/lib/publishing/github/node_modules/undici-types/interceptors.d.ts +72 -9
- package/lib/publishing/github/node_modules/undici-types/mock-agent.d.ts +36 -18
- package/lib/publishing/github/node_modules/undici-types/mock-call-history.d.ts +111 -0
- package/lib/publishing/github/node_modules/undici-types/mock-client.d.ts +6 -4
- package/lib/publishing/github/node_modules/undici-types/mock-errors.d.ts +3 -3
- package/lib/publishing/github/node_modules/undici-types/mock-interceptor.d.ts +26 -21
- package/lib/publishing/github/node_modules/undici-types/mock-pool.d.ts +6 -4
- package/lib/publishing/github/node_modules/undici-types/package.json +1 -1
- package/lib/publishing/github/node_modules/undici-types/patch.d.ts +0 -4
- package/lib/publishing/github/node_modules/undici-types/pool-stats.d.ts +8 -8
- package/lib/publishing/github/node_modules/undici-types/pool.d.ts +14 -14
- package/lib/publishing/github/node_modules/undici-types/proxy-agent.d.ts +14 -6
- package/lib/publishing/github/node_modules/undici-types/readable.d.ts +19 -16
- package/lib/publishing/github/node_modules/undici-types/retry-agent.d.ts +1 -1
- package/lib/publishing/github/node_modules/undici-types/retry-handler.d.ts +19 -10
- package/lib/publishing/github/node_modules/undici-types/round-robin-pool.d.ts +39 -0
- package/lib/publishing/github/node_modules/undici-types/snapshot-agent.d.ts +113 -0
- package/lib/publishing/github/node_modules/undici-types/socks5-proxy-agent.d.ts +25 -0
- package/lib/publishing/github/node_modules/undici-types/util.d.ts +3 -3
- package/lib/publishing/github/node_modules/undici-types/utility.d.ts +7 -0
- package/lib/publishing/github/node_modules/undici-types/webidl.d.ts +148 -30
- package/lib/publishing/github/node_modules/undici-types/websocket.d.ts +48 -10
- package/lib/shellable.d.ts +7 -3
- package/lib/shellable.js +44 -30
- package/package.json +11 -11
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/compatibility/disposable.d.ts +0 -14
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/compatibility/index.d.ts +0 -9
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/compatibility/indexable.d.ts +0 -20
- package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/compatibility/iterators.d.ts +0 -20
- package/lib/publishing/github/node_modules/undici-types/file.d.ts +0 -39
- package/lib/publishing/github/node_modules/undici-types/filereader.d.ts +0 -54
package/lib/publishing/github/node_modules/@types/jsonwebtoken/node_modules/@types/node/test.d.ts
CHANGED
|
@@ -1,86 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The `node:test` module facilitates the creation of JavaScript tests.
|
|
3
|
-
* To access it:
|
|
4
|
-
*
|
|
5
|
-
* ```js
|
|
6
|
-
* import test from 'node:test';
|
|
7
|
-
* ```
|
|
8
|
-
*
|
|
9
|
-
* This module is only available under the `node:` scheme. The following will not
|
|
10
|
-
* work:
|
|
11
|
-
*
|
|
12
|
-
* ```js
|
|
13
|
-
* import test from 'node:test';
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* Tests created via the `test` module consist of a single function that is
|
|
17
|
-
* processed in one of three ways:
|
|
18
|
-
*
|
|
19
|
-
* 1. A synchronous function that is considered failing if it throws an exception,
|
|
20
|
-
* and is considered passing otherwise.
|
|
21
|
-
* 2. A function that returns a `Promise` that is considered failing if the `Promise` rejects, and is considered passing if the `Promise` fulfills.
|
|
22
|
-
* 3. A function that receives a callback function. If the callback receives any
|
|
23
|
-
* truthy value as its first argument, the test is considered failing. If a
|
|
24
|
-
* falsy value is passed as the first argument to the callback, the test is
|
|
25
|
-
* considered passing. If the test function receives a callback function and
|
|
26
|
-
* also returns a `Promise`, the test will fail.
|
|
27
|
-
*
|
|
28
|
-
* The following example illustrates how tests are written using the `test` module.
|
|
29
|
-
*
|
|
30
|
-
* ```js
|
|
31
|
-
* test('synchronous passing test', (t) => {
|
|
32
|
-
* // This test passes because it does not throw an exception.
|
|
33
|
-
* assert.strictEqual(1, 1);
|
|
34
|
-
* });
|
|
35
|
-
*
|
|
36
|
-
* test('synchronous failing test', (t) => {
|
|
37
|
-
* // This test fails because it throws an exception.
|
|
38
|
-
* assert.strictEqual(1, 2);
|
|
39
|
-
* });
|
|
40
|
-
*
|
|
41
|
-
* test('asynchronous passing test', async (t) => {
|
|
42
|
-
* // This test passes because the Promise returned by the async
|
|
43
|
-
* // function is settled and not rejected.
|
|
44
|
-
* assert.strictEqual(1, 1);
|
|
45
|
-
* });
|
|
46
|
-
*
|
|
47
|
-
* test('asynchronous failing test', async (t) => {
|
|
48
|
-
* // This test fails because the Promise returned by the async
|
|
49
|
-
* // function is rejected.
|
|
50
|
-
* assert.strictEqual(1, 2);
|
|
51
|
-
* });
|
|
52
|
-
*
|
|
53
|
-
* test('failing test using Promises', (t) => {
|
|
54
|
-
* // Promises can be used directly as well.
|
|
55
|
-
* return new Promise((resolve, reject) => {
|
|
56
|
-
* setImmediate(() => {
|
|
57
|
-
* reject(new Error('this will cause the test to fail'));
|
|
58
|
-
* });
|
|
59
|
-
* });
|
|
60
|
-
* });
|
|
61
|
-
*
|
|
62
|
-
* test('callback passing test', (t, done) => {
|
|
63
|
-
* // done() is the callback function. When the setImmediate() runs, it invokes
|
|
64
|
-
* // done() with no arguments.
|
|
65
|
-
* setImmediate(done);
|
|
66
|
-
* });
|
|
67
|
-
*
|
|
68
|
-
* test('callback failing test', (t, done) => {
|
|
69
|
-
* // When the setImmediate() runs, done() is invoked with an Error object and
|
|
70
|
-
* // the test fails.
|
|
71
|
-
* setImmediate(() => {
|
|
72
|
-
* done(new Error('callback failure'));
|
|
73
|
-
* });
|
|
74
|
-
* });
|
|
75
|
-
* ```
|
|
76
|
-
*
|
|
77
|
-
* If any tests fail, the process exit code is set to `1`.
|
|
78
|
-
* @since v18.0.0, v16.17.0
|
|
79
|
-
* @see [source](https://github.com/nodejs/node/blob/v22.x/lib/test.js)
|
|
80
|
-
*/
|
|
81
1
|
declare module "node:test" {
|
|
82
|
-
import { AssertMethodNames } from "node:assert";
|
|
83
|
-
import { Readable } from "node:stream";
|
|
2
|
+
import { AssertMethodNames, AssertPredicate } from "node:assert";
|
|
3
|
+
import { Readable, ReadableEventMap } from "node:stream";
|
|
4
|
+
import { TestEvent } from "node:test/reporters";
|
|
84
5
|
import { URL } from "node:url";
|
|
85
6
|
import TestFn = test.TestFn;
|
|
86
7
|
import TestOptions = test.TestOptions;
|
|
@@ -190,6 +111,16 @@ declare module "node:test" {
|
|
|
190
111
|
function only(name?: string, fn?: SuiteFn): Promise<void>;
|
|
191
112
|
function only(options?: TestOptions, fn?: SuiteFn): Promise<void>;
|
|
192
113
|
function only(fn?: SuiteFn): Promise<void>;
|
|
114
|
+
/**
|
|
115
|
+
* This flips the pass/fail reporting for a specific test or suite: a flagged test
|
|
116
|
+
* case must throw in order to pass, and a flagged test case that does not throw
|
|
117
|
+
* fails.
|
|
118
|
+
* @since v25.5.0
|
|
119
|
+
*/
|
|
120
|
+
function expectFailure(name?: string, options?: TestOptions, fn?: SuiteFn): Promise<void>;
|
|
121
|
+
function expectFailure(name?: string, fn?: SuiteFn): Promise<void>;
|
|
122
|
+
function expectFailure(options?: TestOptions, fn?: SuiteFn): Promise<void>;
|
|
123
|
+
function expectFailure(fn?: SuiteFn): Promise<void>;
|
|
193
124
|
}
|
|
194
125
|
/**
|
|
195
126
|
* Shorthand for skipping a test. This is the same as calling {@link test} with `options.skip` set to `true`.
|
|
@@ -215,6 +146,11 @@ declare module "node:test" {
|
|
|
215
146
|
function only(name?: string, fn?: TestFn): Promise<void>;
|
|
216
147
|
function only(options?: TestOptions, fn?: TestFn): Promise<void>;
|
|
217
148
|
function only(fn?: TestFn): Promise<void>;
|
|
149
|
+
// added in v25.5.0, undocumented
|
|
150
|
+
function expectFailure(name?: string, options?: TestOptions, fn?: TestFn): Promise<void>;
|
|
151
|
+
function expectFailure(name?: string, fn?: TestFn): Promise<void>;
|
|
152
|
+
function expectFailure(options?: TestOptions, fn?: TestFn): Promise<void>;
|
|
153
|
+
function expectFailure(fn?: TestFn): Promise<void>;
|
|
218
154
|
/**
|
|
219
155
|
* The type of a function passed to {@link test}. The first argument to this function is a {@link TestContext} object.
|
|
220
156
|
* If the test uses callbacks, the callback function is passed as the second argument.
|
|
@@ -236,14 +172,22 @@ declare module "node:test" {
|
|
|
236
172
|
}
|
|
237
173
|
interface RunOptions {
|
|
238
174
|
/**
|
|
239
|
-
* If a number is provided, then that many
|
|
175
|
+
* If a number is provided, then that many tests would run asynchronously (they are still managed by the single-threaded event loop).
|
|
240
176
|
* If `true`, it would run `os.availableParallelism() - 1` test files in parallel. If `false`, it would only run one test file at a time.
|
|
241
177
|
* @default false
|
|
242
178
|
*/
|
|
243
179
|
concurrency?: number | boolean | undefined;
|
|
244
180
|
/**
|
|
245
|
-
*
|
|
246
|
-
*
|
|
181
|
+
* Specifies the current working directory to be used by the test runner.
|
|
182
|
+
* Serves as the base path for resolving files according to the
|
|
183
|
+
* [test runner execution model](https://nodejs.org/docs/latest-v26.x/api/test.html#test-runner-execution-model).
|
|
184
|
+
* @since v23.0.0
|
|
185
|
+
* @default process.cwd()
|
|
186
|
+
*/
|
|
187
|
+
cwd?: string | undefined;
|
|
188
|
+
/**
|
|
189
|
+
* An array containing the list of files to run. If omitted, files are run according to the
|
|
190
|
+
* [test runner execution model](https://nodejs.org/docs/latest-v26.x/api/test.html#test-runner-execution-model).
|
|
247
191
|
*/
|
|
248
192
|
files?: readonly string[] | undefined;
|
|
249
193
|
/**
|
|
@@ -255,8 +199,8 @@ declare module "node:test" {
|
|
|
255
199
|
forceExit?: boolean | undefined;
|
|
256
200
|
/**
|
|
257
201
|
* An array containing the list of glob patterns to match test files.
|
|
258
|
-
* This option cannot be used together with `files`.
|
|
259
|
-
*
|
|
202
|
+
* This option cannot be used together with `files`. If omitted, files are run according to the
|
|
203
|
+
* [test runner execution model](https://nodejs.org/docs/latest-v26.x/api/test.html#test-runner-execution-model).
|
|
260
204
|
* @since v22.6.0
|
|
261
205
|
*/
|
|
262
206
|
globPatterns?: readonly string[] | undefined;
|
|
@@ -320,6 +264,15 @@ declare module "node:test" {
|
|
|
320
264
|
* @since v22.1.0
|
|
321
265
|
*/
|
|
322
266
|
testSkipPatterns?: string | RegExp | ReadonlyArray<string | RegExp> | undefined;
|
|
267
|
+
/**
|
|
268
|
+
* A tag name, or an array of tag names,
|
|
269
|
+
* used to filter tests by their declared tags. Tests must contain every
|
|
270
|
+
* listed tag to run. Equivalent to passing `--experimental-test-tag-filter`
|
|
271
|
+
* on the command line. See [Test tags](https://nodejs.org/docs/latest-v26.x/api/test.html#test-tags).
|
|
272
|
+
* @default undefined
|
|
273
|
+
* @since v26.2.0
|
|
274
|
+
*/
|
|
275
|
+
testTagFilters?: string | readonly string[] | undefined;
|
|
323
276
|
/**
|
|
324
277
|
* The number of milliseconds after which the test execution will fail.
|
|
325
278
|
* If unspecified, subtests inherit this value from their parent.
|
|
@@ -337,7 +290,28 @@ declare module "node:test" {
|
|
|
337
290
|
*/
|
|
338
291
|
shard?: TestShard | undefined;
|
|
339
292
|
/**
|
|
340
|
-
*
|
|
293
|
+
* Randomize execution order for test files and queued tests.
|
|
294
|
+
* This option is not supported with `watch: true`.
|
|
295
|
+
* @since v26.1.0
|
|
296
|
+
* @default false
|
|
297
|
+
*/
|
|
298
|
+
randomize?: boolean | undefined;
|
|
299
|
+
/**
|
|
300
|
+
* Seed used when randomizing execution order. If this
|
|
301
|
+
* option is set, runs can replay the same randomized order deterministically,
|
|
302
|
+
* and setting this option also enables randomization. The value must be an
|
|
303
|
+
* integer between `0` and `4294967295`.
|
|
304
|
+
*/
|
|
305
|
+
randomSeed?: number | undefined;
|
|
306
|
+
/**
|
|
307
|
+
* A file path where the test runner will
|
|
308
|
+
* store the state of the tests to allow rerunning only the failed tests on a next run.
|
|
309
|
+
* @since v24.7.0
|
|
310
|
+
* @default undefined
|
|
311
|
+
*/
|
|
312
|
+
rerunFailuresFilePath?: string | undefined;
|
|
313
|
+
/**
|
|
314
|
+
* enable [code coverage](https://nodejs.org/docs/latest-v26.x/api/test.html#collecting-code-coverage) collection.
|
|
341
315
|
* @since v22.10.0
|
|
342
316
|
* @default false
|
|
343
317
|
*/
|
|
@@ -383,6 +357,33 @@ declare module "node:test" {
|
|
|
383
357
|
* @default 0
|
|
384
358
|
*/
|
|
385
359
|
functionCoverage?: number | undefined;
|
|
360
|
+
/**
|
|
361
|
+
* Specify environment variables to be passed along to the test process.
|
|
362
|
+
* This option is not compatible with `isolation='none'`. These variables will override
|
|
363
|
+
* those from the main process, and are not merged with `process.env`.
|
|
364
|
+
* @since v25.6.0
|
|
365
|
+
* @default process.env
|
|
366
|
+
*/
|
|
367
|
+
env?: NodeJS.ProcessEnv | undefined;
|
|
368
|
+
}
|
|
369
|
+
interface TestsStreamEventMap extends ReadableEventMap {
|
|
370
|
+
"data": [data: TestEvent];
|
|
371
|
+
"test:coverage": [data: EventData.TestCoverage];
|
|
372
|
+
"test:complete": [data: EventData.TestComplete];
|
|
373
|
+
"test:dequeue": [data: EventData.TestDequeue];
|
|
374
|
+
"test:diagnostic": [data: EventData.TestDiagnostic];
|
|
375
|
+
"test:enqueue": [data: EventData.TestEnqueue];
|
|
376
|
+
"test:fail": [data: EventData.TestFail];
|
|
377
|
+
"test:interrupted": [data: EventData.TestInterrupted];
|
|
378
|
+
"test:log": [data: EventData.TestLog];
|
|
379
|
+
"test:pass": [data: EventData.TestPass];
|
|
380
|
+
"test:plan": [data: EventData.TestPlan];
|
|
381
|
+
"test:start": [data: EventData.TestStart];
|
|
382
|
+
"test:stderr": [data: EventData.TestStderr];
|
|
383
|
+
"test:stdout": [data: EventData.TestStdout];
|
|
384
|
+
"test:summary": [data: EventData.TestSummary];
|
|
385
|
+
"test:watch:drained": [];
|
|
386
|
+
"test:watch:restarted": [];
|
|
386
387
|
}
|
|
387
388
|
/**
|
|
388
389
|
* A successful call to `run()` will return a new `TestsStream` object, streaming a series of events representing the execution of the tests.
|
|
@@ -391,94 +392,63 @@ declare module "node:test" {
|
|
|
391
392
|
* @since v18.9.0, v16.19.0
|
|
392
393
|
*/
|
|
393
394
|
interface TestsStream extends Readable {
|
|
394
|
-
|
|
395
|
-
addListener
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
addListener(
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
once(event: "test:summary", listener: (data: EventData.TestSummary) => void): this;
|
|
448
|
-
once(event: "test:watch:drained", listener: () => void): this;
|
|
449
|
-
once(event: string, listener: (...args: any[]) => void): this;
|
|
450
|
-
prependListener(event: "test:coverage", listener: (data: EventData.TestCoverage) => void): this;
|
|
451
|
-
prependListener(event: "test:complete", listener: (data: EventData.TestComplete) => void): this;
|
|
452
|
-
prependListener(event: "test:dequeue", listener: (data: EventData.TestDequeue) => void): this;
|
|
453
|
-
prependListener(event: "test:diagnostic", listener: (data: EventData.TestDiagnostic) => void): this;
|
|
454
|
-
prependListener(event: "test:enqueue", listener: (data: EventData.TestEnqueue) => void): this;
|
|
455
|
-
prependListener(event: "test:fail", listener: (data: EventData.TestFail) => void): this;
|
|
456
|
-
prependListener(event: "test:pass", listener: (data: EventData.TestPass) => void): this;
|
|
457
|
-
prependListener(event: "test:plan", listener: (data: EventData.TestPlan) => void): this;
|
|
458
|
-
prependListener(event: "test:start", listener: (data: EventData.TestStart) => void): this;
|
|
459
|
-
prependListener(event: "test:stderr", listener: (data: EventData.TestStderr) => void): this;
|
|
460
|
-
prependListener(event: "test:stdout", listener: (data: EventData.TestStdout) => void): this;
|
|
461
|
-
prependListener(event: "test:summary", listener: (data: EventData.TestSummary) => void): this;
|
|
462
|
-
prependListener(event: "test:watch:drained", listener: () => void): this;
|
|
463
|
-
prependListener(event: string, listener: (...args: any[]) => void): this;
|
|
464
|
-
prependOnceListener(event: "test:coverage", listener: (data: EventData.TestCoverage) => void): this;
|
|
465
|
-
prependOnceListener(event: "test:complete", listener: (data: EventData.TestComplete) => void): this;
|
|
466
|
-
prependOnceListener(event: "test:dequeue", listener: (data: EventData.TestDequeue) => void): this;
|
|
467
|
-
prependOnceListener(event: "test:diagnostic", listener: (data: EventData.TestDiagnostic) => void): this;
|
|
468
|
-
prependOnceListener(event: "test:enqueue", listener: (data: EventData.TestEnqueue) => void): this;
|
|
469
|
-
prependOnceListener(event: "test:fail", listener: (data: EventData.TestFail) => void): this;
|
|
470
|
-
prependOnceListener(event: "test:pass", listener: (data: EventData.TestPass) => void): this;
|
|
471
|
-
prependOnceListener(event: "test:plan", listener: (data: EventData.TestPlan) => void): this;
|
|
472
|
-
prependOnceListener(event: "test:start", listener: (data: EventData.TestStart) => void): this;
|
|
473
|
-
prependOnceListener(event: "test:stderr", listener: (data: EventData.TestStderr) => void): this;
|
|
474
|
-
prependOnceListener(event: "test:stdout", listener: (data: EventData.TestStdout) => void): this;
|
|
475
|
-
prependOnceListener(event: "test:summary", listener: (data: EventData.TestSummary) => void): this;
|
|
476
|
-
prependOnceListener(event: "test:watch:drained", listener: () => void): this;
|
|
477
|
-
prependOnceListener(event: string, listener: (...args: any[]) => void): this;
|
|
395
|
+
// #region InternalEventEmitter
|
|
396
|
+
addListener<E extends keyof TestsStreamEventMap>(
|
|
397
|
+
eventName: E,
|
|
398
|
+
listener: (...args: TestsStreamEventMap[E]) => void,
|
|
399
|
+
): this;
|
|
400
|
+
addListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
|
401
|
+
emit<E extends keyof TestsStreamEventMap>(eventName: E, ...args: TestsStreamEventMap[E]): boolean;
|
|
402
|
+
emit(eventName: string | symbol, ...args: any[]): boolean;
|
|
403
|
+
listenerCount<E extends keyof TestsStreamEventMap>(
|
|
404
|
+
eventName: E,
|
|
405
|
+
listener?: (...args: TestsStreamEventMap[E]) => void,
|
|
406
|
+
): number;
|
|
407
|
+
listenerCount(eventName: string | symbol, listener?: (...args: any[]) => void): number;
|
|
408
|
+
listeners<E extends keyof TestsStreamEventMap>(eventName: E): ((...args: TestsStreamEventMap[E]) => void)[];
|
|
409
|
+
listeners(eventName: string | symbol): ((...args: any[]) => void)[];
|
|
410
|
+
off<E extends keyof TestsStreamEventMap>(
|
|
411
|
+
eventName: E,
|
|
412
|
+
listener: (...args: TestsStreamEventMap[E]) => void,
|
|
413
|
+
): this;
|
|
414
|
+
off(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
|
415
|
+
on<E extends keyof TestsStreamEventMap>(
|
|
416
|
+
eventName: E,
|
|
417
|
+
listener: (...args: TestsStreamEventMap[E]) => void,
|
|
418
|
+
): this;
|
|
419
|
+
on(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
|
420
|
+
once<E extends keyof TestsStreamEventMap>(
|
|
421
|
+
eventName: E,
|
|
422
|
+
listener: (...args: TestsStreamEventMap[E]) => void,
|
|
423
|
+
): this;
|
|
424
|
+
once(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
|
425
|
+
prependListener<E extends keyof TestsStreamEventMap>(
|
|
426
|
+
eventName: E,
|
|
427
|
+
listener: (...args: TestsStreamEventMap[E]) => void,
|
|
428
|
+
): this;
|
|
429
|
+
prependListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
|
430
|
+
prependOnceListener<E extends keyof TestsStreamEventMap>(
|
|
431
|
+
eventName: E,
|
|
432
|
+
listener: (...args: TestsStreamEventMap[E]) => void,
|
|
433
|
+
): this;
|
|
434
|
+
prependOnceListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
|
435
|
+
rawListeners<E extends keyof TestsStreamEventMap>(
|
|
436
|
+
eventName: E,
|
|
437
|
+
): ((...args: TestsStreamEventMap[E]) => void)[];
|
|
438
|
+
rawListeners(eventName: string | symbol): ((...args: any[]) => void)[];
|
|
439
|
+
// eslint-disable-next-line @definitelytyped/no-unnecessary-generics
|
|
440
|
+
removeAllListeners<E extends keyof TestsStreamEventMap>(eventName?: E): this;
|
|
441
|
+
removeAllListeners(eventName?: string | symbol): this;
|
|
442
|
+
removeListener<E extends keyof TestsStreamEventMap>(
|
|
443
|
+
eventName: E,
|
|
444
|
+
listener: (...args: TestsStreamEventMap[E]) => void,
|
|
445
|
+
): this;
|
|
446
|
+
removeListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
|
447
|
+
// #endregion
|
|
478
448
|
}
|
|
479
449
|
namespace EventData {
|
|
480
450
|
interface Error extends globalThis.Error {
|
|
481
|
-
cause:
|
|
451
|
+
cause: unknown;
|
|
482
452
|
}
|
|
483
453
|
interface LocationInfo {
|
|
484
454
|
/**
|
|
@@ -486,6 +456,13 @@ declare module "node:test" {
|
|
|
486
456
|
* `undefined` if the test was run through the REPL.
|
|
487
457
|
*/
|
|
488
458
|
column?: number;
|
|
459
|
+
/**
|
|
460
|
+
* The path of the test file that was
|
|
461
|
+
* executed as the entry point of the child process that emitted this event.
|
|
462
|
+
* Only present when tests run with process isolation. May differ from
|
|
463
|
+
* `file` when the test is defined in a module imported by the entry file.
|
|
464
|
+
*/
|
|
465
|
+
entryFile?: string;
|
|
489
466
|
/**
|
|
490
467
|
* The path of the test file, `undefined` if test was run through the REPL.
|
|
491
468
|
*/
|
|
@@ -698,7 +675,7 @@ declare module "node:test" {
|
|
|
698
675
|
/**
|
|
699
676
|
* The type of the test, used to denote whether this is a suite.
|
|
700
677
|
*/
|
|
701
|
-
type?: "suite";
|
|
678
|
+
type?: "suite" | "test";
|
|
702
679
|
};
|
|
703
680
|
/**
|
|
704
681
|
* The test name.
|
|
@@ -708,6 +685,24 @@ declare module "node:test" {
|
|
|
708
685
|
* The nesting level of the test.
|
|
709
686
|
*/
|
|
710
687
|
nesting: number;
|
|
688
|
+
/**
|
|
689
|
+
* The `testId` of the enclosing test, or
|
|
690
|
+
* `undefined` for top-level tests. Lets custom reporters track lineage
|
|
691
|
+
* when concurrent siblings at the same nesting level interleave.
|
|
692
|
+
*/
|
|
693
|
+
parentId: number | undefined;
|
|
694
|
+
/**
|
|
695
|
+
* The flattened lowercased tags declared on the test
|
|
696
|
+
* and its ancestor suites, in declaration order. Empty for untagged tests.
|
|
697
|
+
* See [Test tags](https://nodejs.org/docs/latest-v26.x/api/test.html#test-tags).
|
|
698
|
+
*/
|
|
699
|
+
tags: string[];
|
|
700
|
+
/**
|
|
701
|
+
* A numeric identifier for this test instance, unique
|
|
702
|
+
* within the test file's process. Consistent across all events for the same
|
|
703
|
+
* test instance, enabling reliable correlation in custom reporters.
|
|
704
|
+
*/
|
|
705
|
+
testId: number;
|
|
711
706
|
/**
|
|
712
707
|
* The ordinal number of the test.
|
|
713
708
|
*/
|
|
@@ -730,6 +725,24 @@ declare module "node:test" {
|
|
|
730
725
|
* The nesting level of the test.
|
|
731
726
|
*/
|
|
732
727
|
nesting: number;
|
|
728
|
+
/**
|
|
729
|
+
* The `testId` of the enclosing test, or
|
|
730
|
+
* `undefined` for top-level tests. Lets custom reporters track lineage
|
|
731
|
+
* when concurrent siblings at the same nesting level interleave.
|
|
732
|
+
*/
|
|
733
|
+
parentId: number | undefined;
|
|
734
|
+
/**
|
|
735
|
+
* The flattened lowercased tags declared on the test
|
|
736
|
+
* and its ancestor suites, in declaration order. Empty for untagged tests.
|
|
737
|
+
* See [Test tags](https://nodejs.org/docs/latest-v26.x/api/test.html#test-tags).
|
|
738
|
+
*/
|
|
739
|
+
tags: string[];
|
|
740
|
+
/**
|
|
741
|
+
* A numeric identifier for this test instance, unique
|
|
742
|
+
* within the test file's process. Consistent across all events for the same
|
|
743
|
+
* test instance, enabling reliable correlation in custom reporters.
|
|
744
|
+
*/
|
|
745
|
+
testId: number;
|
|
733
746
|
/**
|
|
734
747
|
* The test type. Either `'suite'` or `'test'`.
|
|
735
748
|
* @since v22.15.0
|
|
@@ -745,6 +758,24 @@ declare module "node:test" {
|
|
|
745
758
|
* The nesting level of the test.
|
|
746
759
|
*/
|
|
747
760
|
nesting: number;
|
|
761
|
+
/**
|
|
762
|
+
* The `testId` of the enclosing test, or
|
|
763
|
+
* `undefined` for top-level tests. Lets custom reporters track lineage
|
|
764
|
+
* when concurrent siblings at the same nesting level interleave.
|
|
765
|
+
*/
|
|
766
|
+
parentId: number | undefined;
|
|
767
|
+
/**
|
|
768
|
+
* The flattened lowercased tags declared on the test
|
|
769
|
+
* and its ancestor suites, in declaration order. Empty for untagged tests.
|
|
770
|
+
* See [Test tags](https://nodejs.org/docs/latest-v26.x/api/test.html#test-tags).
|
|
771
|
+
*/
|
|
772
|
+
tags: string[];
|
|
773
|
+
/**
|
|
774
|
+
* A numeric identifier for this test instance, unique
|
|
775
|
+
* within the test file's process. Consistent across all events for the same
|
|
776
|
+
* test instance, enabling reliable correlation in custom reporters.
|
|
777
|
+
*/
|
|
778
|
+
testId: number;
|
|
748
779
|
/**
|
|
749
780
|
* The test type. Either `'suite'` or `'test'`.
|
|
750
781
|
* @since v22.15.0
|
|
@@ -768,7 +799,13 @@ declare module "node:test" {
|
|
|
768
799
|
* The type of the test, used to denote whether this is a suite.
|
|
769
800
|
* @since v20.0.0, v19.9.0, v18.17.0
|
|
770
801
|
*/
|
|
771
|
-
type?: "suite";
|
|
802
|
+
type?: "suite" | "test";
|
|
803
|
+
/**
|
|
804
|
+
* The attempt number of the test run,
|
|
805
|
+
* present only when using the `--test-rerun-failures` flag.
|
|
806
|
+
* @since v24.7.0
|
|
807
|
+
*/
|
|
808
|
+
attempt?: number;
|
|
772
809
|
};
|
|
773
810
|
/**
|
|
774
811
|
* The test name.
|
|
@@ -778,6 +815,24 @@ declare module "node:test" {
|
|
|
778
815
|
* The nesting level of the test.
|
|
779
816
|
*/
|
|
780
817
|
nesting: number;
|
|
818
|
+
/**
|
|
819
|
+
* The `testId` of the enclosing test, or
|
|
820
|
+
* `undefined` for top-level tests. Lets custom reporters track lineage
|
|
821
|
+
* when concurrent siblings at the same nesting level interleave.
|
|
822
|
+
*/
|
|
823
|
+
parentId: number | undefined;
|
|
824
|
+
/**
|
|
825
|
+
* The flattened lowercased tags declared on the test
|
|
826
|
+
* and its ancestor suites, in declaration order. Empty for untagged tests.
|
|
827
|
+
* See [Test tags](https://nodejs.org/docs/latest-v26.x/api/test.html#test-tags).
|
|
828
|
+
*/
|
|
829
|
+
tags: string[];
|
|
830
|
+
/**
|
|
831
|
+
* A numeric identifier for this test instance, unique
|
|
832
|
+
* within the test file's process. Consistent across all events for the same
|
|
833
|
+
* test instance, enabling reliable correlation in custom reporters.
|
|
834
|
+
*/
|
|
835
|
+
testId: number;
|
|
781
836
|
/**
|
|
782
837
|
* The ordinal number of the test.
|
|
783
838
|
*/
|
|
@@ -791,6 +846,43 @@ declare module "node:test" {
|
|
|
791
846
|
*/
|
|
792
847
|
skip?: string | boolean;
|
|
793
848
|
}
|
|
849
|
+
interface TestInterrupted {
|
|
850
|
+
/**
|
|
851
|
+
* An array of objects containing information about the
|
|
852
|
+
* interrupted tests.
|
|
853
|
+
*/
|
|
854
|
+
tests: TestStart[];
|
|
855
|
+
}
|
|
856
|
+
interface TestLog extends LocationInfo {
|
|
857
|
+
/**
|
|
858
|
+
* The structured payload passed to `context.log`, or
|
|
859
|
+
* `undefined` if none was provided. The test runner does not interpret this
|
|
860
|
+
* value.
|
|
861
|
+
*/
|
|
862
|
+
data: unknown;
|
|
863
|
+
/**
|
|
864
|
+
* The log message.
|
|
865
|
+
*/
|
|
866
|
+
message: string;
|
|
867
|
+
/**
|
|
868
|
+
* The test name.
|
|
869
|
+
*/
|
|
870
|
+
name: string;
|
|
871
|
+
/**
|
|
872
|
+
* The nesting level of the test.
|
|
873
|
+
*/
|
|
874
|
+
nesting: number;
|
|
875
|
+
/**
|
|
876
|
+
* The `testId` of the enclosing test, or
|
|
877
|
+
* `undefined` for top-level tests.
|
|
878
|
+
*/
|
|
879
|
+
parentId: number | undefined;
|
|
880
|
+
/**
|
|
881
|
+
* A numeric identifier for the test instance that emitted
|
|
882
|
+
* the log message.
|
|
883
|
+
*/
|
|
884
|
+
testId: number;
|
|
885
|
+
}
|
|
794
886
|
interface TestPass extends LocationInfo {
|
|
795
887
|
/**
|
|
796
888
|
* Additional execution metadata.
|
|
@@ -804,7 +896,19 @@ declare module "node:test" {
|
|
|
804
896
|
* The type of the test, used to denote whether this is a suite.
|
|
805
897
|
* @since 20.0.0, 19.9.0, 18.17.0
|
|
806
898
|
*/
|
|
807
|
-
type?: "suite";
|
|
899
|
+
type?: "suite" | "test";
|
|
900
|
+
/**
|
|
901
|
+
* The attempt number of the test run,
|
|
902
|
+
* present only when using the `--test-rerun-failures` flag.
|
|
903
|
+
* @since v24.7.0
|
|
904
|
+
*/
|
|
905
|
+
attempt?: number;
|
|
906
|
+
/**
|
|
907
|
+
* The attempt number the test passed on,
|
|
908
|
+
* present only when using the `--test-rerun-failures` flag.
|
|
909
|
+
* @since v24.7.0
|
|
910
|
+
*/
|
|
911
|
+
passed_on_attempt?: number;
|
|
808
912
|
};
|
|
809
913
|
/**
|
|
810
914
|
* The test name.
|
|
@@ -814,6 +918,24 @@ declare module "node:test" {
|
|
|
814
918
|
* The nesting level of the test.
|
|
815
919
|
*/
|
|
816
920
|
nesting: number;
|
|
921
|
+
/**
|
|
922
|
+
* The `testId` of the enclosing test, or
|
|
923
|
+
* `undefined` for top-level tests. Lets custom reporters track lineage
|
|
924
|
+
* when concurrent siblings at the same nesting level interleave.
|
|
925
|
+
*/
|
|
926
|
+
parentId: number | undefined;
|
|
927
|
+
/**
|
|
928
|
+
* The flattened lowercased tags declared on the test
|
|
929
|
+
* and its ancestor suites, in declaration order. Empty for untagged tests.
|
|
930
|
+
* See [Test tags](https://nodejs.org/docs/latest-v26.x/api/test.html#test-tags).
|
|
931
|
+
*/
|
|
932
|
+
tags: string[];
|
|
933
|
+
/**
|
|
934
|
+
* A numeric identifier for this test instance, unique
|
|
935
|
+
* within the test file's process. Consistent across all events for the same
|
|
936
|
+
* test instance, enabling reliable correlation in custom reporters.
|
|
937
|
+
*/
|
|
938
|
+
testId: number;
|
|
817
939
|
/**
|
|
818
940
|
* The ordinal number of the test.
|
|
819
941
|
*/
|
|
@@ -846,6 +968,24 @@ declare module "node:test" {
|
|
|
846
968
|
* The nesting level of the test.
|
|
847
969
|
*/
|
|
848
970
|
nesting: number;
|
|
971
|
+
/**
|
|
972
|
+
* The `testId` of the enclosing test, or
|
|
973
|
+
* `undefined` for top-level tests. Lets custom reporters track lineage
|
|
974
|
+
* when concurrent siblings at the same nesting level interleave.
|
|
975
|
+
*/
|
|
976
|
+
parentId: number | undefined;
|
|
977
|
+
/**
|
|
978
|
+
* The flattened lowercased tags declared on the test
|
|
979
|
+
* and its ancestor suites, in declaration order. Empty for untagged tests.
|
|
980
|
+
* See [Test tags](https://nodejs.org/docs/latest-v26.x/api/test.html#test-tags).
|
|
981
|
+
*/
|
|
982
|
+
tags: string[];
|
|
983
|
+
/**
|
|
984
|
+
* A numeric identifier for this test instance, unique
|
|
985
|
+
* within the test file's process. Consistent across all events for the same
|
|
986
|
+
* test instance, enabling reliable correlation in custom reporters.
|
|
987
|
+
*/
|
|
988
|
+
testId: number;
|
|
849
989
|
}
|
|
850
990
|
interface TestStderr {
|
|
851
991
|
/**
|
|
@@ -919,6 +1059,39 @@ declare module "node:test" {
|
|
|
919
1059
|
success: boolean;
|
|
920
1060
|
}
|
|
921
1061
|
}
|
|
1062
|
+
/**
|
|
1063
|
+
* Returns the {@link TestContext} or {@link SuiteContext} object associated with the
|
|
1064
|
+
* currently executing test or suite, or `undefined` if called outside of a test or
|
|
1065
|
+
* suite. This function can be used to access context information from within the
|
|
1066
|
+
* test or suite function or any async operations within them.
|
|
1067
|
+
|
|
1068
|
+
* ```js
|
|
1069
|
+
* import { getTestContext } from 'node:test';
|
|
1070
|
+
*
|
|
1071
|
+
* test('example test', async () => {
|
|
1072
|
+
* const ctx = getTestContext();
|
|
1073
|
+
* console.log(`Running test: ${ctx.name}`);
|
|
1074
|
+
* });
|
|
1075
|
+
*
|
|
1076
|
+
* describe('example suite', () => {
|
|
1077
|
+
* const ctx = getTestContext();
|
|
1078
|
+
* console.log(`Running suite: ${ctx.name}`);
|
|
1079
|
+
* });
|
|
1080
|
+
* ```
|
|
1081
|
+
*
|
|
1082
|
+
* When called from a test, returns a `TestContext`.
|
|
1083
|
+
* When called from a suite, returns a `SuiteContext`.
|
|
1084
|
+
*
|
|
1085
|
+
* If called from outside a test or suite (e.g., at the top level of a module or in
|
|
1086
|
+
* a setTimeout callback after execution has completed), this function returns
|
|
1087
|
+
* `undefined`.
|
|
1088
|
+
*
|
|
1089
|
+
* When called from within a hook (before, beforeEach, after, afterEach), this
|
|
1090
|
+
* function returns the context of the test or suite that the hook is associated
|
|
1091
|
+
* with.
|
|
1092
|
+
* @since v26.1.0
|
|
1093
|
+
*/
|
|
1094
|
+
function getTestContext(): TestContext | SuiteContext | undefined;
|
|
922
1095
|
/**
|
|
923
1096
|
* An instance of `TestContext` is passed to each test function in order to
|
|
924
1097
|
* interact with the test runner. However, the `TestContext` constructor is not
|
|
@@ -995,6 +1168,25 @@ declare module "node:test" {
|
|
|
995
1168
|
* @param message Message to be reported.
|
|
996
1169
|
*/
|
|
997
1170
|
diagnostic(message: string): void;
|
|
1171
|
+
/**
|
|
1172
|
+
* This function is used to write a log message to the output. Unlike
|
|
1173
|
+
* `context.diagnostic`, the resulting `'test:log'` event is emitted
|
|
1174
|
+
* immediately, in the order that the tests execute, rather than being buffered
|
|
1175
|
+
* until the test reports its results. This function does not return a value.
|
|
1176
|
+
*
|
|
1177
|
+
* ```js
|
|
1178
|
+
* test('top level test', (t) => {
|
|
1179
|
+
* t.log('fetched user', { userId: 42 });
|
|
1180
|
+
* t.log('retrying flaky endpoint', { attempt: 3 });
|
|
1181
|
+
* });
|
|
1182
|
+
* ```
|
|
1183
|
+
* @since v26.6.0
|
|
1184
|
+
* @param message Message to be reported.
|
|
1185
|
+
* @param data Optional structured payload attached to the message. The test
|
|
1186
|
+
* runner passes it through untouched. When tests run with process isolation,
|
|
1187
|
+
* this value must be compatible with the [HTML structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm).
|
|
1188
|
+
*/
|
|
1189
|
+
log(message: string, data?: unknown): void;
|
|
998
1190
|
/**
|
|
999
1191
|
* The absolute path of the test file that created the current test. If a test file imports
|
|
1000
1192
|
* additional modules that generate tests, the imported tests will return the path of the root test file.
|
|
@@ -1011,6 +1203,58 @@ declare module "node:test" {
|
|
|
1011
1203
|
* @since v18.8.0, v16.18.0
|
|
1012
1204
|
*/
|
|
1013
1205
|
readonly name: string;
|
|
1206
|
+
/**
|
|
1207
|
+
* Indicated whether the test succeeded.
|
|
1208
|
+
* @since v21.7.0, v20.12.0
|
|
1209
|
+
*/
|
|
1210
|
+
readonly passed: boolean;
|
|
1211
|
+
/**
|
|
1212
|
+
* The failure reason for the test/case; wrapped and available via `context.error.cause`.
|
|
1213
|
+
* @since v21.7.0, v20.12.0
|
|
1214
|
+
*/
|
|
1215
|
+
readonly error: EventData.Error | null;
|
|
1216
|
+
/**
|
|
1217
|
+
* The attempt number of the test. This value is zero-based, so the first attempt is `0`,
|
|
1218
|
+
* the second attempt is `1`, and so on. This property is useful in conjunction with the
|
|
1219
|
+
* `--test-rerun-failures` option to determine which attempt the test is currently running.
|
|
1220
|
+
* @since v21.7.0, v20.12.0
|
|
1221
|
+
*/
|
|
1222
|
+
readonly attempt: number;
|
|
1223
|
+
/**
|
|
1224
|
+
* A frozen array of the test's flattened lowercased tags, in declaration
|
|
1225
|
+
* order, including any tags inherited from ancestor suites. Empty when the
|
|
1226
|
+
* test has no tags. See [Test tags](https://nodejs.org/docs/latest-v26.x/api/test.html#test-tags).
|
|
1227
|
+
* @since v26.2.0
|
|
1228
|
+
*/
|
|
1229
|
+
readonly tags: readonly string[];
|
|
1230
|
+
/**
|
|
1231
|
+
* The unique identifier of the worker running the current test file. This value is
|
|
1232
|
+
* derived from the `NODE_TEST_WORKER_ID` environment variable. When running tests
|
|
1233
|
+
* with `--test-isolation=process` (the default), each test file runs in a separate
|
|
1234
|
+
* child process and is assigned a worker ID from 1 to N, where N is the number of
|
|
1235
|
+
* concurrent workers. When running with `--test-isolation=none`, all tests run in
|
|
1236
|
+
* the same process and the worker ID is always 1. This value is `undefined` when
|
|
1237
|
+
* not running in a test context.
|
|
1238
|
+
*
|
|
1239
|
+
* This property is useful for splitting resources (like database connections or
|
|
1240
|
+
* server ports) across concurrent test files:
|
|
1241
|
+
*
|
|
1242
|
+
* ```js
|
|
1243
|
+
* import { test } from 'node:test';
|
|
1244
|
+
* import { process } from 'node:process';
|
|
1245
|
+
*
|
|
1246
|
+
* test('database operations', async (t) => {
|
|
1247
|
+
* // Worker ID is available via context
|
|
1248
|
+
* console.log(`Running in worker ${t.workerId}`);
|
|
1249
|
+
*
|
|
1250
|
+
* // Or via environment variable (available at import time)
|
|
1251
|
+
* const workerId = process.env.NODE_TEST_WORKER_ID;
|
|
1252
|
+
* // Use workerId to allocate separate resources per worker
|
|
1253
|
+
* });
|
|
1254
|
+
* ```
|
|
1255
|
+
* @since v25.8.0
|
|
1256
|
+
*/
|
|
1257
|
+
readonly workerId: number | undefined;
|
|
1014
1258
|
/**
|
|
1015
1259
|
* This function is used to set the number of assertions and subtests that are expected to run
|
|
1016
1260
|
* within the test. If the number of assertions and subtests that run does not match the
|
|
@@ -1179,7 +1423,7 @@ declare module "node:test" {
|
|
|
1179
1423
|
* highlighting.
|
|
1180
1424
|
* @since v22.14.0
|
|
1181
1425
|
* @param value A value to serialize to a string. If Node.js was started with
|
|
1182
|
-
* the [`--test-update-snapshots`](https://nodejs.org/docs/latest-
|
|
1426
|
+
* the [`--test-update-snapshots`](https://nodejs.org/docs/latest-v26.x/api/cli.html#--test-update-snapshots)
|
|
1183
1427
|
* flag, the serialized value is written to
|
|
1184
1428
|
* `path`. Otherwise, the serialized value is compared to the contents of the
|
|
1185
1429
|
* existing snapshot file.
|
|
@@ -1202,7 +1446,7 @@ declare module "node:test" {
|
|
|
1202
1446
|
* ```
|
|
1203
1447
|
* @since v22.3.0
|
|
1204
1448
|
* @param value A value to serialize to a string. If Node.js was started with
|
|
1205
|
-
* the [`--test-update-snapshots`](https://nodejs.org/docs/latest-
|
|
1449
|
+
* the [`--test-update-snapshots`](https://nodejs.org/docs/latest-v26.x/api/cli.html#--test-update-snapshots)
|
|
1206
1450
|
* flag, the serialized value is written to
|
|
1207
1451
|
* the snapshot file. Otherwise, the serialized value is compared to the
|
|
1208
1452
|
* corresponding value in the existing snapshot file.
|
|
@@ -1265,6 +1509,11 @@ declare module "node:test" {
|
|
|
1265
1509
|
* @since v22.6.0
|
|
1266
1510
|
*/
|
|
1267
1511
|
readonly filePath: string | undefined;
|
|
1512
|
+
/**
|
|
1513
|
+
* The name of the suite and each of its ancestors, separated by `>`.
|
|
1514
|
+
* @since v22.3.0, v20.16.0
|
|
1515
|
+
*/
|
|
1516
|
+
readonly fullName: string;
|
|
1268
1517
|
/**
|
|
1269
1518
|
* The name of the suite.
|
|
1270
1519
|
* @since v18.8.0, v16.18.0
|
|
@@ -1275,6 +1524,46 @@ declare module "node:test" {
|
|
|
1275
1524
|
* @since v18.7.0, v16.17.0
|
|
1276
1525
|
*/
|
|
1277
1526
|
readonly signal: AbortSignal;
|
|
1527
|
+
/**
|
|
1528
|
+
* Indicates whether the suite and all of its subtests have passed.
|
|
1529
|
+
* @since v26.1.0
|
|
1530
|
+
*/
|
|
1531
|
+
readonly passed: boolean;
|
|
1532
|
+
/**
|
|
1533
|
+
* The attempt number of the suite. This value is zero-based, so the first attempt is `0`,
|
|
1534
|
+
* the second attempt is `1`, and so on. This property is useful in conjunction with the
|
|
1535
|
+
* `--test-rerun-failures` option to determine the attempt number of the current run.
|
|
1536
|
+
* @since v26.1.0
|
|
1537
|
+
*/
|
|
1538
|
+
readonly attempt: number;
|
|
1539
|
+
/**
|
|
1540
|
+
* Output a diagnostic message. This is typically used for logging information
|
|
1541
|
+
* about the current suite or its tests.
|
|
1542
|
+
*
|
|
1543
|
+
* ```js
|
|
1544
|
+
* test.describe('my suite', (suite) => {
|
|
1545
|
+
* suite.diagnostic('Suite diagnostic message');
|
|
1546
|
+
* });
|
|
1547
|
+
* ```
|
|
1548
|
+
* @since v26.1.0
|
|
1549
|
+
* @param message A diagnostic message to output.
|
|
1550
|
+
*/
|
|
1551
|
+
diagnostic(message: string): void;
|
|
1552
|
+
/**
|
|
1553
|
+
* Write a log message to the output. The resulting `'test:log'` event is
|
|
1554
|
+
* emitted immediately, in the order that the tests execute.
|
|
1555
|
+
*
|
|
1556
|
+
* ```js
|
|
1557
|
+
* test.describe('my suite', (suite) => {
|
|
1558
|
+
* suite.log('Suite log message');
|
|
1559
|
+
* });
|
|
1560
|
+
* ```
|
|
1561
|
+
* @since v26.6.0
|
|
1562
|
+
* @param message Message to be reported.
|
|
1563
|
+
* @param data Optional structured payload attached to the message. The test
|
|
1564
|
+
* runner passes it through untouched.
|
|
1565
|
+
*/
|
|
1566
|
+
log(message: string, data?: unknown): void;
|
|
1278
1567
|
}
|
|
1279
1568
|
interface TestOptions {
|
|
1280
1569
|
/**
|
|
@@ -1286,6 +1575,17 @@ declare module "node:test" {
|
|
|
1286
1575
|
* @default false
|
|
1287
1576
|
*/
|
|
1288
1577
|
concurrency?: number | boolean | undefined;
|
|
1578
|
+
/**
|
|
1579
|
+
* If truthy, the test is expected to fail. If a non-empty string is provided, that string is displayed
|
|
1580
|
+
* in the test results as the reason why the test is expected to fail. If a
|
|
1581
|
+
* `RegExp`, `Function`, `Object`, or `Error` is provided directly (without wrapping in `{ match: … }`), the test passes
|
|
1582
|
+
* only if the thrown error matches, following the behavior of
|
|
1583
|
+
* `assert.throws`. To provide both a reason and validation, pass an object
|
|
1584
|
+
* with `label` (string) and `match` (RegExp, Function, Object, or Error).
|
|
1585
|
+
* @since v25.5.0
|
|
1586
|
+
* @default false
|
|
1587
|
+
*/
|
|
1588
|
+
expectFailure?: boolean | string | AssertPredicate | undefined;
|
|
1289
1589
|
/**
|
|
1290
1590
|
* If truthy, and the test context is configured to run `only` tests, then this test will be
|
|
1291
1591
|
* run. Otherwise, the test is skipped.
|
|
@@ -1303,6 +1603,15 @@ declare module "node:test" {
|
|
|
1303
1603
|
* @default false
|
|
1304
1604
|
*/
|
|
1305
1605
|
skip?: boolean | string | undefined;
|
|
1606
|
+
/**
|
|
1607
|
+
* An array of string labels associated with the test.
|
|
1608
|
+
* Used together with `--experimental-test-tag-filter` to filter which
|
|
1609
|
+
* tests run. Tags inherit from suites to nested tests by union. See
|
|
1610
|
+
* [Test tags](https://nodejs.org/docs/latest-v26.x/api/test.html#test-tags).
|
|
1611
|
+
* @default []
|
|
1612
|
+
* @since v26.2.0
|
|
1613
|
+
*/
|
|
1614
|
+
tags?: readonly string[] | undefined;
|
|
1306
1615
|
/**
|
|
1307
1616
|
* A number of milliseconds the test will fail after. If unspecified, subtests inherit this
|
|
1308
1617
|
* value from their parent.
|
|
@@ -1332,7 +1641,7 @@ declare module "node:test" {
|
|
|
1332
1641
|
* describe('tests', async () => {
|
|
1333
1642
|
* before(() => console.log('about to run some test'));
|
|
1334
1643
|
* it('is a subtest', () => {
|
|
1335
|
-
*
|
|
1644
|
+
* // Some relevant assertion here
|
|
1336
1645
|
* });
|
|
1337
1646
|
* });
|
|
1338
1647
|
* ```
|
|
@@ -1348,7 +1657,7 @@ declare module "node:test" {
|
|
|
1348
1657
|
* describe('tests', async () => {
|
|
1349
1658
|
* after(() => console.log('finished running tests'));
|
|
1350
1659
|
* it('is a subtest', () => {
|
|
1351
|
-
*
|
|
1660
|
+
* // Some relevant assertion here
|
|
1352
1661
|
* });
|
|
1353
1662
|
* });
|
|
1354
1663
|
* ```
|
|
@@ -1364,7 +1673,7 @@ declare module "node:test" {
|
|
|
1364
1673
|
* describe('tests', async () => {
|
|
1365
1674
|
* beforeEach(() => console.log('about to run a test'));
|
|
1366
1675
|
* it('is a subtest', () => {
|
|
1367
|
-
*
|
|
1676
|
+
* // Some relevant assertion here
|
|
1368
1677
|
* });
|
|
1369
1678
|
* });
|
|
1370
1679
|
* ```
|
|
@@ -1381,7 +1690,7 @@ declare module "node:test" {
|
|
|
1381
1690
|
* describe('tests', async () => {
|
|
1382
1691
|
* afterEach(() => console.log('finished running a test'));
|
|
1383
1692
|
* it('is a subtest', () => {
|
|
1384
|
-
*
|
|
1693
|
+
* // Some relevant assertion here
|
|
1385
1694
|
* });
|
|
1386
1695
|
* });
|
|
1387
1696
|
* ```
|
|
@@ -1449,19 +1758,40 @@ declare module "node:test" {
|
|
|
1449
1758
|
*/
|
|
1450
1759
|
cache?: boolean | undefined;
|
|
1451
1760
|
/**
|
|
1452
|
-
*
|
|
1453
|
-
*
|
|
1454
|
-
*
|
|
1455
|
-
*
|
|
1456
|
-
* If
|
|
1761
|
+
* Optional mocked exports. The `default` property, if
|
|
1762
|
+
* provided, is used as the mocked module's default export. All other own
|
|
1763
|
+
* enumerable properties are used as named exports.
|
|
1764
|
+
* **This option cannot be used with `defaultExport` or `namedExports`.**
|
|
1765
|
+
* * If the mock is a CommonJS or builtin module, `exports.default` is used as
|
|
1766
|
+
* the value of `module.exports`.
|
|
1767
|
+
* * If `exports.default` is not provided for a CommonJS or builtin mock,
|
|
1768
|
+
* `module.exports` defaults to an empty object.
|
|
1769
|
+
* * If named exports are provided with a non-object default export, the mock
|
|
1770
|
+
* throws an exception when used as a CommonJS or builtin module.
|
|
1771
|
+
*/
|
|
1772
|
+
exports?: object | undefined;
|
|
1773
|
+
/**
|
|
1774
|
+
* An optional value used as the mocked module's default
|
|
1775
|
+
* export. If this value is not provided, ESM mocks do not include a default
|
|
1776
|
+
* export. If the mock is a CommonJS or builtin module, this setting is used as
|
|
1777
|
+
* the value of `module.exports`. If this value is not provided, CJS and builtin
|
|
1778
|
+
* mocks use an empty object as the value of `module.exports`.
|
|
1779
|
+
* **This option cannot be used with `options.exports`.**
|
|
1780
|
+
* This option is deprecated and will be removed in a later version.
|
|
1781
|
+
* Prefer `options.exports.default`.
|
|
1782
|
+
* @deprecated
|
|
1457
1783
|
*/
|
|
1458
1784
|
defaultExport?: any;
|
|
1459
1785
|
/**
|
|
1460
|
-
* An object whose keys and values are used to
|
|
1461
|
-
*
|
|
1462
|
-
*
|
|
1463
|
-
*
|
|
1464
|
-
*
|
|
1786
|
+
* An optional object whose keys and values are used to
|
|
1787
|
+
* create the named exports of the mock module. If the mock is a CommonJS or
|
|
1788
|
+
* builtin module, these values are copied onto `module.exports`. Therefore, if a
|
|
1789
|
+
* mock is created with both named exports and a non-object default export, the
|
|
1790
|
+
* mock will throw an exception when used as a CJS or builtin module.
|
|
1791
|
+
* **This option cannot be used with `options.exports`.**
|
|
1792
|
+
* This option is deprecated and will be removed in a later version.
|
|
1793
|
+
* Prefer `options.exports`.
|
|
1794
|
+
* @deprecated
|
|
1465
1795
|
*/
|
|
1466
1796
|
namedExports?: object | undefined;
|
|
1467
1797
|
}
|
|
@@ -1630,10 +1960,48 @@ declare module "node:test" {
|
|
|
1630
1960
|
options?: MockFunctionOptions,
|
|
1631
1961
|
): Mock<((value: MockedObject[MethodName]) => void) | Implementation>;
|
|
1632
1962
|
/**
|
|
1633
|
-
* This function is used to mock the exports of ECMAScript modules, CommonJS modules,
|
|
1634
|
-
* Any references to the original module prior to mocking are not impacted.
|
|
1963
|
+
* This function is used to mock the exports of ECMAScript modules, CommonJS modules, JSON modules, and
|
|
1964
|
+
* Node.js builtin modules. Any references to the original module prior to mocking are not impacted. In
|
|
1965
|
+
* order to enable module mocking, Node.js must be started with the
|
|
1966
|
+
* [`--experimental-test-module-mocks`](https://nodejs.org/docs/latest-v26.x/api/cli.html#--experimental-test-module-mocks)
|
|
1967
|
+
* command-line flag.
|
|
1968
|
+
*
|
|
1969
|
+
* **Note**: [module customization hooks](https://nodejs.org/docs/latest-v26.x/api/module.html#customization-hooks) registered via the **synchronous** API effect resolution of
|
|
1970
|
+
* the `specifier` provided to `mock.module`. Customization hooks registered via the **asynchronous**
|
|
1971
|
+
* API are currently ignored (because the test runner's loader is synchronous, and node does not
|
|
1972
|
+
* support multi-chain / cross-chain loading).
|
|
1635
1973
|
*
|
|
1636
|
-
*
|
|
1974
|
+
* The following example demonstrates how a mock is created for a module.
|
|
1975
|
+
*
|
|
1976
|
+
* ```js
|
|
1977
|
+
* test('mocks a builtin module in both module systems', async (t) => {
|
|
1978
|
+
* // Create a mock of 'node:readline' with a named export named 'foo', which
|
|
1979
|
+
* // does not exist in the original 'node:readline' module.
|
|
1980
|
+
* const mock = t.mock.module('node:readline', {
|
|
1981
|
+
* exports: { foo: () => 42 },
|
|
1982
|
+
* });
|
|
1983
|
+
*
|
|
1984
|
+
* let esmImpl = await import('node:readline');
|
|
1985
|
+
* let cjsImpl = require('node:readline');
|
|
1986
|
+
*
|
|
1987
|
+
* // cursorTo() is an export of the original 'node:readline' module.
|
|
1988
|
+
* assert.strictEqual(esmImpl.cursorTo, undefined);
|
|
1989
|
+
* assert.strictEqual(cjsImpl.cursorTo, undefined);
|
|
1990
|
+
* assert.strictEqual(esmImpl.fn(), 42);
|
|
1991
|
+
* assert.strictEqual(cjsImpl.fn(), 42);
|
|
1992
|
+
*
|
|
1993
|
+
* mock.restore();
|
|
1994
|
+
*
|
|
1995
|
+
* // The mock is restored, so the original builtin module is returned.
|
|
1996
|
+
* esmImpl = await import('node:readline');
|
|
1997
|
+
* cjsImpl = require('node:readline');
|
|
1998
|
+
*
|
|
1999
|
+
* assert.strictEqual(typeof esmImpl.cursorTo, 'function');
|
|
2000
|
+
* assert.strictEqual(typeof cjsImpl.cursorTo, 'function');
|
|
2001
|
+
* assert.strictEqual(esmImpl.fn, undefined);
|
|
2002
|
+
* assert.strictEqual(cjsImpl.fn, undefined);
|
|
2003
|
+
* });
|
|
2004
|
+
* ```
|
|
1637
2005
|
* @since v22.3.0
|
|
1638
2006
|
* @experimental
|
|
1639
2007
|
* @param specifier A string identifying the module to mock.
|
|
@@ -1663,14 +2031,14 @@ declare module "node:test" {
|
|
|
1663
2031
|
* assert.strictEqual(obj.foo, 42);
|
|
1664
2032
|
* });
|
|
1665
2033
|
* ```
|
|
1666
|
-
* @since
|
|
2034
|
+
* @since v24.3.0
|
|
1667
2035
|
* @param object The object whose value is being mocked.
|
|
1668
2036
|
* @param propertyName The identifier of the property on `object` to mock.
|
|
1669
2037
|
* @param value An optional value used as the mock value
|
|
1670
2038
|
* for `object[propertyName]`. **Default:** The original property value.
|
|
1671
2039
|
* @returns A proxy to the mocked object. The mocked object contains a
|
|
1672
|
-
* special `mock` property, which is an instance of [`MockPropertyContext`]
|
|
1673
|
-
*
|
|
2040
|
+
* special `mock` property, which is an instance of [`MockPropertyContext`][], and
|
|
2041
|
+
* can be used for inspecting and changing the behavior of the mocked property.
|
|
1674
2042
|
*/
|
|
1675
2043
|
property<
|
|
1676
2044
|
MockedObject extends object,
|
|
@@ -1850,7 +2218,7 @@ declare module "node:test" {
|
|
|
1850
2218
|
restore(): void;
|
|
1851
2219
|
}
|
|
1852
2220
|
/**
|
|
1853
|
-
* @since
|
|
2221
|
+
* @since v24.3.0
|
|
1854
2222
|
*/
|
|
1855
2223
|
class MockPropertyContext<PropertyType = any> {
|
|
1856
2224
|
/**
|
|
@@ -1888,6 +2256,8 @@ declare module "node:test" {
|
|
|
1888
2256
|
* test('changes a mock behavior once', (t) => {
|
|
1889
2257
|
* const obj = { foo: 1 };
|
|
1890
2258
|
*
|
|
2259
|
+
* const prop = t.mock.property(obj, 'foo', 5);
|
|
2260
|
+
*
|
|
1891
2261
|
* assert.strictEqual(obj.foo, 5);
|
|
1892
2262
|
* prop.mock.mockImplementationOnce(25);
|
|
1893
2263
|
* assert.strictEqual(obj.foo, 25);
|
|
@@ -1926,7 +2296,6 @@ declare module "node:test" {
|
|
|
1926
2296
|
* The `MockTracker` provides a top-level `timers` export
|
|
1927
2297
|
* which is a `MockTimers` instance.
|
|
1928
2298
|
* @since v20.4.0
|
|
1929
|
-
* @experimental
|
|
1930
2299
|
*/
|
|
1931
2300
|
interface MockTimers {
|
|
1932
2301
|
/**
|
|
@@ -1979,24 +2348,28 @@ declare module "node:test" {
|
|
|
1979
2348
|
*/
|
|
1980
2349
|
enable(options?: MockTimersOptions): void;
|
|
1981
2350
|
/**
|
|
1982
|
-
*
|
|
1983
|
-
*
|
|
1984
|
-
*
|
|
2351
|
+
* Sets the current Unix timestamp that will be used as reference for any mocked
|
|
2352
|
+
* `Date` objects.
|
|
2353
|
+
*
|
|
1985
2354
|
* ```js
|
|
1986
2355
|
* import assert from 'node:assert';
|
|
1987
2356
|
* import { test } from 'node:test';
|
|
1988
|
-
*
|
|
1989
|
-
*
|
|
1990
|
-
*
|
|
1991
|
-
*
|
|
1992
|
-
* //
|
|
1993
|
-
*
|
|
1994
|
-
*
|
|
1995
|
-
*
|
|
2357
|
+
*
|
|
2358
|
+
* test('runAll functions following the given order', (context) => {
|
|
2359
|
+
* const now = Date.now();
|
|
2360
|
+
* const setTime = 1000;
|
|
2361
|
+
* // Date.now is not mocked
|
|
2362
|
+
* assert.deepStrictEqual(Date.now(), now);
|
|
2363
|
+
*
|
|
2364
|
+
* context.mock.timers.enable({ apis: ['Date'] });
|
|
2365
|
+
* context.mock.timers.setTime(setTime);
|
|
2366
|
+
* // Date.now is now 1000
|
|
2367
|
+
* assert.strictEqual(Date.now(), setTime);
|
|
1996
2368
|
* });
|
|
1997
2369
|
* ```
|
|
2370
|
+
* @since v21.2.0, v20.11.0
|
|
1998
2371
|
*/
|
|
1999
|
-
setTime(
|
|
2372
|
+
setTime(milliseconds: number): void;
|
|
2000
2373
|
/**
|
|
2001
2374
|
* This function restores the default behavior of all mocks that were previously
|
|
2002
2375
|
* created by this `MockTimers` instance and disassociates the mocks
|
|
@@ -2183,83 +2556,3 @@ declare module "node:test" {
|
|
|
2183
2556
|
}[keyof T];
|
|
2184
2557
|
export = test;
|
|
2185
2558
|
}
|
|
2186
|
-
|
|
2187
|
-
/**
|
|
2188
|
-
* The `node:test/reporters` module exposes the builtin-reporters for `node:test`.
|
|
2189
|
-
* To access it:
|
|
2190
|
-
*
|
|
2191
|
-
* ```js
|
|
2192
|
-
* import test from 'node:test/reporters';
|
|
2193
|
-
* ```
|
|
2194
|
-
*
|
|
2195
|
-
* This module is only available under the `node:` scheme. The following will not
|
|
2196
|
-
* work:
|
|
2197
|
-
*
|
|
2198
|
-
* ```js
|
|
2199
|
-
* import test from 'node:test/reporters';
|
|
2200
|
-
* ```
|
|
2201
|
-
* @since v19.9.0
|
|
2202
|
-
* @see [source](https://github.com/nodejs/node/blob/v22.x/lib/test/reporters.js)
|
|
2203
|
-
*/
|
|
2204
|
-
declare module "node:test/reporters" {
|
|
2205
|
-
import { Transform, TransformOptions } from "node:stream";
|
|
2206
|
-
import { EventData } from "node:test";
|
|
2207
|
-
|
|
2208
|
-
type TestEvent =
|
|
2209
|
-
| { type: "test:coverage"; data: EventData.TestCoverage }
|
|
2210
|
-
| { type: "test:complete"; data: EventData.TestComplete }
|
|
2211
|
-
| { type: "test:dequeue"; data: EventData.TestDequeue }
|
|
2212
|
-
| { type: "test:diagnostic"; data: EventData.TestDiagnostic }
|
|
2213
|
-
| { type: "test:enqueue"; data: EventData.TestEnqueue }
|
|
2214
|
-
| { type: "test:fail"; data: EventData.TestFail }
|
|
2215
|
-
| { type: "test:pass"; data: EventData.TestPass }
|
|
2216
|
-
| { type: "test:plan"; data: EventData.TestPlan }
|
|
2217
|
-
| { type: "test:start"; data: EventData.TestStart }
|
|
2218
|
-
| { type: "test:stderr"; data: EventData.TestStderr }
|
|
2219
|
-
| { type: "test:stdout"; data: EventData.TestStdout }
|
|
2220
|
-
| { type: "test:summary"; data: EventData.TestSummary }
|
|
2221
|
-
| { type: "test:watch:drained"; data: undefined };
|
|
2222
|
-
type TestEventGenerator = AsyncGenerator<TestEvent, void>;
|
|
2223
|
-
|
|
2224
|
-
interface ReporterConstructorWrapper<T extends new(...args: any[]) => Transform> {
|
|
2225
|
-
new(...args: ConstructorParameters<T>): InstanceType<T>;
|
|
2226
|
-
(...args: ConstructorParameters<T>): InstanceType<T>;
|
|
2227
|
-
}
|
|
2228
|
-
|
|
2229
|
-
/**
|
|
2230
|
-
* The `dot` reporter outputs the test results in a compact format,
|
|
2231
|
-
* where each passing test is represented by a `.`,
|
|
2232
|
-
* and each failing test is represented by a `X`.
|
|
2233
|
-
* @since v20.0.0
|
|
2234
|
-
*/
|
|
2235
|
-
function dot(source: TestEventGenerator): AsyncGenerator<"\n" | "." | "X", void>;
|
|
2236
|
-
/**
|
|
2237
|
-
* The `tap` reporter outputs the test results in the [TAP](https://testanything.org/) format.
|
|
2238
|
-
* @since v20.0.0
|
|
2239
|
-
*/
|
|
2240
|
-
function tap(source: TestEventGenerator): AsyncGenerator<string, void>;
|
|
2241
|
-
class SpecReporter extends Transform {
|
|
2242
|
-
constructor();
|
|
2243
|
-
}
|
|
2244
|
-
/**
|
|
2245
|
-
* The `spec` reporter outputs the test results in a human-readable format.
|
|
2246
|
-
* @since v20.0.0
|
|
2247
|
-
*/
|
|
2248
|
-
const spec: ReporterConstructorWrapper<typeof SpecReporter>;
|
|
2249
|
-
/**
|
|
2250
|
-
* The `junit` reporter outputs test results in a jUnit XML format.
|
|
2251
|
-
* @since v21.0.0
|
|
2252
|
-
*/
|
|
2253
|
-
function junit(source: TestEventGenerator): AsyncGenerator<string, void>;
|
|
2254
|
-
class LcovReporter extends Transform {
|
|
2255
|
-
constructor(opts?: Omit<TransformOptions, "writableObjectMode">);
|
|
2256
|
-
}
|
|
2257
|
-
/**
|
|
2258
|
-
* The `lcov` reporter outputs test coverage when used with the
|
|
2259
|
-
* [`--experimental-test-coverage`](https://nodejs.org/docs/latest-v22.x/api/cli.html#--experimental-test-coverage) flag.
|
|
2260
|
-
* @since v22.0.0
|
|
2261
|
-
*/
|
|
2262
|
-
const lcov: LcovReporter;
|
|
2263
|
-
|
|
2264
|
-
export { dot, junit, lcov, spec, tap, TestEvent };
|
|
2265
|
-
}
|