@types/node 20.11.1 → 20.11.5
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.
- node/README.md +1 -1
- node/crypto.d.ts +17 -1
- node/module.d.ts +2 -2
- node/package.json +2 -2
- node/stream/web.d.ts +17 -1
- node/test.d.ts +40 -9
- node/ts4.8/crypto.d.ts +17 -1
- node/ts4.8/module.d.ts +2 -2
- node/ts4.8/stream/web.d.ts +17 -1
- node/ts4.8/test.d.ts +40 -9
node/README.md
CHANGED
|
@@ -8,7 +8,7 @@ This package contains type definitions for node (https://nodejs.org/).
|
|
|
8
8
|
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node.
|
|
9
9
|
|
|
10
10
|
### Additional Details
|
|
11
|
-
* Last updated:
|
|
11
|
+
* Last updated: Wed, 17 Jan 2024 06:36:16 GMT
|
|
12
12
|
* Dependencies: [undici-types](https://npmjs.com/package/undici-types)
|
|
13
13
|
|
|
14
14
|
# Credits
|
node/crypto.d.ts
CHANGED
|
@@ -100,6 +100,8 @@ declare module "crypto" {
|
|
|
100
100
|
const OPENSSL_VERSION_NUMBER: number;
|
|
101
101
|
/** Applies multiple bug workarounds within OpenSSL. See https://www.openssl.org/docs/man1.0.2/ssl/SSL_CTX_set_options.html for detail. */
|
|
102
102
|
const SSL_OP_ALL: number;
|
|
103
|
+
/** Instructs OpenSSL to allow a non-[EC]DHE-based key exchange mode for TLS v1.3 */
|
|
104
|
+
const SSL_OP_ALLOW_NO_DHE_KEX: number;
|
|
103
105
|
/** Allows legacy insecure renegotiation between OpenSSL and unpatched clients or servers. See https://www.openssl.org/docs/man1.0.2/ssl/SSL_CTX_set_options.html. */
|
|
104
106
|
const SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION: number;
|
|
105
107
|
/** Attempts to use the server's preferences instead of the client's when selecting a cipher. See https://www.openssl.org/docs/man1.0.2/ssl/SSL_CTX_set_options.html. */
|
|
@@ -116,15 +118,29 @@ declare module "crypto" {
|
|
|
116
118
|
const SSL_OP_LEGACY_SERVER_CONNECT: number;
|
|
117
119
|
/** Instructs OpenSSL to disable support for SSL/TLS compression. */
|
|
118
120
|
const SSL_OP_NO_COMPRESSION: number;
|
|
121
|
+
/** Instructs OpenSSL to disable encrypt-then-MAC. */
|
|
122
|
+
const SSL_OP_NO_ENCRYPT_THEN_MAC: number;
|
|
119
123
|
const SSL_OP_NO_QUERY_MTU: number;
|
|
124
|
+
/** Instructs OpenSSL to disable renegotiation. */
|
|
125
|
+
const SSL_OP_NO_RENEGOTIATION: number;
|
|
120
126
|
/** Instructs OpenSSL to always start a new session when performing renegotiation. */
|
|
121
127
|
const SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION: number;
|
|
128
|
+
/** Instructs OpenSSL to turn off SSL v2 */
|
|
122
129
|
const SSL_OP_NO_SSLv2: number;
|
|
130
|
+
/** Instructs OpenSSL to turn off SSL v3 */
|
|
123
131
|
const SSL_OP_NO_SSLv3: number;
|
|
132
|
+
/** Instructs OpenSSL to disable use of RFC4507bis tickets. */
|
|
124
133
|
const SSL_OP_NO_TICKET: number;
|
|
134
|
+
/** Instructs OpenSSL to turn off TLS v1 */
|
|
125
135
|
const SSL_OP_NO_TLSv1: number;
|
|
136
|
+
/** Instructs OpenSSL to turn off TLS v1.1 */
|
|
126
137
|
const SSL_OP_NO_TLSv1_1: number;
|
|
138
|
+
/** Instructs OpenSSL to turn off TLS v1.2 */
|
|
127
139
|
const SSL_OP_NO_TLSv1_2: number;
|
|
140
|
+
/** Instructs OpenSSL to turn off TLS v1.3 */
|
|
141
|
+
const SSL_OP_NO_TLSv1_3: number;
|
|
142
|
+
/** Instructs OpenSSL server to prioritize ChaCha20-Poly1305 when the client does. This option has no effect if `SSL_OP_CIPHER_SERVER_PREFERENCE` is not enabled. */
|
|
143
|
+
const SSL_OP_PRIORITIZE_CHACHA: number;
|
|
128
144
|
/** Instructs OpenSSL to disable version rollback attack detection. */
|
|
129
145
|
const SSL_OP_TLS_ROLLBACK_BUG: number;
|
|
130
146
|
const ENGINE_METHOD_RSA: number;
|
|
@@ -363,7 +379,7 @@ declare module "crypto" {
|
|
|
363
379
|
* @since v13.1.0
|
|
364
380
|
* @param options `stream.transform` options
|
|
365
381
|
*/
|
|
366
|
-
copy(options?:
|
|
382
|
+
copy(options?: HashOptions): Hash;
|
|
367
383
|
/**
|
|
368
384
|
* Updates the hash content with the given `data`, the encoding of which
|
|
369
385
|
* is given in `inputEncoding`.
|
node/module.d.ts
CHANGED
|
@@ -280,13 +280,13 @@ declare module "module" {
|
|
|
280
280
|
* The directory name of the current module. This is the same as the `path.dirname()` of the `import.meta.filename`.
|
|
281
281
|
* **Caveat:** only present on `file:` modules.
|
|
282
282
|
*/
|
|
283
|
-
dirname
|
|
283
|
+
dirname: string;
|
|
284
284
|
/**
|
|
285
285
|
* The full absolute path and filename of the current module, with symlinks resolved.
|
|
286
286
|
* This is the same as the `url.fileURLToPath()` of the `import.meta.url`.
|
|
287
287
|
* **Caveat:** only local modules support this property. Modules not using the `file:` protocol will not provide it.
|
|
288
288
|
*/
|
|
289
|
-
filename
|
|
289
|
+
filename: string;
|
|
290
290
|
/**
|
|
291
291
|
* The absolute `file:` URL of the module.
|
|
292
292
|
*/
|
node/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@types/node",
|
|
3
|
-
"version": "20.11.
|
|
3
|
+
"version": "20.11.5",
|
|
4
4
|
"description": "TypeScript definitions for node",
|
|
5
5
|
"homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node",
|
|
6
6
|
"license": "MIT",
|
|
@@ -224,7 +224,7 @@
|
|
|
224
224
|
"dependencies": {
|
|
225
225
|
"undici-types": "~5.26.4"
|
|
226
226
|
},
|
|
227
|
-
"typesPublisherContentHash": "
|
|
227
|
+
"typesPublisherContentHash": "c9a4069d05b7343bb761470d8e688010c07b955f2242b07b710e067f1720f96a",
|
|
228
228
|
"typeScriptVersion": "4.6",
|
|
229
229
|
"nonNpm": true
|
|
230
230
|
}
|
node/stream/web.d.ts
CHANGED
|
@@ -342,7 +342,23 @@ declare module "stream/web" {
|
|
|
342
342
|
}
|
|
343
343
|
const TextDecoderStream: {
|
|
344
344
|
prototype: TextDecoderStream;
|
|
345
|
-
new(
|
|
345
|
+
new(encoding?: string, options?: TextDecoderOptions): TextDecoderStream;
|
|
346
|
+
};
|
|
347
|
+
interface CompressionStream<R = any, W = any> {
|
|
348
|
+
readonly readable: ReadableStream<R>;
|
|
349
|
+
readonly writable: WritableStream<W>;
|
|
350
|
+
}
|
|
351
|
+
const CompressionStream: {
|
|
352
|
+
prototype: CompressionStream;
|
|
353
|
+
new<R = any, W = any>(format: string): CompressionStream<R, W>;
|
|
354
|
+
};
|
|
355
|
+
interface DecompressionStream<R = any, W = any> {
|
|
356
|
+
readonly readable: ReadableStream<R>;
|
|
357
|
+
readonly writable: WritableStream<W>;
|
|
358
|
+
}
|
|
359
|
+
const DecompressionStream: {
|
|
360
|
+
prototype: DecompressionStream;
|
|
361
|
+
new<R = any, W = any>(format: string): DecompressionStream<R, W>;
|
|
346
362
|
};
|
|
347
363
|
}
|
|
348
364
|
declare module "node:stream/web" {
|
node/test.d.ts
CHANGED
|
@@ -1012,13 +1012,19 @@ declare module "node:test" {
|
|
|
1012
1012
|
*/
|
|
1013
1013
|
restore(): void;
|
|
1014
1014
|
}
|
|
1015
|
-
type Timer = "setInterval" | "
|
|
1015
|
+
type Timer = "setInterval" | "setTimeout" | "setImmediate" | "Date";
|
|
1016
|
+
|
|
1017
|
+
interface MockTimersOptions {
|
|
1018
|
+
apis: Timer[];
|
|
1019
|
+
now?: number | Date;
|
|
1020
|
+
}
|
|
1016
1021
|
/**
|
|
1017
1022
|
* Mocking timers is a technique commonly used in software testing to simulate and
|
|
1018
1023
|
* control the behavior of timers, such as `setInterval` and `setTimeout`,
|
|
1019
1024
|
* without actually waiting for the specified time intervals.
|
|
1020
1025
|
*
|
|
1021
|
-
* MockTimers
|
|
1026
|
+
* The MockTimers API also allows for mocking of the `Date` constructor and
|
|
1027
|
+
* `setImmediate`/`clearImmediate` functions.
|
|
1022
1028
|
*
|
|
1023
1029
|
* The `MockTracker` provides a top-level `timers` export
|
|
1024
1030
|
* which is a `MockTimers` instance.
|
|
@@ -1039,11 +1045,12 @@ declare module "node:test" {
|
|
|
1039
1045
|
*
|
|
1040
1046
|
* ```js
|
|
1041
1047
|
* import { mock } from 'node:test';
|
|
1042
|
-
* mock.timers.enable({ apis: ['setInterval'] });
|
|
1048
|
+
* mock.timers.enable({ apis: ['setInterval', 'Date'], now: 1234 });
|
|
1043
1049
|
* ```
|
|
1044
1050
|
*
|
|
1045
|
-
* The above example enables mocking for the `setInterval` timer and
|
|
1046
|
-
* implicitly mocks the `clearInterval` function. Only the `
|
|
1051
|
+
* The above example enables mocking for the `Date` constructor, `setInterval` timer and
|
|
1052
|
+
* implicitly mocks the `clearInterval` function. Only the `Date` constructor from `globalThis`,
|
|
1053
|
+
* `setInterval` and `clearInterval` functions from `node:timers`,`node:timers/promises`, and `globalThis` will be mocked.
|
|
1047
1054
|
*
|
|
1048
1055
|
* Example usage with initial time set
|
|
1049
1056
|
*
|
|
@@ -1061,12 +1068,36 @@ declare module "node:test" {
|
|
|
1061
1068
|
*
|
|
1062
1069
|
* Alternatively, if you call `mock.timers.enable()` without any parameters:
|
|
1063
1070
|
*
|
|
1064
|
-
* All timers (`'setInterval'`, `'clearInterval'`, `'setTimeout'`, and `'clearTimeout'`)
|
|
1065
|
-
* will be mocked.
|
|
1066
|
-
*
|
|
1071
|
+
* All timers (`'setInterval'`, `'clearInterval'`, `'Date'`, `'setImmediate'`, `'clearImmediate'`, `'setTimeout'`, and `'clearTimeout'`)
|
|
1072
|
+
* will be mocked.
|
|
1073
|
+
*
|
|
1074
|
+
* The `setInterval`, `clearInterval`, `setTimeout`, and `clearTimeout` functions from `node:timers`, `node:timers/promises`,
|
|
1075
|
+
* and `globalThis` will be mocked.
|
|
1076
|
+
* The `Date` constructor from `globalThis` will be mocked.
|
|
1077
|
+
*
|
|
1078
|
+
* If there is no initial epoch set, the initial date will be based on 0 in the Unix epoch. This is `January 1st, 1970, 00:00:00 UTC`. You can set an initial date by passing a now property to the `.enable()` method. This value will be used as the initial date for the mocked Date object. It can either be a positive integer, or another Date object.
|
|
1067
1079
|
* @since v20.4.0
|
|
1068
1080
|
*/
|
|
1069
|
-
enable(
|
|
1081
|
+
enable(options?: MockTimersOptions): void;
|
|
1082
|
+
/**
|
|
1083
|
+
* You can use the `.setTime()` method to manually move the mocked date to another time. This method only accepts a positive integer.
|
|
1084
|
+
* Note: This method will execute any mocked timers that are in the past from the new time.
|
|
1085
|
+
* In the below example we are setting a new time for the mocked date.
|
|
1086
|
+
* ```js
|
|
1087
|
+
* import assert from 'node:assert';
|
|
1088
|
+
* import { test } from 'node:test';
|
|
1089
|
+
* test('sets the time of a date object', (context) => {
|
|
1090
|
+
* // Optionally choose what to mock
|
|
1091
|
+
* context.mock.timers.enable({ apis: ['Date'], now: 100 });
|
|
1092
|
+
* assert.strictEqual(Date.now(), 100);
|
|
1093
|
+
* // Advance in time will also advance the date
|
|
1094
|
+
* context.mock.timers.setTime(1000);
|
|
1095
|
+
* context.mock.timers.tick(200);
|
|
1096
|
+
* assert.strictEqual(Date.now(), 1200);
|
|
1097
|
+
* });
|
|
1098
|
+
* ```
|
|
1099
|
+
*/
|
|
1100
|
+
setTime(time: number): void;
|
|
1070
1101
|
/**
|
|
1071
1102
|
* This function restores the default behavior of all mocks that were previously
|
|
1072
1103
|
* created by this `MockTimers` instance and disassociates the mocks
|
node/ts4.8/crypto.d.ts
CHANGED
|
@@ -100,6 +100,8 @@ declare module "crypto" {
|
|
|
100
100
|
const OPENSSL_VERSION_NUMBER: number;
|
|
101
101
|
/** Applies multiple bug workarounds within OpenSSL. See https://www.openssl.org/docs/man1.0.2/ssl/SSL_CTX_set_options.html for detail. */
|
|
102
102
|
const SSL_OP_ALL: number;
|
|
103
|
+
/** Instructs OpenSSL to allow a non-[EC]DHE-based key exchange mode for TLS v1.3 */
|
|
104
|
+
const SSL_OP_ALLOW_NO_DHE_KEX: number;
|
|
103
105
|
/** Allows legacy insecure renegotiation between OpenSSL and unpatched clients or servers. See https://www.openssl.org/docs/man1.0.2/ssl/SSL_CTX_set_options.html. */
|
|
104
106
|
const SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION: number;
|
|
105
107
|
/** Attempts to use the server's preferences instead of the client's when selecting a cipher. See https://www.openssl.org/docs/man1.0.2/ssl/SSL_CTX_set_options.html. */
|
|
@@ -116,15 +118,29 @@ declare module "crypto" {
|
|
|
116
118
|
const SSL_OP_LEGACY_SERVER_CONNECT: number;
|
|
117
119
|
/** Instructs OpenSSL to disable support for SSL/TLS compression. */
|
|
118
120
|
const SSL_OP_NO_COMPRESSION: number;
|
|
121
|
+
/** Instructs OpenSSL to disable encrypt-then-MAC. */
|
|
122
|
+
const SSL_OP_NO_ENCRYPT_THEN_MAC: number;
|
|
119
123
|
const SSL_OP_NO_QUERY_MTU: number;
|
|
124
|
+
/** Instructs OpenSSL to disable renegotiation. */
|
|
125
|
+
const SSL_OP_NO_RENEGOTIATION: number;
|
|
120
126
|
/** Instructs OpenSSL to always start a new session when performing renegotiation. */
|
|
121
127
|
const SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION: number;
|
|
128
|
+
/** Instructs OpenSSL to turn off SSL v2 */
|
|
122
129
|
const SSL_OP_NO_SSLv2: number;
|
|
130
|
+
/** Instructs OpenSSL to turn off SSL v3 */
|
|
123
131
|
const SSL_OP_NO_SSLv3: number;
|
|
132
|
+
/** Instructs OpenSSL to disable use of RFC4507bis tickets. */
|
|
124
133
|
const SSL_OP_NO_TICKET: number;
|
|
134
|
+
/** Instructs OpenSSL to turn off TLS v1 */
|
|
125
135
|
const SSL_OP_NO_TLSv1: number;
|
|
136
|
+
/** Instructs OpenSSL to turn off TLS v1.1 */
|
|
126
137
|
const SSL_OP_NO_TLSv1_1: number;
|
|
138
|
+
/** Instructs OpenSSL to turn off TLS v1.2 */
|
|
127
139
|
const SSL_OP_NO_TLSv1_2: number;
|
|
140
|
+
/** Instructs OpenSSL to turn off TLS v1.3 */
|
|
141
|
+
const SSL_OP_NO_TLSv1_3: number;
|
|
142
|
+
/** Instructs OpenSSL server to prioritize ChaCha20-Poly1305 when the client does. This option has no effect if `SSL_OP_CIPHER_SERVER_PREFERENCE` is not enabled. */
|
|
143
|
+
const SSL_OP_PRIORITIZE_CHACHA: number;
|
|
128
144
|
/** Instructs OpenSSL to disable version rollback attack detection. */
|
|
129
145
|
const SSL_OP_TLS_ROLLBACK_BUG: number;
|
|
130
146
|
const ENGINE_METHOD_RSA: number;
|
|
@@ -363,7 +379,7 @@ declare module "crypto" {
|
|
|
363
379
|
* @since v13.1.0
|
|
364
380
|
* @param options `stream.transform` options
|
|
365
381
|
*/
|
|
366
|
-
copy(options?:
|
|
382
|
+
copy(options?: HashOptions): Hash;
|
|
367
383
|
/**
|
|
368
384
|
* Updates the hash content with the given `data`, the encoding of which
|
|
369
385
|
* is given in `inputEncoding`.
|
node/ts4.8/module.d.ts
CHANGED
|
@@ -280,13 +280,13 @@ declare module "module" {
|
|
|
280
280
|
* The directory name of the current module. This is the same as the `path.dirname()` of the `import.meta.filename`.
|
|
281
281
|
* **Caveat:** only present on `file:` modules.
|
|
282
282
|
*/
|
|
283
|
-
dirname
|
|
283
|
+
dirname: string;
|
|
284
284
|
/**
|
|
285
285
|
* The full absolute path and filename of the current module, with symlinks resolved.
|
|
286
286
|
* This is the same as the `url.fileURLToPath()` of the `import.meta.url`.
|
|
287
287
|
* **Caveat:** only local modules support this property. Modules not using the `file:` protocol will not provide it.
|
|
288
288
|
*/
|
|
289
|
-
filename
|
|
289
|
+
filename: string;
|
|
290
290
|
/**
|
|
291
291
|
* The absolute `file:` URL of the module.
|
|
292
292
|
*/
|
node/ts4.8/stream/web.d.ts
CHANGED
|
@@ -342,7 +342,23 @@ declare module "stream/web" {
|
|
|
342
342
|
}
|
|
343
343
|
const TextDecoderStream: {
|
|
344
344
|
prototype: TextDecoderStream;
|
|
345
|
-
new(
|
|
345
|
+
new(encoding?: string, options?: TextDecoderOptions): TextDecoderStream;
|
|
346
|
+
};
|
|
347
|
+
interface CompressionStream<R = any, W = any> {
|
|
348
|
+
readonly readable: ReadableStream<R>;
|
|
349
|
+
readonly writable: WritableStream<W>;
|
|
350
|
+
}
|
|
351
|
+
const CompressionStream: {
|
|
352
|
+
prototype: CompressionStream;
|
|
353
|
+
new<R = any, W = any>(format: string): CompressionStream<R, W>;
|
|
354
|
+
};
|
|
355
|
+
interface DecompressionStream<R = any, W = any> {
|
|
356
|
+
readonly readable: ReadableStream<R>;
|
|
357
|
+
readonly writable: WritableStream<W>;
|
|
358
|
+
}
|
|
359
|
+
const DecompressionStream: {
|
|
360
|
+
prototype: DecompressionStream;
|
|
361
|
+
new<R = any, W = any>(format: string): DecompressionStream<R, W>;
|
|
346
362
|
};
|
|
347
363
|
}
|
|
348
364
|
declare module "node:stream/web" {
|
node/ts4.8/test.d.ts
CHANGED
|
@@ -1012,13 +1012,19 @@ declare module "node:test" {
|
|
|
1012
1012
|
*/
|
|
1013
1013
|
restore(): void;
|
|
1014
1014
|
}
|
|
1015
|
-
type Timer = "setInterval" | "
|
|
1015
|
+
type Timer = "setInterval" | "setTimeout" | "setImmediate" | "Date";
|
|
1016
|
+
|
|
1017
|
+
interface MockTimersOptions {
|
|
1018
|
+
apis: Timer[];
|
|
1019
|
+
now?: number | Date;
|
|
1020
|
+
}
|
|
1016
1021
|
/**
|
|
1017
1022
|
* Mocking timers is a technique commonly used in software testing to simulate and
|
|
1018
1023
|
* control the behavior of timers, such as `setInterval` and `setTimeout`,
|
|
1019
1024
|
* without actually waiting for the specified time intervals.
|
|
1020
1025
|
*
|
|
1021
|
-
* MockTimers
|
|
1026
|
+
* The MockTimers API also allows for mocking of the `Date` constructor and
|
|
1027
|
+
* `setImmediate`/`clearImmediate` functions.
|
|
1022
1028
|
*
|
|
1023
1029
|
* The `MockTracker` provides a top-level `timers` export
|
|
1024
1030
|
* which is a `MockTimers` instance.
|
|
@@ -1039,11 +1045,12 @@ declare module "node:test" {
|
|
|
1039
1045
|
*
|
|
1040
1046
|
* ```js
|
|
1041
1047
|
* import { mock } from 'node:test';
|
|
1042
|
-
* mock.timers.enable({ apis: ['setInterval'] });
|
|
1048
|
+
* mock.timers.enable({ apis: ['setInterval', 'Date'], now: 1234 });
|
|
1043
1049
|
* ```
|
|
1044
1050
|
*
|
|
1045
|
-
* The above example enables mocking for the `setInterval` timer and
|
|
1046
|
-
* implicitly mocks the `clearInterval` function. Only the `
|
|
1051
|
+
* The above example enables mocking for the `Date` constructor, `setInterval` timer and
|
|
1052
|
+
* implicitly mocks the `clearInterval` function. Only the `Date` constructor from `globalThis`,
|
|
1053
|
+
* `setInterval` and `clearInterval` functions from `node:timers`,`node:timers/promises`, and `globalThis` will be mocked.
|
|
1047
1054
|
*
|
|
1048
1055
|
* Example usage with initial time set
|
|
1049
1056
|
*
|
|
@@ -1061,12 +1068,36 @@ declare module "node:test" {
|
|
|
1061
1068
|
*
|
|
1062
1069
|
* Alternatively, if you call `mock.timers.enable()` without any parameters:
|
|
1063
1070
|
*
|
|
1064
|
-
* All timers (`'setInterval'`, `'clearInterval'`, `'setTimeout'`, and `'clearTimeout'`)
|
|
1065
|
-
* will be mocked.
|
|
1066
|
-
*
|
|
1071
|
+
* All timers (`'setInterval'`, `'clearInterval'`, `'Date'`, `'setImmediate'`, `'clearImmediate'`, `'setTimeout'`, and `'clearTimeout'`)
|
|
1072
|
+
* will be mocked.
|
|
1073
|
+
*
|
|
1074
|
+
* The `setInterval`, `clearInterval`, `setTimeout`, and `clearTimeout` functions from `node:timers`, `node:timers/promises`,
|
|
1075
|
+
* and `globalThis` will be mocked.
|
|
1076
|
+
* The `Date` constructor from `globalThis` will be mocked.
|
|
1077
|
+
*
|
|
1078
|
+
* If there is no initial epoch set, the initial date will be based on 0 in the Unix epoch. This is `January 1st, 1970, 00:00:00 UTC`. You can set an initial date by passing a now property to the `.enable()` method. This value will be used as the initial date for the mocked Date object. It can either be a positive integer, or another Date object.
|
|
1067
1079
|
* @since v20.4.0
|
|
1068
1080
|
*/
|
|
1069
|
-
enable(
|
|
1081
|
+
enable(options?: MockTimersOptions): void;
|
|
1082
|
+
/**
|
|
1083
|
+
* You can use the `.setTime()` method to manually move the mocked date to another time. This method only accepts a positive integer.
|
|
1084
|
+
* Note: This method will execute any mocked timers that are in the past from the new time.
|
|
1085
|
+
* In the below example we are setting a new time for the mocked date.
|
|
1086
|
+
* ```js
|
|
1087
|
+
* import assert from 'node:assert';
|
|
1088
|
+
* import { test } from 'node:test';
|
|
1089
|
+
* test('sets the time of a date object', (context) => {
|
|
1090
|
+
* // Optionally choose what to mock
|
|
1091
|
+
* context.mock.timers.enable({ apis: ['Date'], now: 100 });
|
|
1092
|
+
* assert.strictEqual(Date.now(), 100);
|
|
1093
|
+
* // Advance in time will also advance the date
|
|
1094
|
+
* context.mock.timers.setTime(1000);
|
|
1095
|
+
* context.mock.timers.tick(200);
|
|
1096
|
+
* assert.strictEqual(Date.now(), 1200);
|
|
1097
|
+
* });
|
|
1098
|
+
* ```
|
|
1099
|
+
*/
|
|
1100
|
+
setTime(time: number): void;
|
|
1070
1101
|
/**
|
|
1071
1102
|
* This function restores the default behavior of all mocks that were previously
|
|
1072
1103
|
* created by this `MockTimers` instance and disassociates the mocks
|