nodejs/doc/api/test.md

3788 lines
119 KiB
Markdown
Raw Permalink Normal View History

# Test runner
2022-04-19, Version 18.0.0 (Current) Notable Changes: Deprecations and Removals: - (SEMVER-MAJOR) fs: runtime deprecate string coercion in `fs.write`, `fs.writeFileSync` (Livia Medeiros) (https://github.com/nodejs/node/pull/42607) - (SEMVER-MAJOR) dns: remove `dns.lookup` and `dnsPromises.lookup` options type coercion (Antoine du Hamel) (https://github.com/nodejs/node/pull/41431) - (SEMVER-MAJOR) process: runtime deprecate multipleResolves (Benjamin Gruenbaum) (https://github.com/nodejs/node/pull/41896) - (SEMVER-MAJOR) stream: remove thenable support (Robert Nagy) (https://github.com/nodejs/node/pull/40773) - (SEMVER-MAJOR) tls: move tls.parseCertString to end-of-life (Tobias Nießen) (https://github.com/nodejs/node/pull/41479) fetch (experimental): An experimental fetch API is available on the global scope by default. The implementation is based upon https://undici.nodejs.org/#/, an HTTP/1.1 client written for Node.js by contributors to the project. Through this addition, the following globals are made available: `fetch` , `FormData`, `Headers`, `Request`, `Response`. Disable this API with the `--no-experimental-fetch` command-line flag. Contributed by Michaël Zasso in https://github.com/nodejs/node/pull/41811. HTTP Timeouts: `server.headersTimeout`, which limits the amount of time the parser will wait to receive the complete HTTP headers, is now set to `60000` (60 seconds) by default. `server.requestTimeout`, which sets the timeout value in milliseconds for receiving the entire request from the client, is now set to `300000` (5 minutes) by default. If these timeouts expire, the server responds with status 408 without forwarding the request to the request listener and then closes the connection. Both timeouts must be set to a non-zero value to protect against potential Denial-of-Service attacks in case the server is deployed without a reverse proxy in front. Contributed by Paolo Insogna in https://github.com/nodejs/node/pull/41263. Test Runner module (experimental): The `node:test` module facilitates the creation of JavaScript tests that report results in TAP format. This module is only available under the `node:` scheme. Contributed by Colin Ihrig in https://github.com/nodejs/node/pull/42325. Toolchain and Compiler Upgrades: - Prebuilt binaries for Linux are now built on Red Hat Enterprise Linux (RHEL) 8 and are compatible with Linux distributions based on glibc 2.28 or later, for example, Debian 10, RHEL 8, Ubuntu 20.04. - Prebuilt binaries for macOS now require macOS 10.15 or later. - For AIX the minimum supported architecture has been raised from Power 7 to Power 8. Prebuilt binaries for 32-bit Windows will initially not be available due to issues building the V8 dependency in Node.js. We hope to restore 32-bit Windows binaries for Node.js 18 with a future V8 update. Node.js does not support running on operating systems that are no longer supported by their vendor. For operating systems where their vendor has planned to end support earlier than April 2025, such as Windows 8.1 (January 2023) and Windows Server 2012 R2 (October 2023), support for Node.js 18 will end at the earlier date. Full details about the supported toolchains and compilers are documented in the Node.js `BUILDING.md` file. Contributed by Richard Lau in https://github.com/nodejs/node/pull/42292, https://github.com/nodejs/node/pull/42604 and https://github.com/nodejs/node/pull/42659 , and Michaël Zasso in https://github.com/nodejs/node/pull/42105 and https://github.com/nodejs/node/pull/42666. V8 10.1: The V8 engine is updated to version 10.1, which is part of Chromium 101. Compared to the version included in Node.js 17.9.0, the following new features are included: - The `findLast` and `findLastIndex` array methods. - Improvements to the `Intl.Locale` API. - The `Intl.supportedValuesOf` function. - Improved performance of class fields and private class methods (the initialization of them is now as fast as ordinary property stores). The data format returned by the serialization API (`v8.serialize(value)`) has changed, and cannot be deserialized by earlier versions of Node.js. On the other hand, it is still possible to deserialize the previous format, as the API is backwards-compatible. Contributed by Michaël Zasso in https://github.com/nodejs/node/pull/42657. Web Streams API (experimental): Node.js now exposes the experimental implementation of the Web Streams API on the global scope. This means the following APIs are now globally available: - `ReadableStream`, `ReadableStreamDefaultReader`, `ReadableStreamBYOBReader`, `ReadableStreamBYOBRequest`, `ReadableByteStreamController`, `ReadableStreamDefaultController`, `TransformStream`, `TransformStreamDefaultController`, `WritableStream`, `WritableStreamDefaultWriter`, `WritableStreamDefaultController`, `ByteLengthQueuingStrategy`, `CountQueuingStrategy`, `TextEncoderStream`, `TextDecoderStream`, `CompressionStream`, `DecompressionStream`. Contributed James Snell in https://github.com/nodejs/node/pull/39062, and Antoine du Hamel in https://github.com/nodejs/node/pull/42225. Other Notable Changes: - (SEMVER-MAJOR) buffer: expose Blob as a global (James M Snell) (https://github.com/nodejs/node/pull/41270) - (SEMVER-MAJOR) child\_process: improve argument validation (Rich Trott) (https://github.com/nodejs/node/pull/41305) - doc: add RafaelGSS to collaborators (RafaelGSS) (https://github.com/nodejs/node/pull/42718) - (SEMVER-MAJOR) http: make TCP noDelay enabled by default (Paolo Insogna) (https://github.com/nodejs/node/pull/42163) - (SEMVER-MAJOR) net: make `server.address()` return an integer for `family` (Antoine du Hamel) (https://github.com/nodejs/node/pull/41431) - (SEMVER-MAJOR) worker: expose BroadcastChannel as a global (James M Snell) (https://github.com/nodejs/node/pull/41271) - (SEMVER-MAJOR) worker: graduate BroadcastChannel to supported (James M Snell) (https://github.com/nodejs/node/pull/41271) Semver-Major Commits: - (SEMVER-MAJOR) assert,util: compare RegExp.lastIndex while using deep equal checks (Ruben Bridgewater) (https://github.com/nodejs/node/pull/41020) - (SEMVER-MAJOR) buffer: refactor `byteLength` to remove outdated optimizations (Rongjian Zhang) (https://github.com/nodejs/node/pull/38545) - (SEMVER-MAJOR) buffer: expose Blob as a global (James M Snell) (https://github.com/nodejs/node/pull/41270) - (SEMVER-MAJOR) buffer: graduate Blob from experimental (James M Snell) (https://github.com/nodejs/node/pull/41270) - (SEMVER-MAJOR) build: make x86 Windows support temporarily experimental (Michaël Zasso) (https://github.com/nodejs/node/pull/42666) - (SEMVER-MAJOR) build: bump macOS deployment target to 10.15 (Richard Lau) (https://github.com/nodejs/node/pull/42292) - (SEMVER-MAJOR) build: downgrade Windows 8.1 and server 2012 R2 to experimental (Michaël Zasso) (https://github.com/nodejs/node/pull/42105) - (SEMVER-MAJOR) child\_process: improve argument validation (Rich Trott) (https://github.com/nodejs/node/pull/41305) - (SEMVER-MAJOR) cluster: make `kill` to be just `process.kill` (Bar Admoni) (https://github.com/nodejs/node/pull/34312) - (SEMVER-MAJOR) crypto: cleanup validation (Mohammed Keyvanzadeh) (https://github.com/nodejs/node/pull/39841) - (SEMVER-MAJOR) crypto: prettify othername in PrintGeneralName (Tobias Nießen) (https://github.com/nodejs/node/pull/42123) - (SEMVER-MAJOR) crypto: fix X509Certificate toLegacyObject (Tobias Nießen) (https://github.com/nodejs/node/pull/42124) - (SEMVER-MAJOR) crypto: use RFC2253 format in PrintGeneralName (Tobias Nießen) (https://github.com/nodejs/node/pull/42002) - (SEMVER-MAJOR) crypto: change default check(Host|Email) behavior (Tobias Nießen) (https://github.com/nodejs/node/pull/41600) - (SEMVER-MAJOR) deps: V8: cherry-pick semver-major commits from 10.2 (Michaël Zasso) (https://github.com/nodejs/node/pull/42657) - (SEMVER-MAJOR) deps: update V8 to 10.1.124.6 (Michaël Zasso) (https://github.com/nodejs/node/pull/42657) - (SEMVER-MAJOR) deps: update V8 to 9.8.177.9 (Michaël Zasso) (https://github.com/nodejs/node/pull/41610) - (SEMVER-MAJOR) deps: update V8 to 9.7.106.18 (Michaël Zasso) (https://github.com/nodejs/node/pull/40907) - (SEMVER-MAJOR) dns: remove `dns.lookup` and `dnsPromises.lookup` options type coercion (Antoine du Hamel) (https://github.com/nodejs/node/pull/41431) - (SEMVER-MAJOR) doc: update minimum glibc requirements for Linux (Richard Lau) (https://github.com/nodejs/node/pull/42659) - (SEMVER-MAJOR) doc: update AIX minimum supported arch (Richard Lau) (https://github.com/nodejs/node/pull/42604) - (SEMVER-MAJOR) fs: runtime deprecate string coercion in `fs.write`, `fs.writeFileSync` (Livia Medeiros) (https://github.com/nodejs/node/pull/42607) - (SEMVER-MAJOR) http: refactor headersTimeout and requestTimeout logic (Paolo Insogna) (https://github.com/nodejs/node/pull/41263) - (SEMVER-MAJOR) http: make TCP noDelay enabled by default (Paolo Insogna) (https://github.com/nodejs/node/pull/42163) - (SEMVER-MAJOR) lib: enable fetch by default (Michaël Zasso) (https://github.com/nodejs/node/pull/41811) - (SEMVER-MAJOR) lib: replace validator and error (Mohammed Keyvanzadeh) (https://github.com/nodejs/node/pull/41678) - (SEMVER-MAJOR) module,repl: support 'node:'-only core modules (Colin Ihrig) (https://github.com/nodejs/node/pull/42325) - (SEMVER-MAJOR) net: make `server.address()` return an integer for `family` (Antoine du Hamel) (https://github.com/nodejs/node/pull/41431) - (SEMVER-MAJOR) process: disallow some uses of Object.defineProperty() on process.env (Himself65) (https://github.com/nodejs/node/pull/28006) - (SEMVER-MAJOR) process: runtime deprecate multipleResolves (Benjamin Gruenbaum) (https://github.com/nodejs/node/pull/41896) - (SEMVER-MAJOR) readline: fix question still called after closed (Xuguang Mei) (https://github.com/nodejs/node/pull/42464) - (SEMVER-MAJOR) stream: remove thenable support (Robert Nagy) (https://github.com/nodejs/node/pull/40773) - (SEMVER-MAJOR) stream: expose web streams globals, remove runtime experimental warning (Antoine du Hamel) (https://github.com/nodejs/node/pull/42225) - (SEMVER-MAJOR) stream: need to cleanup event listeners if last stream is readable (Xuguang Mei) (https://github.com/nodejs/node/pull/41954) - (SEMVER-MAJOR) stream: revert revert `map` spec compliance (Benjamin Gruenbaum) (https://github.com/nodejs/node/pull/41933) - (SEMVER-MAJOR) stream: throw invalid arg type from End Of Stream (Jithil P Ponnan) (https://github.com/nodejs/node/pull/41766) - (SEMVER-MAJOR) stream: don't emit finish after destroy (Robert Nagy) (https://github.com/nodejs/node/pull/40852) - (SEMVER-MAJOR) stream: add errored and closed props (Robert Nagy) (https://github.com/nodejs/node/pull/40696) - (SEMVER-MAJOR) test: add initial test module (Colin Ihrig) (https://github.com/nodejs/node/pull/42325) - (SEMVER-MAJOR) timers: refactor internal classes to ES2015 syntax (Rabbit) (https://github.com/nodejs/node/pull/37408) - (SEMVER-MAJOR) tls: represent registeredID numerically always (Tobias Nießen) (https://github.com/nodejs/node/pull/41561) - (SEMVER-MAJOR) tls: move tls.parseCertString to end-of-life (Tobias Nießen) (https://github.com/nodejs/node/pull/41479) - (SEMVER-MAJOR) url: throw on NULL in IPv6 hostname (Rich Trott) (https://github.com/nodejs/node/pull/42313) - (SEMVER-MAJOR) v8: make v8.writeHeapSnapshot() error codes consistent (Darshan Sen) (https://github.com/nodejs/node/pull/42577) - (SEMVER-MAJOR) v8: make writeHeapSnapshot throw if fopen fails (Antonio Román) (https://github.com/nodejs/node/pull/41373) - (SEMVER-MAJOR) worker: expose BroadcastChannel as a global (James M Snell) (https://github.com/nodejs/node/pull/41271) - (SEMVER-MAJOR) worker: graduate BroadcastChannel to supported (James M Snell) (https://github.com/nodejs/node/pull/41271) PR-URL: https://github.com/nodejs/node/pull/42262
2022-03-08 01:39:47 +00:00
<!--introduced_in=v18.0.0-->
<!-- YAML
added:
- v18.0.0
- v16.17.0
changes:
2023-04-18, Version 20.0.0 (Current) Notable Changes: crypto: * (SEMVER-MAJOR) use WebIDL converters in WebCryptoAPI (Filip Skokan) https://github.com/nodejs/node/pull/46067 deps: * update ada to 2.0.0 (Node.js GitHub Bot) https://github.com/nodejs/node/pull/47339 esm: * move hook execution to separate thread (Jacob Smith) https://github.com/nodejs/node/pull/44710 sea: * use JSON configuration and blob content for SEA (Joyee Cheung) https://github.com/nodejs/node/pull/47125 src,process: * (SEMVER-MINOR) add permission model (Rafael Gonzaga) https://github.com/nodejs/node/pull/44004 url: * drop ICU requirement for parsing hostnames (Yagiz Nizipli) https://github.com/nodejs/node/pull/47339 * use ada::url_aggregator for parsing urls (Yagiz Nizipli) https://github.com/nodejs/node/pull/47339 * (SEMVER-MAJOR) runtime-deprecate url.parse() with invalid ports (Rich Trott) https://github.com/nodejs/node/pull/45526 Semver-Major Commits: * [9fafb0a090] - (SEMVER-MAJOR) async_hooks: deprecate the AsyncResource.bind asyncResource property (James M Snell) https://github.com/nodejs/node/pull/46432 * [1948d37595] - (SEMVER-MAJOR) buffer: check INSPECT_MAX_BYTES with validateNumber (Umuoy) https://github.com/nodejs/node/pull/46599 * [7bc0e6a4e7] - (SEMVER-MAJOR) buffer: graduate File from experimental and expose as global (Khafra) https://github.com/nodejs/node/pull/47153 * [671ffd7825] - (SEMVER-MAJOR) buffer: use min/max of `validateNumber` (Deokjin Kim) https://github.com/nodejs/node/pull/45796 * [ab1614d280] - (SEMVER-MAJOR) build: reset embedder string to "-node.0" (Michaël Zasso) https://github.com/nodejs/node/pull/47251 * [c1bcdbcf79] - (SEMVER-MAJOR) build: warn for gcc versions earlier than 10.1 (Richard Lau) https://github.com/nodejs/node/pull/46806 * [649f68fc1e] - (SEMVER-MAJOR) build: reset embedder string to "-node.0" (Yagiz Nizipli) https://github.com/nodejs/node/pull/45579 * [9374700d7a] - (SEMVER-MAJOR) crypto: remove DEFAULT_ENCODING (Tobias Nießen) https://github.com/nodejs/node/pull/47182 * [1640aeb680] - (SEMVER-MAJOR) crypto: remove obsolete SSL_OP_* constants (Tobias Nießen) https://github.com/nodejs/node/pull/47073 * [c2e4b1fa9a] - (SEMVER-MAJOR) crypto: remove ALPN_ENABLED (Tobias Nießen) https://github.com/nodejs/node/pull/47028 * [3ef38c4bd7] - (SEMVER-MAJOR) crypto: use WebIDL converters in WebCryptoAPI (Filip Skokan) https://github.com/nodejs/node/pull/46067 * [08af023b1f] - (SEMVER-MAJOR) crypto: runtime deprecate replaced rsa-pss keygen parameters (Filip Skokan) https://github.com/nodejs/node/pull/45653 * [7eb0ac3cb6] - (SEMVER-MAJOR) deps: patch V8 to support compilation on win-arm64 (Michaël Zasso) https://github.com/nodejs/node/pull/47251 * [a7c129f286] - (SEMVER-MAJOR) deps: silence irrelevant V8 warning (Michaël Zasso) https://github.com/nodejs/node/pull/47251 * [6f5655a18e] - (SEMVER-MAJOR) deps: always define V8_EXPORT_PRIVATE as no-op (Michaël Zasso) https://github.com/nodejs/node/pull/47251 * [f226350fcb] - (SEMVER-MAJOR) deps: update V8 to 11.3.244.4 (Michaël Zasso) https://github.com/nodejs/node/pull/47251 * [d6dae7420e] - (SEMVER-MAJOR) deps: V8: cherry-pick f1c888e7093e (Michaël Zasso) https://github.com/nodejs/node/pull/45579 * [56c436533e] - (SEMVER-MAJOR) deps: fix V8 build on Windows with MSVC (Michaël Zasso) https://github.com/nodejs/node/pull/45579 * [51ab98c71b] - (SEMVER-MAJOR) deps: silence irrelevant V8 warning (Michaël Zasso) https://github.com/nodejs/node/pull/45579 * [9f84d3eea8] - (SEMVER-MAJOR) deps: V8: fix v8-cppgc.h for MSVC (Jiawen Geng) https://github.com/nodejs/node/pull/45579 * [f2318cd4b5] - (SEMVER-MAJOR) deps: fix V8 build issue with inline methods (Jiawen Geng) https://github.com/nodejs/node/pull/45579 * [16e03e7968] - (SEMVER-MAJOR) deps: update V8 to 10.9.194.4 (Yagiz Nizipli) https://github.com/nodejs/node/pull/45579 * [6473f5e7f7] - (SEMVER-MAJOR) doc: update toolchains used for Node.js 20 releases (Richard Lau) https://github.com/nodejs/node/pull/47352 * [cc18fd9608] - (SEMVER-MAJOR) events: refactor to use `validateNumber` (Deokjin Kim) https://github.com/nodejs/node/pull/45770 * [ff92b40ffc] - (SEMVER-MAJOR) http: close the connection after sending a body without declared length (Tim Perry) https://github.com/nodejs/node/pull/46333 * [2a29df6464] - (SEMVER-MAJOR) http: keep HTTP/1.1 conns alive even if the Connection header is removed (Tim Perry) https://github.com/nodejs/node/pull/46331 * [391dc74a10] - (SEMVER-MAJOR) http: throw error if options of http.Server is array (Deokjin Kim) https://github.com/nodejs/node/pull/46283 * [ed3604cd64] - (SEMVER-MAJOR) http: server check Host header, to meet RFC 7230 5.4 requirement (wwwzbwcom) https://github.com/nodejs/node/pull/45597 * [88d71dc301] - (SEMVER-MAJOR) lib: refactor to use min/max of `validateNumber` (Deokjin Kim) https://github.com/nodejs/node/pull/45772 * [e4d641f02a] - (SEMVER-MAJOR) lib: refactor to use validators in http2 (Debadree Chatterjee) https://github.com/nodejs/node/pull/46174 * [0f3e531096] - (SEMVER-MAJOR) lib: performance improvement on readline async iterator (Thiago Oliveira Santos) https://github.com/nodejs/node/pull/41276 * [5b5898ac86] - (SEMVER-MAJOR) lib,src: update exit codes as per todos (Debadree Chatterjee) https://github.com/nodejs/node/pull/45841 * [55321bafd1] - (SEMVER-MAJOR) net: enable autoSelectFamily by default (Paolo Insogna) https://github.com/nodejs/node/pull/46790 * [2d0d99733b] - (SEMVER-MAJOR) process: remove `process.exit()`, `process.exitCode` coercion to integer (Daeyeon Jeong) https://github.com/nodejs/node/pull/43716 * [dc06df31b6] - (SEMVER-MAJOR) readline: refactor to use `validateNumber` (Deokjin Kim) https://github.com/nodejs/node/pull/45801 * [295b2f3ff4] - (SEMVER-MAJOR) src: update NODE_MODULE_VERSION to 115 (Michaël Zasso) https://github.com/nodejs/node/pull/47251 * [3803b028dd] - (SEMVER-MAJOR) src: share common code paths for SEA and embedder script (Anna Henningsen) https://github.com/nodejs/node/pull/46825 * [e8bddac3e9] - (SEMVER-MAJOR) src: apply ABI-breaking API simplifications (Anna Henningsen) https://github.com/nodejs/node/pull/46705 * [f84de0ad4c] - (SEMVER-MAJOR) src: use uint32_t for process initialization flags enum (Anna Henningsen) https://github.com/nodejs/node/pull/46427 * [a6242772ec] - (SEMVER-MAJOR) src: fix ArrayBuffer::Detach deprecation (Michaël Zasso) https://github.com/nodejs/node/pull/45579 * [dd5c39a808] - (SEMVER-MAJOR) src: update NODE_MODULE_VERSION to 112 (Yagiz Nizipli) https://github.com/nodejs/node/pull/45579 * [63eca7fec0] - (SEMVER-MAJOR) stream: validate readable defaultEncoding (Marco Ippolito) https://github.com/nodejs/node/pull/46430 * [9e7093f416] - (SEMVER-MAJOR) stream: validate writable defaultEncoding (Marco Ippolito) https://github.com/nodejs/node/pull/46322 * [fb91ee4f26] - (SEMVER-MAJOR) test: make trace-gc-flag tests less strict (Yagiz Nizipli) https://github.com/nodejs/node/pull/45579 * [eca618071e] - (SEMVER-MAJOR) test: adapt test-v8-stats for V8 update (Michaël Zasso) https://github.com/nodejs/node/pull/45579 * [c03354d3e0] - (SEMVER-MAJOR) test: test case for multiple res.writeHead and res.getHeader (Marco Ippolito) https://github.com/nodejs/node/pull/45508 * [c733cc0c7f] - (SEMVER-MAJOR) test_runner: mark module as stable (Colin Ihrig) https://github.com/nodejs/node/pull/46983 * [7ce223273d] - (SEMVER-MAJOR) tools: update V8 gypfiles for 11.1 (Michaël Zasso) https://github.com/nodejs/node/pull/47251 * [ca4bd3023e] - (SEMVER-MAJOR) tools: update V8 gypfiles for 11.0 (Michaël Zasso) https://github.com/nodejs/node/pull/47251 * [58b06a269a] - (SEMVER-MAJOR) tools: update V8 gypfiles (Michaël Zasso) https://github.com/nodejs/node/pull/45579 * [027841c964] - (SEMVER-MAJOR) url: use private properties for brand check (Yagiz Nizipli) https://github.com/nodejs/node/pull/46904 * [3bed5f11e0] - (SEMVER-MAJOR) url: runtime-deprecate url.parse() with invalid ports (Rich Trott) https://github.com/nodejs/node/pull/45526 * [7c76fddf25] - (SEMVER-MAJOR) util,doc: mark parseArgs() as stable (Colin Ihrig) https://github.com/nodejs/node/pull/46718 * [4b52727976] - (SEMVER-MAJOR) wasi: make version non-optional (Michael Dawson) https://github.com/nodejs/node/pull/47391 Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com> PR-URL: https://github.com/nodejs/node/pull/47441 Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com>
2023-04-03 11:30:30 +01:00
- version: v20.0.0
pr-url: https://github.com/nodejs/node/pull/46983
description: The test runner is now stable.
-->
> Stability: 2 - Stable
<!-- source_link=lib/test.js -->
The `node:test` module facilitates the creation of JavaScript tests.
To access it:
```mjs
import test from 'node:test';
```
```cjs
const test = require('node:test');
```
This module is only available under the `node:` scheme.
Tests created via the `test` module consist of a single function that is
processed in one of three ways:
1. A synchronous function that is considered failing if it throws an exception,
and is considered passing otherwise.
2. A function that returns a `Promise` that is considered failing if the
`Promise` rejects, and is considered passing if the `Promise` fulfills.
3. A function that receives a callback function. If the callback receives any
truthy value as its first argument, the test is considered failing. If a
falsy value is passed as the first argument to the callback, the test is
considered passing. If the test function receives a callback function and
also returns a `Promise`, the test will fail.
The following example illustrates how tests are written using the
`test` module.
```js
test('synchronous passing test', (t) => {
// This test passes because it does not throw an exception.
assert.strictEqual(1, 1);
});
test('synchronous failing test', (t) => {
// This test fails because it throws an exception.
assert.strictEqual(1, 2);
});
test('asynchronous passing test', async (t) => {
// This test passes because the Promise returned by the async
// function is settled and not rejected.
assert.strictEqual(1, 1);
});
test('asynchronous failing test', async (t) => {
// This test fails because the Promise returned by the async
// function is rejected.
assert.strictEqual(1, 2);
});
test('failing test using Promises', (t) => {
// Promises can be used directly as well.
return new Promise((resolve, reject) => {
setImmediate(() => {
reject(new Error('this will cause the test to fail'));
});
});
});
test('callback passing test', (t, done) => {
// done() is the callback function. When the setImmediate() runs, it invokes
// done() with no arguments.
setImmediate(done);
});
test('callback failing test', (t, done) => {
// When the setImmediate() runs, done() is invoked with an Error object and
// the test fails.
setImmediate(() => {
done(new Error('callback failure'));
});
});
```
If any tests fail, the process exit code is set to `1`.
## Subtests
The test context's `test()` method allows subtests to be created.
It allows you to structure your tests in a hierarchical manner,
where you can create nested tests within a larger test.
This method behaves identically to the top level `test()` function.
The following example demonstrates the creation of a
top level test with two subtests.
```js
test('top level test', async (t) => {
t.test('subtest 1', (t) => {
assert.strictEqual(1, 1);
});
t.test('subtest 2', (t) => {
assert.strictEqual(2, 2);
});
});
```
> **Note:** `beforeEach` and `afterEach` hooks are triggered
> between each subtest execution.
Any subtest failures cause the parent test to fail.
## Skipping tests
Individual tests can be skipped by passing the `skip` option to the test, or by
calling the test context's `skip()` method as shown in the
following example.
```js
// The skip option is used, but no message is provided.
test('skip option', { skip: true }, (t) => {
// This code is never executed.
});
// The skip option is used, and a message is provided.
test('skip option with message', { skip: 'this is skipped' }, (t) => {
// This code is never executed.
});
test('skip() method', (t) => {
// Make sure to return here as well if the test contains additional logic.
t.skip();
});
test('skip() method with message', (t) => {
// Make sure to return here as well if the test contains additional logic.
t.skip('this is skipped');
});
```
## TODO tests
Individual tests can be marked as flaky or incomplete by passing the `todo`
option to the test, or by calling the test context's `todo()` method, as shown
in the following example. These tests represent a pending implementation or bug
that needs to be fixed. TODO tests are executed, but are not treated as test
failures, and therefore do not affect the process exit code. If a test is marked
as both TODO and skipped, the TODO option is ignored.
```js
// The todo option is used, but no message is provided.
test('todo option', { todo: true }, (t) => {
// This code is executed, but not treated as a failure.
throw new Error('this does not fail the test');
});
// The todo option is used, and a message is provided.
test('todo option with message', { todo: 'this is a todo test' }, (t) => {
// This code is executed.
});
test('todo() method', (t) => {
t.todo();
});
test('todo() method with message', (t) => {
t.todo('this is a todo test and is not treated as a failure');
throw new Error('this does not fail the test');
});
```
## `describe()` and `it()` aliases
Suites and tests can also be written using the `describe()` and `it()`
functions. [`describe()`][] is an alias for [`suite()`][], and [`it()`][] is an
alias for [`test()`][].
```js
describe('A thing', () => {
it('should work', () => {
assert.strictEqual(1, 1);
});
it('should be ok', () => {
assert.strictEqual(2, 2);
});
describe('a nested thing', () => {
it('should work', () => {
assert.strictEqual(3, 3);
});
});
});
```
`describe()` and `it()` are imported from the `node:test` module.
```mjs
import { describe, it } from 'node:test';
```
```cjs
const { describe, it } = require('node:test');
```
## `only` tests
If Node.js is started with the [`--test-only`][] command-line option, or test
isolation is disabled, it is possible to skip all tests except for a selected
subset by passing the `only` option to the tests that should run. When a test
with the `only` option is set, all subtests are also run.
If a suite has the `only` option set, all tests within the suite are run,
unless it has descendants with the `only` option set, in which case only those
tests are run.
When using [subtests][] within a `test()`/`it()`, it is required to mark
all ancestor tests with the `only` option to run only a
selected subset of tests.
The test context's `runOnly()`
method can be used to implement the same behavior at the subtest level. Tests
that are not executed are omitted from the test runner output.
```js
// Assume Node.js is run with the --test-only command-line option.
// The suite's 'only' option is set, so these tests are run.
test('this test is run', { only: true }, async (t) => {
// Within this test, all subtests are run by default.
t.test('running subtest');
// The test context can be updated to run subtests with the 'only' option.
t.runOnly(true);
t.test('this subtest is now skipped');
t.test('this subtest is run', { only: true });
// Switch the context back to execute all tests.
t.runOnly(false);
t.test('this subtest is now run');
// Explicitly do not run these tests.
t.test('skipped subtest 3', { only: false });
t.test('skipped subtest 4', { skip: true });
});
// The 'only' option is not set, so this test is skipped.
test('this test is not run', () => {
// This code is not run.
throw new Error('fail');
});
describe('a suite', () => {
// The 'only' option is set, so this test is run.
it('this test is run', { only: true }, () => {
// This code is run.
});
it('this test is not run', () => {
// This code is not run.
throw new Error('fail');
});
});
describe.only('a suite', () => {
// The 'only' option is set, so this test is run.
it('this test is run', () => {
// This code is run.
});
it('this test is run', () => {
// This code is run.
});
});
```
## Filtering tests by name
The [`--test-name-pattern`][] command-line option can be used to only run
tests whose name matches the provided pattern, and the
[`--test-skip-pattern`][] option can be used to skip tests whose name
matches the provided pattern. Test name patterns are interpreted as
JavaScript regular expressions. The `--test-name-pattern` and
`--test-skip-pattern` options can be specified multiple times in order to run
nested tests. For each test that is executed, any corresponding test hooks,
such as `beforeEach()`, are also run. Tests that are not executed are omitted
from the test runner output.
Given the following test file, starting Node.js with the
`--test-name-pattern="test [1-3]"` option would cause the test runner to execute
`test 1`, `test 2`, and `test 3`. If `test 1` did not match the test name
pattern, then its subtests would not execute, despite matching the pattern. The
same set of tests could also be executed by passing `--test-name-pattern`
multiple times (e.g. `--test-name-pattern="test 1"`,
`--test-name-pattern="test 2"`, etc.).
```js
test('test 1', async (t) => {
t.test('test 2');
t.test('test 3');
});
test('Test 4', async (t) => {
t.test('Test 5');
t.test('test 6');
});
```
Test name patterns can also be specified using regular expression literals. This
allows regular expression flags to be used. In the previous example, starting
Node.js with `--test-name-pattern="/test [4-5]/i"` (or `--test-skip-pattern="/test [4-5]/i"`)
would match `Test 4` and `Test 5` because the pattern is case-insensitive.
To match a single test with a pattern, you can prefix it with all its ancestor
test names separated by space, to ensure it is unique.
For example, given the following test file:
```js
describe('test 1', (t) => {
it('some test');
});
describe('test 2', (t) => {
it('some test');
});
```
Starting Node.js with `--test-name-pattern="test 1 some test"` would match
only `some test` in `test 1`.
Test name patterns do not change the set of files that the test runner executes.
If both `--test-name-pattern` and `--test-skip-pattern` are supplied,
tests must satisfy **both** requirements in order to be executed.
## Extraneous asynchronous activity
Once a test function finishes executing, the results are reported as quickly
as possible while maintaining the order of the tests. However, it is possible
for the test function to generate asynchronous activity that outlives the test
itself. The test runner handles this type of activity, but does not delay the
reporting of test results in order to accommodate it.
In the following example, a test completes with two `setImmediate()`
operations still outstanding. The first `setImmediate()` attempts to create a
new subtest. Because the parent test has already finished and output its
results, the new subtest is immediately marked as failed, and reported later
to the {TestsStream}.
The second `setImmediate()` creates an `uncaughtException` event.
`uncaughtException` and `unhandledRejection` events originating from a completed
test are marked as failed by the `test` module and reported as diagnostic
warnings at the top level by the {TestsStream}.
```js
test('a test that creates asynchronous activity', (t) => {
setImmediate(() => {
t.test('subtest that is created too late', (t) => {
throw new Error('error1');
});
});
setImmediate(() => {
throw new Error('error2');
});
// The test finishes after this line.
});
```
## Watch mode
<!-- YAML
2023-01-05, Version 18.13.0 'Hydrogen' (LTS) Notable changes: Add support for externally shared js builtins: By default Node.js is built so that all dependencies are bundled into the Node.js binary itself. Some Node.js distributions prefer to manage dependencies externally. There are existing build options that allow dependencies with native code to be externalized. This commit adds additional options so that dependencies with JavaScript code (including WASM) can also be externalized. This addition does not affect binaries shipped by the Node.js project but will allow other distributions to externalize additional dependencies when needed. Contributed by Michael Dawson in https://github.com/nodejs/node/pull/44376 Introduce `File`: The File class is part of the [FileAPI](https://w3c.github.io/FileAPI/). It can be used anywhere a Blob can, for example in `URL.createObjectURL` and `FormData`. It contains two properties that Blobs do not have: `lastModified`, the last time the file was modified in ms, and `name`, the name of the file. Contributed by Khafra in https://github.com/nodejs/node/pull/45139 Support function mocking on Node.js test runner: The `node:test` module supports mocking during testing via a top-level `mock` object. ```js test('spies on an object method', (t) => { const number = { value: 5, add(a) { return this.value + a; }, }; t.mock.method(number, 'add'); assert.strictEqual(number.add(3), 8); assert.strictEqual(number.add.mock.calls.length, 1); }); ``` Contributed by Colin Ihrig in https://github.com/nodejs/node/pull/45326 Other notable changes: build: * disable v8 snapshot compression by default (Joyee Cheung) https://github.com/nodejs/node/pull/45716 crypto: * update root certificates (Luigi Pinca) https://github.com/nodejs/node/pull/45490 deps: * update ICU to 72.1 (Michaël Zasso) https://github.com/nodejs/node/pull/45068 doc: * add doc-only deprecation for headers/trailers setters (Rich Trott) https://github.com/nodejs/node/pull/45697 * add Rafael to the tsc (Michael Dawson) https://github.com/nodejs/node/pull/45691 * deprecate use of invalid ports in `url.parse` (Antoine du Hamel) https://github.com/nodejs/node/pull/45576 * add lukekarrys to collaborators (Luke Karrys) https://github.com/nodejs/node/pull/45180 * add anonrig to collaborators (Yagiz Nizipli) https://github.com/nodejs/node/pull/45002 * deprecate url.parse() (Rich Trott) https://github.com/nodejs/node/pull/44919 lib: * drop fetch experimental warning (Matteo Collina) https://github.com/nodejs/node/pull/45287 net: * (SEMVER-MINOR) add autoSelectFamily and autoSelectFamilyAttemptTimeout options (Paolo Insogna) https://github.com/nodejs/node/pull/44731 * src: * (SEMVER-MINOR) add uvwasi version (Jithil P Ponnan) https://github.com/nodejs/node/pull/45639 * (SEMVER-MINOR) add initial shadow realm support (Chengzhong Wu) https://github.com/nodejs/node/pull/42869 test_runner: * (SEMVER-MINOR) add t.after() hook (Colin Ihrig) https://github.com/nodejs/node/pull/45792 * (SEMVER-MINOR) don't use a symbol for runHook() (Colin Ihrig) https://github.com/nodejs/node/pull/45792 tls: * (SEMVER-MINOR) add "ca" property to certificate object (Ben Noordhuis) https://github.com/nodejs/node/pull/44935 * remove trustcor root ca certificates (Ben Noordhuis) https://github.com/nodejs/node/pull/45776 tools: * update certdata.txt (Luigi Pinca) https://github.com/nodejs/node/pull/45490 util: * add fast path for utf8 encoding (Yagiz Nizipli) https://github.com/nodejs/node/pull/45412 * improve textdecoder decode performance (Yagiz Nizipli) https://github.com/nodejs/node/pull/45294 * (SEMVER-MINOR) add MIME utilities (#21128) (Bradley Farias) https://github.com/nodejs/node/pull/21128 PR-URL: https://github.com/nodejs/node/pull/46025
2022-12-30 15:18:44 -05:00
added:
- v19.2.0
- v18.13.0
-->
> Stability: 1 - Experimental
The Node.js test runner supports running in watch mode by passing the `--watch` flag:
```bash
node --test --watch
```
In watch mode, the test runner will watch for changes to test files and
their dependencies. When a change is detected, the test runner will
rerun the tests affected by the change.
The test runner will continue to run until the process is terminated.
## Global setup and teardown
<!-- YAML
added: REPLACEME
-->
> Stability: 1.0 - Early development
The test runner supports specifying a module that will be evaluated before all tests are executed and
can be used to setup global state or fixtures for tests. This is useful for preparing resources or setting up
shared state that is required by multiple tests.
This module can export any of the following:
* A `globalSetup` function which runs once before all tests start
* A `globalTeardown` function which runs once after all tests complete
The module is specified using the `--test-global-setup` flag when running tests from the command line.
```cjs
// setup-module.js
async function globalSetup() {
// Setup shared resources, state, or environment
console.log('Global setup executed');
// Run servers, create files, prepare databases, etc.
}
async function globalTeardown() {
// Clean up resources, state, or environment
console.log('Global teardown executed');
// Close servers, remove files, disconnect from databases, etc.
}
module.exports = { globalSetup, globalTeardown };
```
```mjs
// setup-module.mjs
export async function globalSetup() {
// Setup shared resources, state, or environment
console.log('Global setup executed');
// Run servers, create files, prepare databases, etc.
}
export async function globalTeardown() {
// Clean up resources, state, or environment
console.log('Global teardown executed');
// Close servers, remove files, disconnect from databases, etc.
}
```
If the global setup function throws an error, no tests will be run and the process will exit with a non-zero exit code.
The global teardown function will not be called in this case.
## Running tests from the command line
The Node.js test runner can be invoked from the command line by passing the
[`--test`][] flag:
```bash
node --test
```
By default, Node.js will run all files matching these patterns:
* `**/*.test.{cjs,mjs,js}`
* `**/*-test.{cjs,mjs,js}`
* `**/*_test.{cjs,mjs,js}`
* `**/test-*.{cjs,mjs,js}`
* `**/test.{cjs,mjs,js}`
* `**/test/**/*.{cjs,mjs,js}`
Unless [`--no-experimental-strip-types`][] is supplied, the following
additional patterns are also matched:
* `**/test/**/*-test.{cts,mts,ts}`
* `**/test/**/*.test.{cts,mts,ts}`
* `**/test/**/*_test.{cts,mts,ts}`
Alternatively, one or more glob patterns can be provided as the
final argument(s) to the Node.js command, as shown below.
Glob patterns follow the behavior of [`glob(7)`][].
The glob patterns should be enclosed in double quotes on the command line to
prevent shell expansion, which can reduce portability across systems.
```bash
node --test "**/*.test.js" "**/*.spec.js"
```
Matching files are executed as test files.
More information on the test file execution can be found
in the [test runner execution model][] section.
### Test runner execution model
When process-level test isolation is enabled, each matching test file is
executed in a separate child process. The maximum number of child processes
running at any time is controlled by the [`--test-concurrency`][] flag. If the
child process finishes with an exit code of 0, the test is considered passing.
Otherwise, the test is considered to be a failure. Test files must be executable
by Node.js, but are not required to use the `node:test` module internally.
Each test file is executed as if it was a regular script. That is, if the test
file itself uses `node:test` to define tests, all of those tests will be
executed within a single application thread, regardless of the value of the
`concurrency` option of [`test()`][].
When process-level test isolation is disabled, each matching test file is
imported into the test runner process. Once all test files have been loaded, the
top level tests are executed with a concurrency of one. Because the test files
are all run within the same context, it is possible for tests to interact with
each other in ways that are not possible when isolation is enabled. For example,
if a test relies on global state, it is possible for that state to be modified
by a test originating from another file.
## Collecting code coverage
> Stability: 1 - Experimental
When Node.js is started with the [`--experimental-test-coverage`][]
command-line flag, code coverage is collected and statistics are reported once
all tests have completed. If the [`NODE_V8_COVERAGE`][] environment variable is
used to specify a code coverage directory, the generated V8 coverage files are
written to that directory. Node.js core modules and files within
`node_modules/` directories are, by default, not included in the coverage report.
However, they can be explicitly included via the [`--test-coverage-include`][] flag.
By default all the matching test files are excluded from the coverage report.
Exclusions can be overridden by using the [`--test-coverage-exclude`][] flag.
If coverage is enabled, the coverage report is sent to any [test reporters][] via
the `'test:coverage'` event.
Coverage can be disabled on a series of lines using the following
comment syntax:
```js
/* node:coverage disable */
if (anAlwaysFalseCondition) {
// Code in this branch will never be executed, but the lines are ignored for
// coverage purposes. All lines following the 'disable' comment are ignored
// until a corresponding 'enable' comment is encountered.
console.log('this is never executed');
}
/* node:coverage enable */
```
Coverage can also be disabled for a specified number of lines. After the
specified number of lines, coverage will be automatically reenabled. If the
number of lines is not explicitly provided, a single line is ignored.
```js
/* node:coverage ignore next */
if (anAlwaysFalseCondition) { console.log('this is never executed'); }
/* node:coverage ignore next 3 */
if (anAlwaysFalseCondition) {
console.log('this is never executed');
}
```
### Coverage reporters
The tap and spec reporters will print a summary of the coverage statistics.
There is also an lcov reporter that will generate an lcov file which can be
used as an in depth coverage report.
```bash
node --test --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=lcov.info
```
* No test results are reported by this reporter.
* This reporter should ideally be used alongside another reporter.
## Mocking
The `node:test` module supports mocking during testing via a top-level `mock`
object. The following example creates a spy on a function that adds two numbers
together. The spy is then used to assert that the function was called as
expected.
```mjs
import assert from 'node:assert';
import { mock, test } from 'node:test';
test('spies on a function', () => {
const sum = mock.fn((a, b) => {
return a + b;
});
assert.strictEqual(sum.mock.callCount(), 0);
assert.strictEqual(sum(3, 4), 7);
assert.strictEqual(sum.mock.callCount(), 1);
const call = sum.mock.calls[0];
assert.deepStrictEqual(call.arguments, [3, 4]);
assert.strictEqual(call.result, 7);
assert.strictEqual(call.error, undefined);
// Reset the globally tracked mocks.
mock.reset();
});
```
```cjs
'use strict';
const assert = require('node:assert');
const { mock, test } = require('node:test');
test('spies on a function', () => {
const sum = mock.fn((a, b) => {
return a + b;
});
assert.strictEqual(sum.mock.callCount(), 0);
assert.strictEqual(sum(3, 4), 7);
assert.strictEqual(sum.mock.callCount(), 1);
const call = sum.mock.calls[0];
assert.deepStrictEqual(call.arguments, [3, 4]);
assert.strictEqual(call.result, 7);
assert.strictEqual(call.error, undefined);
// Reset the globally tracked mocks.
mock.reset();
});
```
The same mocking functionality is also exposed on the [`TestContext`][] object
of each test. The following example creates a spy on an object method using the
API exposed on the `TestContext`. The benefit of mocking via the test context is
that the test runner will automatically restore all mocked functionality once
the test finishes.
```js
test('spies on an object method', (t) => {
const number = {
value: 5,
add(a) {
return this.value + a;
},
};
t.mock.method(number, 'add');
assert.strictEqual(number.add.mock.callCount(), 0);
assert.strictEqual(number.add(3), 8);
assert.strictEqual(number.add.mock.callCount(), 1);
const call = number.add.mock.calls[0];
assert.deepStrictEqual(call.arguments, [3]);
assert.strictEqual(call.result, 8);
assert.strictEqual(call.target, undefined);
assert.strictEqual(call.this, number);
});
```
### Timers
Mocking timers is a technique commonly used in software testing to simulate and
control the behavior of timers, such as `setInterval` and `setTimeout`,
without actually waiting for the specified time intervals.
Refer to the [`MockTimers`][] class for a full list of methods and features.
This allows developers to write more reliable and
predictable tests for time-dependent functionality.
The example below shows how to mock `setTimeout`.
Using `.enable({ apis: ['setTimeout'] });`
it will mock the `setTimeout` functions in the [node:timers](./timers.md) and
[node:timers/promises](./timers.md#timers-promises-api) modules,
as well as from the Node.js global context.
**Note:** Destructuring functions such as
`import { setTimeout } from 'node:timers'`
is currently not supported by this API.
```mjs
import assert from 'node:assert';
import { mock, test } from 'node:test';
test('mocks setTimeout to be executed synchronously without having to actually wait for it', () => {
const fn = mock.fn();
// Optionally choose what to mock
mock.timers.enable({ apis: ['setTimeout'] });
setTimeout(fn, 9999);
assert.strictEqual(fn.mock.callCount(), 0);
// Advance in time
mock.timers.tick(9999);
assert.strictEqual(fn.mock.callCount(), 1);
// Reset the globally tracked mocks.
mock.timers.reset();
// If you call reset mock instance, it will also reset timers instance
mock.reset();
});
```
```cjs
const assert = require('node:assert');
const { mock, test } = require('node:test');
test('mocks setTimeout to be executed synchronously without having to actually wait for it', () => {
const fn = mock.fn();
// Optionally choose what to mock
mock.timers.enable({ apis: ['setTimeout'] });
setTimeout(fn, 9999);
assert.strictEqual(fn.mock.callCount(), 0);
// Advance in time
mock.timers.tick(9999);
assert.strictEqual(fn.mock.callCount(), 1);
// Reset the globally tracked mocks.
mock.timers.reset();
// If you call reset mock instance, it will also reset timers instance
mock.reset();
});
```
The same mocking functionality is also exposed in the mock property on the [`TestContext`][] object
of each test. The benefit of mocking via the test context is
that the test runner will automatically restore all mocked timers
functionality once the test finishes.
```mjs
import assert from 'node:assert';
import { test } from 'node:test';
test('mocks setTimeout to be executed synchronously without having to actually wait for it', (context) => {
const fn = context.mock.fn();
// Optionally choose what to mock
context.mock.timers.enable({ apis: ['setTimeout'] });
setTimeout(fn, 9999);
assert.strictEqual(fn.mock.callCount(), 0);
// Advance in time
context.mock.timers.tick(9999);
assert.strictEqual(fn.mock.callCount(), 1);
});
```
```cjs
const assert = require('node:assert');
const { test } = require('node:test');
test('mocks setTimeout to be executed synchronously without having to actually wait for it', (context) => {
const fn = context.mock.fn();
// Optionally choose what to mock
context.mock.timers.enable({ apis: ['setTimeout'] });
setTimeout(fn, 9999);
assert.strictEqual(fn.mock.callCount(), 0);
// Advance in time
context.mock.timers.tick(9999);
assert.strictEqual(fn.mock.callCount(), 1);
});
```
### Dates
The mock timers API also allows the mocking of the `Date` object. This is a
useful feature for testing time-dependent functionality, or to simulate
internal calendar functions such as `Date.now()`.
The dates implementation is also part of the [`MockTimers`][] class. Refer to it
for a full list of methods and features.
**Note:** Dates and timers are dependent when mocked together. This means that
if you have both the `Date` and `setTimeout` mocked, advancing the time will
also advance the mocked date as they simulate a single internal clock.
The example below show how to mock the `Date` object and obtain the current
`Date.now()` value.
```mjs
import assert from 'node:assert';
import { test } from 'node:test';
test('mocks the Date object', (context) => {
// Optionally choose what to mock
context.mock.timers.enable({ apis: ['Date'] });
// If not specified, the initial date will be based on 0 in the UNIX epoch
assert.strictEqual(Date.now(), 0);
// Advance in time will also advance the date
context.mock.timers.tick(9999);
assert.strictEqual(Date.now(), 9999);
});
```
```cjs
const assert = require('node:assert');
const { test } = require('node:test');
test('mocks the Date object', (context) => {
// Optionally choose what to mock
context.mock.timers.enable({ apis: ['Date'] });
// If not specified, the initial date will be based on 0 in the UNIX epoch
assert.strictEqual(Date.now(), 0);
// Advance in time will also advance the date
context.mock.timers.tick(9999);
assert.strictEqual(Date.now(), 9999);
});
```
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.
```mjs
import assert from 'node:assert';
import { test } from 'node:test';
test('mocks the Date object with initial time', (context) => {
// Optionally choose what to mock
context.mock.timers.enable({ apis: ['Date'], now: 100 });
assert.strictEqual(Date.now(), 100);
// Advance in time will also advance the date
context.mock.timers.tick(200);
assert.strictEqual(Date.now(), 300);
});
```
```cjs
const assert = require('node:assert');
const { test } = require('node:test');
test('mocks the Date object with initial time', (context) => {
// Optionally choose what to mock
context.mock.timers.enable({ apis: ['Date'], now: 100 });
assert.strictEqual(Date.now(), 100);
// Advance in time will also advance the date
context.mock.timers.tick(200);
assert.strictEqual(Date.now(), 300);
});
```
You can use the `.setTime()` method to manually move the mocked date to another
time. This method only accepts a positive integer.
**Note:** This method will execute any mocked timers that are in the past
from the new time.
In the below example we are setting a new time for the mocked date.
```mjs
import assert from 'node:assert';
import { test } from 'node:test';
test('sets the time of a date object', (context) => {
// Optionally choose what to mock
context.mock.timers.enable({ apis: ['Date'], now: 100 });
assert.strictEqual(Date.now(), 100);
// Advance in time will also advance the date
context.mock.timers.setTime(1000);
context.mock.timers.tick(200);
assert.strictEqual(Date.now(), 1200);
});
```
```cjs
const assert = require('node:assert');
const { test } = require('node:test');
test('sets the time of a date object', (context) => {
// Optionally choose what to mock
context.mock.timers.enable({ apis: ['Date'], now: 100 });
assert.strictEqual(Date.now(), 100);
// Advance in time will also advance the date
context.mock.timers.setTime(1000);
context.mock.timers.tick(200);
assert.strictEqual(Date.now(), 1200);
});
```
If you have any timer that's set to run in the past, it will be executed as if
the `.tick()` method has been called. This is useful if you want to test
time-dependent functionality that's already in the past.
```mjs
import assert from 'node:assert';
import { test } from 'node:test';
test('runs timers as setTime passes ticks', (context) => {
// Optionally choose what to mock
context.mock.timers.enable({ apis: ['setTimeout', 'Date'] });
const fn = context.mock.fn();
setTimeout(fn, 1000);
context.mock.timers.setTime(800);
// Timer is not executed as the time is not yet reached
assert.strictEqual(fn.mock.callCount(), 0);
assert.strictEqual(Date.now(), 800);
context.mock.timers.setTime(1200);
// Timer is executed as the time is now reached
assert.strictEqual(fn.mock.callCount(), 1);
assert.strictEqual(Date.now(), 1200);
});
```
```cjs
const assert = require('node:assert');
const { test } = require('node:test');
test('runs timers as setTime passes ticks', (context) => {
// Optionally choose what to mock
context.mock.timers.enable({ apis: ['setTimeout', 'Date'] });
const fn = context.mock.fn();
setTimeout(fn, 1000);
context.mock.timers.setTime(800);
// Timer is not executed as the time is not yet reached
assert.strictEqual(fn.mock.callCount(), 0);
assert.strictEqual(Date.now(), 800);
context.mock.timers.setTime(1200);
// Timer is executed as the time is now reached
assert.strictEqual(fn.mock.callCount(), 1);
assert.strictEqual(Date.now(), 1200);
});
```
Using `.runAll()` will execute all timers that are currently in the queue. This
will also advance the mocked date to the time of the last timer that was
executed as if the time has passed.
```mjs
import assert from 'node:assert';
import { test } from 'node:test';
test('runs timers as setTime passes ticks', (context) => {
// Optionally choose what to mock
context.mock.timers.enable({ apis: ['setTimeout', 'Date'] });
const fn = context.mock.fn();
setTimeout(fn, 1000);
setTimeout(fn, 2000);
setTimeout(fn, 3000);
context.mock.timers.runAll();
// All timers are executed as the time is now reached
assert.strictEqual(fn.mock.callCount(), 3);
assert.strictEqual(Date.now(), 3000);
});
```
```cjs
const assert = require('node:assert');
const { test } = require('node:test');
test('runs timers as setTime passes ticks', (context) => {
// Optionally choose what to mock
context.mock.timers.enable({ apis: ['setTimeout', 'Date'] });
const fn = context.mock.fn();
setTimeout(fn, 1000);
setTimeout(fn, 2000);
setTimeout(fn, 3000);
context.mock.timers.runAll();
// All timers are executed as the time is now reached
assert.strictEqual(fn.mock.callCount(), 3);
assert.strictEqual(Date.now(), 3000);
});
```
## Snapshot testing
<!-- YAML
added: v22.3.0
changes:
- version: v23.4.0
pr-url: https://github.com/nodejs/node/pull/55897
description: Snapsnot testing is no longer experimental.
-->
Snapshot tests allow arbitrary values to be serialized into string values and
compared against a set of known good values. The known good values are known as
snapshots, and are stored in a snapshot file. Snapshot files are managed by the
test runner, but are designed to be human readable to aid in debugging. Best
practice is for snapshot files to be checked into source control along with your
test files.
Snapshot files are generated by starting Node.js with the
[`--test-update-snapshots`][] command-line flag. A separate snapshot file is
generated for each test file. By default, the snapshot file has the same name
as the test file with a `.snapshot` file extension. This behavior can be
configured using the `snapshot.setResolveSnapshotPath()` function. Each
snapshot assertion corresponds to an export in the snapshot file.
An example snapshot test is shown below. The first time this test is executed,
it will fail because the corresponding snapshot file does not exist.
```js
// test.js
suite('suite of snapshot tests', () => {
test('snapshot test', (t) => {
t.assert.snapshot({ value1: 1, value2: 2 });
t.assert.snapshot(5);
});
});
```
Generate the snapshot file by running the test file with
`--test-update-snapshots`. The test should pass, and a file named
`test.js.snapshot` is created in the same directory as the test file. The
contents of the snapshot file are shown below. Each snapshot is identified by
the full name of test and a counter to differentiate between snapshots in the
same test.
```js
exports[`suite of snapshot tests > snapshot test 1`] = `
{
"value1": 1,
"value2": 2
}
`;
exports[`suite of snapshot tests > snapshot test 2`] = `
5
`;
```
Once the snapshot file is created, run the tests again without the
`--test-update-snapshots` flag. The tests should pass now.
## Test reporters
<!-- YAML
added:
- v19.6.0
- v18.15.0
changes:
2023-07-18, Version 18.17.0 'Hydrogen' (LTS) Notable changes: Ada 2.0 Node.js v18.17.0 comes with the latest version of the URL parser, Ada. This update brings significant performance improvements to URL parsing, including enhancements to the url.domainToASCII and url.domainToUnicode functions in node:url. Ada 2.0 has been integrated into the Node.js codebase, ensuring that all parts of the application can benefit from the improved performance. Additionally, Ada 2.0 features a significant performance boost over its predecessor, Ada 1.0.4, while also eliminating the need for the ICU requirement for URL hostname parsing. Contributed by Yagiz Nizipli and Daniel Lemire in https://github.com/nodejs/node/pull/47339 Web Crypto API Web Crypto API functions' arguments are now coerced and validated as per their WebIDL definitions like in other Web Crypto API implementations. This further improves interoperability with other implementations of Web Crypto API. Contributed by Filip Skokan in https://github.com/nodejs/node/pull/46067 crypto: * update root certificates to NSS 3.89 (Node.js GitHub Bot) https://github.com/nodejs/node/pull/47659 dns: * (SEMVER-MINOR) expose getDefaultResultOrder (btea) https://github.com/nodejs/node/pull/46973 doc: * add ovflowd to collaborators (Claudio Wunder) https://github.com/nodejs/node/pull/47844 * add KhafraDev to collaborators (Matthew Aitken) https://github.com/nodejs/node/pull/47510 * events: * (SEMVER-MINOR) add getMaxListeners method (Matthew Aitken) https://github.com/nodejs/node/pull/47039 fs: * (SEMVER-MINOR) add support for mode flag to specify the copy behavior (Tetsuharu Ohzeki) https://github.com/nodejs/node/pull/47084 * (SEMVER-MINOR) add recursive option to readdir and opendir (Ethan Arrowood) https://github.com/nodejs/node/pull/41439 * (SEMVER-MINOR) add support for mode flag to specify the copy behavior (Tetsuharu Ohzeki) https://github.com/nodejs/node/pull/47084 * (SEMVER-MINOR) implement byob mode for readableWebStream() (Debadree Chatterjee) https://github.com/nodejs/node/pull/46933 http: * (SEMVER-MINOR) prevent writing to the body when not allowed by HTTP spec (Gerrard Lindsay) https://github.com/nodejs/node/pull/47732 * (SEMVER-MINOR) remove internal error in assignSocket (Matteo Collina) https://github.com/nodejs/node/pull/47723 * (SEMVER-MINOR) add highWaterMark opt in http.createServer (HinataKah0) https://github.com/nodejs/node/pull/47405 lib: * (SEMVER-MINOR) add webstreams to Duplex.from() (Debadree Chatterjee) https://github.com/nodejs/node/pull/46190 * (SEMVER-MINOR) implement AbortSignal.any() (Chemi Atlow) https://github.com/nodejs/node/pull/47821 module: * change default resolver to not throw on unknown scheme (Gil Tayar) https://github.com/nodejs/node/pull/47824 node-api: * (SEMVER-MINOR) define version 9 (Chengzhong Wu) https://github.com/nodejs/node/pull/48151 * (SEMVER-MINOR) deprecate napi_module_register (Vladimir Morozov) https://github.com/nodejs/node/pull/46319 stream: * (SEMVER-MINOR) preserve object mode in compose (Raz Luvaton) https://github.com/nodejs/node/pull/47413 * (SEMVER-MINOR) add setter & getter for default highWaterMark (#46929) (Robert Nagy) https://github.com/nodejs/node/pull/46929 test: * unflake test-vm-timeout-escape-nexttick (Santiago Gimeno) https://github.com/nodejs/node/pull/48078 test_runner: * (SEMVER-MINOR) add shorthands to `test` (Chemi Atlow) https://github.com/nodejs/node/pull/47909 * (SEMVER-MINOR) support combining coverage reports (Colin Ihrig) https://github.com/nodejs/node/pull/47686 * (SEMVER-MINOR) execute before hook on test (Chemi Atlow) https://github.com/nodejs/node/pull/47586 * (SEMVER-MINOR) expose reporter for use in run api (Chemi Atlow) https://github.com/nodejs/node/pull/47238 tools: * update LICENSE and license-builder.sh (Santiago Gimeno) https://github.com/nodejs/node/pull/48078 url: * (SEMVER-MINOR) implement URL.canParse (Matthew Aitken) https://github.com/nodejs/node/pull/47179 wasi: * (SEMVER-MINOR) no longer require flag to enable wasi (Michael Dawson) https://github.com/nodejs/node/pull/47286 PR-URL: https://github.com/nodejs/node/pull/48694
2023-07-10 08:12:52 -04:00
- version:
- v19.9.0
- v18.17.0
pr-url: https://github.com/nodejs/node/pull/47238
description: Reporters are now exposed at `node:test/reporters`.
-->
The `node:test` module supports passing [`--test-reporter`][]
flags for the test runner to use a specific reporter.
The following built-reporters are supported:
* `spec`
The `spec` reporter outputs the test results in a human-readable format. This
is the default reporter.
* `tap`
The `tap` reporter outputs the test results in the [TAP][] format.
* `dot`
The `dot` reporter outputs the test results in a compact format,
where each passing test is represented by a `.`,
and each failing test is represented by a `X`.
* `junit`
The junit reporter outputs test results in a jUnit XML format
* `lcov`
The `lcov` reporter outputs test coverage when used with the
[`--experimental-test-coverage`][] flag.
The exact output of these reporters is subject to change between versions of
Node.js, and should not be relied on programmatically. If programmatic access
to the test runner's output is required, use the events emitted by the
{TestsStream}.
The reporters are available via the `node:test/reporters` module:
```mjs
import { tap, spec, dot, junit, lcov } from 'node:test/reporters';
```
```cjs
const { tap, spec, dot, junit, lcov } = require('node:test/reporters');
```
### Custom reporters
[`--test-reporter`][] can be used to specify a path to custom reporter.
A custom reporter is a module that exports a value
accepted by [stream.compose][].
Reporters should transform events emitted by a {TestsStream}
Example of a custom reporter using {stream.Transform}:
```mjs
import { Transform } from 'node:stream';
const customReporter = new Transform({
writableObjectMode: true,
transform(event, encoding, callback) {
switch (event.type) {
case 'test:dequeue':
callback(null, `test ${event.data.name} dequeued`);
break;
case 'test:enqueue':
callback(null, `test ${event.data.name} enqueued`);
break;
case 'test:watch:drained':
callback(null, 'test watch queue drained');
break;
case 'test:start':
callback(null, `test ${event.data.name} started`);
break;
case 'test:pass':
callback(null, `test ${event.data.name} passed`);
break;
case 'test:fail':
callback(null, `test ${event.data.name} failed`);
break;
case 'test:plan':
callback(null, 'test plan');
break;
case 'test:diagnostic':
case 'test:stderr':
case 'test:stdout':
callback(null, event.data.message);
break;
case 'test:coverage': {
const { totalLineCount } = event.data.summary.totals;
callback(null, `total line count: ${totalLineCount}\n`);
break;
}
}
},
});
export default customReporter;
```
```cjs
const { Transform } = require('node:stream');
const customReporter = new Transform({
writableObjectMode: true,
transform(event, encoding, callback) {
switch (event.type) {
case 'test:dequeue':
callback(null, `test ${event.data.name} dequeued`);
break;
case 'test:enqueue':
callback(null, `test ${event.data.name} enqueued`);
break;
case 'test:watch:drained':
callback(null, 'test watch queue drained');
break;
case 'test:start':
callback(null, `test ${event.data.name} started`);
break;
case 'test:pass':
callback(null, `test ${event.data.name} passed`);
break;
case 'test:fail':
callback(null, `test ${event.data.name} failed`);
break;
case 'test:plan':
callback(null, 'test plan');
break;
case 'test:diagnostic':
case 'test:stderr':
case 'test:stdout':
callback(null, event.data.message);
break;
case 'test:coverage': {
const { totalLineCount } = event.data.summary.totals;
callback(null, `total line count: ${totalLineCount}\n`);
break;
}
}
},
});
module.exports = customReporter;
```
Example of a custom reporter using a generator function:
```mjs
export default async function * customReporter(source) {
for await (const event of source) {
switch (event.type) {
case 'test:dequeue':
yield `test ${event.data.name} dequeued\n`;
break;
case 'test:enqueue':
yield `test ${event.data.name} enqueued\n`;
break;
case 'test:watch:drained':
yield 'test watch queue drained\n';
break;
case 'test:start':
yield `test ${event.data.name} started\n`;
break;
case 'test:pass':
yield `test ${event.data.name} passed\n`;
break;
case 'test:fail':
yield `test ${event.data.name} failed\n`;
break;
case 'test:plan':
yield 'test plan\n';
break;
case 'test:diagnostic':
case 'test:stderr':
case 'test:stdout':
yield `${event.data.message}\n`;
break;
case 'test:coverage': {
const { totalLineCount } = event.data.summary.totals;
yield `total line count: ${totalLineCount}\n`;
break;
}
}
}
}
```
```cjs
module.exports = async function * customReporter(source) {
for await (const event of source) {
switch (event.type) {
case 'test:dequeue':
yield `test ${event.data.name} dequeued\n`;
break;
case 'test:enqueue':
yield `test ${event.data.name} enqueued\n`;
break;
case 'test:watch:drained':
yield 'test watch queue drained\n';
break;
case 'test:start':
yield `test ${event.data.name} started\n`;
break;
case 'test:pass':
yield `test ${event.data.name} passed\n`;
break;
case 'test:fail':
yield `test ${event.data.name} failed\n`;
break;
case 'test:plan':
yield 'test plan\n';
break;
case 'test:diagnostic':
case 'test:stderr':
case 'test:stdout':
yield `${event.data.message}\n`;
break;
case 'test:coverage': {
const { totalLineCount } = event.data.summary.totals;
yield `total line count: ${totalLineCount}\n`;
break;
}
}
}
};
```
The value provided to `--test-reporter` should be a string like one used in an
`import()` in JavaScript code, or a value provided for [`--import`][].
### Multiple reporters
The [`--test-reporter`][] flag can be specified multiple times to report test
results in several formats. In this situation
it is required to specify a destination for each reporter
using [`--test-reporter-destination`][].
Destination can be `stdout`, `stderr`, or a file path.
Reporters and destinations are paired according
to the order they were specified.
In the following example, the `spec` reporter will output to `stdout`,
and the `dot` reporter will output to `file.txt`:
```bash
node --test-reporter=spec --test-reporter=dot --test-reporter-destination=stdout --test-reporter-destination=file.txt
```
When a single reporter is specified, the destination will default to `stdout`,
unless a destination is explicitly provided.
## `run([options])`
<!-- YAML
added:
- v18.9.0
- v16.19.0
changes:
2024-10-16, Version 23.0.0 (Current) Semver-Major Commits: assert,util: * (SEMVER-MAJOR) change WeakMap and WeakSet comparison handling (Cristian Barlutiu) https://github.com/nodejs/node/pull/53495 buffer: * (SEMVER-MAJOR) throw when writing beyond buffer" (Robert Nagy) https://github.com/nodejs/node/pull/54588 * (SEMVER-MAJOR) make File cloneable (Matthew Aitken) https://github.com/nodejs/node/pull/47613 build: * (SEMVER-MAJOR) reset embedder string to "-node.0" (Michaël Zasso) https://github.com/nodejs/node/pull/54536 * (SEMVER-MAJOR) disable ICF for mksnapshot (Leszek Swirski) https://github.com/nodejs/node/pull/54077 * (SEMVER-MAJOR) include v8-sandbox.h header in distribution (Michaël Zasso) https://github.com/nodejs/node/pull/54077 * (SEMVER-MAJOR) reset embedder string to "-node.0" (Michaël Zasso) https://github.com/nodejs/node/pull/54077 * (SEMVER-MAJOR) warn for GCC versions earlier than 12.2 (Michaël Zasso) https://github.com/nodejs/node/pull/54081 * (SEMVER-MAJOR) drop experimental support for Windows <10 (Michaël Zasso) https://github.com/nodejs/node/pull/54079 * (SEMVER-MAJOR) remove support for 32-bit Windows (Michaël Zasso) https://github.com/nodejs/node/pull/53184 * (SEMVER-MAJOR) compile with C++20 support (Michaël Zasso) https://github.com/nodejs/node/pull/45427 child_process: * (SEMVER-MAJOR) remove unused internal event (Rich Trott) https://github.com/nodejs/node/pull/53793 cli: * (SEMVER-MAJOR) remove deprecated V8 flag (Omer Katz) https://github.com/nodejs/node/pull/54761 * (SEMVER-MAJOR) move --trace-atomics-wait to eol (Marco Ippolito) https://github.com/nodejs/node/pull/52747 * (SEMVER-MAJOR) remove --no-experimental-global-customevent flag (Daeyeon Jeong) https://github.com/nodejs/node/pull/52723 * (SEMVER-MAJOR) remove --no-experimental-fetch flag (Filip Skokan) https://github.com/nodejs/node/pull/52611 * (SEMVER-MAJOR) remove --no-experimental-global-webcrypto flag (Filip Skokan) https://github.com/nodejs/node/pull/52564 crypto: * (SEMVER-MAJOR) runtime deprecate crypto.fips (Yagiz Nizipli) https://github.com/nodejs/node/pull/55019 * (SEMVER-MAJOR) remove ERR_CRYPTO_SCRYPT_INVALID_PARAMETER (Tobias Nießen) https://github.com/nodejs/node/pull/53305 * (SEMVER-MAJOR) move DEP0182 to runtime deprecation (Tobias Nießen) https://github.com/nodejs/node/pull/52552 deps: * (SEMVER-MAJOR) V8: cherry-pick 97199f686e2f (Michaël Zasso) https://github.com/nodejs/node/pull/54536 * (SEMVER-MAJOR) V8: cherry-pick 01a47f3ffff2 (Michaël Zasso) https://github.com/nodejs/node/pull/54536 * (SEMVER-MAJOR) patch V8 to support older Clang versions (Michaël Zasso) https://github.com/nodejs/node/pull/54536 * (SEMVER-MAJOR) always define V8_NODISCARD as no-op (Michaël Zasso) https://github.com/nodejs/node/pull/54536 * (SEMVER-MAJOR) fix FP16 bitcasts.h (Stefan Stojanovic) https://github.com/nodejs/node/pull/54536 * (SEMVER-MAJOR) patch V8 to support compilation with MSVC (StefanStojanovic) https://github.com/nodejs/node/pull/54536 * (SEMVER-MAJOR) patch V8 to avoid duplicated zlib symbol (Michaël Zasso) https://github.com/nodejs/node/pull/54536 * (SEMVER-MAJOR) disable V8 concurrent sparkplug compilation (Michaël Zasso) https://github.com/nodejs/node/pull/54536 * (SEMVER-MAJOR) always define V8_EXPORT_PRIVATE as no-op (Michaël Zasso) https://github.com/nodejs/node/pull/54536 * (SEMVER-MAJOR) update V8 to 12.9.202.18 (Michaël Zasso) https://github.com/nodejs/node/pull/54536 * (SEMVER-MAJOR) remove bogus V8 DCHECK (Michaël Zasso) https://github.com/nodejs/node/pull/54077 * (SEMVER-MAJOR) V8: cherry-pick 00e9eeb3fb2c (Michaël Zasso) https://github.com/nodejs/node/pull/54077 * (SEMVER-MAJOR) V8: cherry-pick b1397772c70c (Michaël Zasso) https://github.com/nodejs/node/pull/54077 * (SEMVER-MAJOR) V8: cherry-pick 35888fee7bba (Joyee Cheung) https://github.com/nodejs/node/pull/54077 * (SEMVER-MAJOR) always define V8_NODISCARD as no-op (Michaël Zasso) https://github.com/nodejs/node/pull/54077 * (SEMVER-MAJOR) fix FP16 bitcasts.h (Stefan Stojanovic) https://github.com/nodejs/node/pull/54077 * (SEMVER-MAJOR) V8: revert CL 5331688 (Michaël Zasso) https://github.com/nodejs/node/pull/54077 * (SEMVER-MAJOR) patch V8 to support compilation with MSVC (StefanStojanovic) https://github.com/nodejs/node/pull/54077 * (SEMVER-MAJOR) silence internal V8 deprecation warning (Michaël Zasso) https://github.com/nodejs/node/pull/54077 * (SEMVER-MAJOR) patch V8 to avoid duplicated zlib symbol (Michaël Zasso) https://github.com/nodejs/node/pull/54077 * (SEMVER-MAJOR) avoid compilation error with ASan (Michaël Zasso) https://github.com/nodejs/node/pull/54077 * (SEMVER-MAJOR) disable V8 concurrent sparkplug compilation (Michaël Zasso) https://github.com/nodejs/node/pull/54077 * (SEMVER-MAJOR) always define V8_EXPORT_PRIVATE as no-op (Michaël Zasso) https://github.com/nodejs/node/pull/54077 * (SEMVER-MAJOR) update V8 to 12.8.374.13 (Michaël Zasso) https://github.com/nodejs/node/pull/54077 doc: * (SEMVER-MAJOR) reflect toolchains used for official binaries (Richard Lau) https://github.com/nodejs/node/pull/54967 * (SEMVER-MAJOR) use gcc 12 on AIX for Node.js >=23 (Richard Lau) https://github.com/nodejs/node/pull/54338 esm: * (SEMVER-MAJOR) export 'module.exports' on ESM CJS wrapper (Guy Bedford) https://github.com/nodejs/node/pull/53848 events: * (SEMVER-MAJOR) set EventEmitterAsyncResource fields private (Yagiz Nizipli) https://github.com/nodejs/node/pull/54889 fs: * (SEMVER-MAJOR) adjust typecheck for `type` in `fs.symlink()` (Livia Medeiros) https://github.com/nodejs/node/pull/49741 * (SEMVER-MAJOR) runtime deprecate `dirent.path` (Antoine du Hamel) https://github.com/nodejs/node/pull/51050 lib: * (SEMVER-MAJOR) validate signals with interface converter (Jason Zhang) https://github.com/nodejs/node/pull/54965 * (SEMVER-MAJOR) implement interface converter in webidl (Jason Zhang) https://github.com/nodejs/node/pull/54965 * (SEMVER-MAJOR) expose global CloseEvent (Matthew Aitken) https://github.com/nodejs/node/pull/53355 net: * (SEMVER-MAJOR) validate host name for server listen (Jason Zhang) https://github.com/nodejs/node/pull/54470 path: * (SEMVER-MAJOR) fix bugs and inconsistencies (Hüseyin Açacak) https://github.com/nodejs/node/pull/54224 process: * (SEMVER-MAJOR) remove `process.assert` (Aviv Keller) https://github.com/nodejs/node/pull/55035 src: * (SEMVER-MAJOR) update NODE_MODULE_VERSION to 131 (Michaël Zasso) https://github.com/nodejs/node/pull/54536 * (SEMVER-MAJOR) stop using deprecated fields of `v8::FastApiCallbackOptions` (Andreas Haas) https://github.com/nodejs/node/pull/54077 * (SEMVER-MAJOR) remove dependency on wrapper-descriptor-based CppHeap (Joyee Cheung) https://github.com/nodejs/node/pull/54077 * (SEMVER-MAJOR) add source location to v8::TaskRunner (François Doray) https://github.com/nodejs/node/pull/54077 * (SEMVER-MAJOR) update NODE_MODULE_VERSION to 129 (Michaël Zasso) https://github.com/nodejs/node/pull/54077 * (SEMVER-MAJOR) do not use soon-to-be-deprecated V8 API (Igor Sheludko) https://github.com/nodejs/node/pull/53174 * (SEMVER-MAJOR) add UV_PIPE_NO_TRUNCATE for bind in pipe_wrap.cc (theanarkh) https://github.com/nodejs/node/pull/52347 stream: * (SEMVER-MAJOR) pipe to a closed or destroyed stream is not allowed in pipeline (jakecastelli) https://github.com/nodejs/node/pull/53241 string_decoder: * (SEMVER-MAJOR) refactor encoding validation (Yagiz Nizipli) https://github.com/nodejs/node/pull/54957 test: * (SEMVER-MAJOR) update v8-stats test for V8 12.6 (Michaël Zasso) https://github.com/nodejs/node/pull/54077 test_runner: * (SEMVER-MAJOR) detect only tests when --test is not used (Colin Ihrig) https://github.com/nodejs/node/pull/54881 * (SEMVER-MAJOR) always make spec the default reporter (Colin Ihrig) https://github.com/nodejs/node/pull/54548 * (SEMVER-MAJOR) expose lcov reporter as newable function (Chemi Atlow) https://github.com/nodejs/node/pull/52403 timers: * (SEMVER-MAJOR) emit warning if delay is negative or NaN (jakecastelli) https://github.com/nodejs/node/pull/46678 tls: * (SEMVER-MAJOR) fix 'ERR_TLS_PSK_SET_IDENTIY_HINT_FAILED' typo (Aviv Keller) https://github.com/nodejs/node/pull/52627 tools: * (SEMVER-MAJOR) add additonal include dirs for V8 on AIX (Abdirahim Musse) https://github.com/nodejs/node/pull/54536 * (SEMVER-MAJOR) update V8 gypfiles for 12.8 (Michaël Zasso) https://github.com/nodejs/node/pull/54077 * (SEMVER-MAJOR) update V8 gypfiles for 12.7 (Richard Lau) https://github.com/nodejs/node/pull/54077 * (SEMVER-MAJOR) update V8 gypfiles for 12.6 (Michaël Zasso) https://github.com/nodejs/node/pull/54077 util: * (SEMVER-MAJOR) move util.log to eol (marco-ippolito) https://github.com/nodejs/node/pull/52744 * (SEMVER-MAJOR) move util.isPrimitive to eol (marco-ippolito) https://github.com/nodejs/node/pull/52744 * (SEMVER-MAJOR) move util.isFunction to eol (marco-ippolito) https://github.com/nodejs/node/pull/52744 * (SEMVER-MAJOR) move util.isError to eol (marco-ippolito) https://github.com/nodejs/node/pull/52744 * (SEMVER-MAJOR) move util.isDate to eol (marco-ippolito) https://github.com/nodejs/node/pull/52744 * (SEMVER-MAJOR) move util.isObject to eol (marco-ippolito) https://github.com/nodejs/node/pull/52744 * (SEMVER-MAJOR) move util.isRegExp to eol (marco-ippolito) https://github.com/nodejs/node/pull/52744 * (SEMVER-MAJOR) move util.isUndefined to eol (marco-ippolito) https://github.com/nodejs/node/pull/52744 * (SEMVER-MAJOR) move util.isSymbol to eol (marco-ippolito) https://github.com/nodejs/node/pull/52744 * (SEMVER-MAJOR) move util.isString to eol (marco-ippolito) https://github.com/nodejs/node/pull/52744 * (SEMVER-MAJOR) move util.isNumber to eol (marco-ippolito) https://github.com/nodejs/node/pull/52744 * (SEMVER-MAJOR) move util.isNullOrUndefined to eol (marco-ippolito) https://github.com/nodejs/node/pull/52744 * (SEMVER-MAJOR) move util.isNull to eol (marco-ippolito) https://github.com/nodejs/node/pull/52744 * (SEMVER-MAJOR) move util.isBuffer to eol (marco-ippolito) https://github.com/nodejs/node/pull/52744 * (SEMVER-MAJOR) move util.isBoolean to eol (marco-ippolito) https://github.com/nodejs/node/pull/52744 * (SEMVER-MAJOR) move util._extend to eol (marco-ippolito) https://github.com/nodejs/node/pull/52744 zlib: * (SEMVER-MAJOR) remove `zlib.bytesRead` (Yagiz Nizipli) https://github.com/nodejs/node/pull/55020 PR-URL: https://github.com/nodejs/node/pull/55338
2024-10-09 14:48:01 -03:00
- version: v23.0.0
pr-url: https://github.com/nodejs/node/pull/54705
description: Added the `cwd` option.
2024-10-16, Version 22.10.0 (Current) Notable changes: crypto: * (SEMVER-MINOR) add `KeyObject.prototype.toCryptoKey` (Filip Skokan) https://github.com/nodejs/node/pull/55262 * (SEMVER-MINOR) add Date fields for `validTo` and `validFrom` (Andrew Moon) https://github.com/nodejs/node/pull/54159 doc: * add abmusse to collaborators (Abdirahim Musse) https://github.com/nodejs/node/pull/55086 http2: * (SEMVER-MINOR) expose `nghttp2_option_set_stream_reset_rate_limit` as an option (Maël Nison) https://github.com/nodejs/node/pull/54875 lib: * (SEMVER-MINOR) propagate aborted state to dependent signals before firing events (jazelly) https://github.com/nodejs/node/pull/54826 module: * (SEMVER-MINOR) support loading entrypoint as url (RedYetiDev) https://github.com/nodejs/node/pull/54933 * (SEMVER-MINOR) implement the `"module-sync"` exports condition (Joyee Cheung) https://github.com/nodejs/node/pull/54648 * (SEMVER-MINOR) implement `flushCompileCache()` (Joyee Cheung) https://github.com/nodejs/node/pull/54971 * (SEMVER-MINOR) throw when invalid argument is passed to `enableCompileCache()` (Joyee Cheung) https://github.com/nodejs/node/pull/54971 * (SEMVER-MINOR) write compile cache to temporary file and then rename it (Joyee Cheung) https://github.com/nodejs/node/pull/54971 process: * (SEMVER-MINOR) add `process.features.require_module` (Joyee Cheung) https://github.com/nodejs/node/pull/55241 * (SEMVER-MINOR) add `process.features.typescript` (Aviv Keller) https://github.com/nodejs/node/pull/54295 src: * mark `node --run` as stable (Yagiz Nizipli) https://github.com/nodejs/node/pull/53763 test_runner: * (SEMVER-MINOR) support custom arguments in `run()` (Aviv Keller) https://github.com/nodejs/node/pull/55126 * (SEMVER-MINOR) add `'test:summary'` event (Colin Ihrig) https://github.com/nodejs/node/pull/54851 * (SEMVER-MINOR) add support for coverage via `run()` (Chemi Atlow) https://github.com/nodejs/node/pull/53937 worker: * (SEMVER-MINOR) add `markAsUncloneable` api (Jason Zhang) https://github.com/nodejs/node/pull/55234 PR-URL: https://github.com/nodejs/node/pull/55343
2024-10-10 00:12:22 +02:00
- version:
- v23.0.0
- v22.10.0
pr-url: https://github.com/nodejs/node/pull/53937
description: Added coverage options.
- version: v22.8.0
pr-url: https://github.com/nodejs/node/pull/53927
description: Added the `isolation` option.
- version: v22.6.0
pr-url: https://github.com/nodejs/node/pull/53866
description: Added the `globPatterns` option.
- version:
- v22.0.0
- v20.14.0
pr-url: https://github.com/nodejs/node/pull/52038
description: Added the `forceExit` option.
2023-07-18, Version 18.17.0 'Hydrogen' (LTS) Notable changes: Ada 2.0 Node.js v18.17.0 comes with the latest version of the URL parser, Ada. This update brings significant performance improvements to URL parsing, including enhancements to the url.domainToASCII and url.domainToUnicode functions in node:url. Ada 2.0 has been integrated into the Node.js codebase, ensuring that all parts of the application can benefit from the improved performance. Additionally, Ada 2.0 features a significant performance boost over its predecessor, Ada 1.0.4, while also eliminating the need for the ICU requirement for URL hostname parsing. Contributed by Yagiz Nizipli and Daniel Lemire in https://github.com/nodejs/node/pull/47339 Web Crypto API Web Crypto API functions' arguments are now coerced and validated as per their WebIDL definitions like in other Web Crypto API implementations. This further improves interoperability with other implementations of Web Crypto API. Contributed by Filip Skokan in https://github.com/nodejs/node/pull/46067 crypto: * update root certificates to NSS 3.89 (Node.js GitHub Bot) https://github.com/nodejs/node/pull/47659 dns: * (SEMVER-MINOR) expose getDefaultResultOrder (btea) https://github.com/nodejs/node/pull/46973 doc: * add ovflowd to collaborators (Claudio Wunder) https://github.com/nodejs/node/pull/47844 * add KhafraDev to collaborators (Matthew Aitken) https://github.com/nodejs/node/pull/47510 * events: * (SEMVER-MINOR) add getMaxListeners method (Matthew Aitken) https://github.com/nodejs/node/pull/47039 fs: * (SEMVER-MINOR) add support for mode flag to specify the copy behavior (Tetsuharu Ohzeki) https://github.com/nodejs/node/pull/47084 * (SEMVER-MINOR) add recursive option to readdir and opendir (Ethan Arrowood) https://github.com/nodejs/node/pull/41439 * (SEMVER-MINOR) add support for mode flag to specify the copy behavior (Tetsuharu Ohzeki) https://github.com/nodejs/node/pull/47084 * (SEMVER-MINOR) implement byob mode for readableWebStream() (Debadree Chatterjee) https://github.com/nodejs/node/pull/46933 http: * (SEMVER-MINOR) prevent writing to the body when not allowed by HTTP spec (Gerrard Lindsay) https://github.com/nodejs/node/pull/47732 * (SEMVER-MINOR) remove internal error in assignSocket (Matteo Collina) https://github.com/nodejs/node/pull/47723 * (SEMVER-MINOR) add highWaterMark opt in http.createServer (HinataKah0) https://github.com/nodejs/node/pull/47405 lib: * (SEMVER-MINOR) add webstreams to Duplex.from() (Debadree Chatterjee) https://github.com/nodejs/node/pull/46190 * (SEMVER-MINOR) implement AbortSignal.any() (Chemi Atlow) https://github.com/nodejs/node/pull/47821 module: * change default resolver to not throw on unknown scheme (Gil Tayar) https://github.com/nodejs/node/pull/47824 node-api: * (SEMVER-MINOR) define version 9 (Chengzhong Wu) https://github.com/nodejs/node/pull/48151 * (SEMVER-MINOR) deprecate napi_module_register (Vladimir Morozov) https://github.com/nodejs/node/pull/46319 stream: * (SEMVER-MINOR) preserve object mode in compose (Raz Luvaton) https://github.com/nodejs/node/pull/47413 * (SEMVER-MINOR) add setter & getter for default highWaterMark (#46929) (Robert Nagy) https://github.com/nodejs/node/pull/46929 test: * unflake test-vm-timeout-escape-nexttick (Santiago Gimeno) https://github.com/nodejs/node/pull/48078 test_runner: * (SEMVER-MINOR) add shorthands to `test` (Chemi Atlow) https://github.com/nodejs/node/pull/47909 * (SEMVER-MINOR) support combining coverage reports (Colin Ihrig) https://github.com/nodejs/node/pull/47686 * (SEMVER-MINOR) execute before hook on test (Chemi Atlow) https://github.com/nodejs/node/pull/47586 * (SEMVER-MINOR) expose reporter for use in run api (Chemi Atlow) https://github.com/nodejs/node/pull/47238 tools: * update LICENSE and license-builder.sh (Santiago Gimeno) https://github.com/nodejs/node/pull/48078 url: * (SEMVER-MINOR) implement URL.canParse (Matthew Aitken) https://github.com/nodejs/node/pull/47179 wasi: * (SEMVER-MINOR) no longer require flag to enable wasi (Michael Dawson) https://github.com/nodejs/node/pull/47286 PR-URL: https://github.com/nodejs/node/pull/48694
2023-07-10 08:12:52 -04:00
- version:
- v20.1.0
- v18.17.0
pr-url: https://github.com/nodejs/node/pull/47628
description: Add a testNamePatterns option.
-->
* `options` {Object} Configuration options for running tests. The following
properties are supported:
* `concurrency` {number|boolean} If a number is provided,
then that many test processes would run in parallel, where each process
corresponds to one test file.
If `true`, it would run `os.availableParallelism() - 1` test files in
parallel.
If `false`, it would only run one test file at a time.
**Default:** `false`.
* `cwd`: {string} Specifies the current working directory to be used by the test runner.
Serves as the base path for resolving files according to the [test runner execution model][].
**Default:** `process.cwd()`.
* `files`: {Array} An array containing the list of files to run.
**Default:** matching files from [test runner execution model][].
* `forceExit`: {boolean} Configures the test runner to exit the process once
all known tests have finished executing even if the event loop would
otherwise remain active. **Default:** `false`.
* `globPatterns`: {Array} An array containing the list of glob patterns to
match test files. This option cannot be used together with `files`.
**Default:** matching files from [test runner execution model][].
* `inspectPort` {number|Function} Sets inspector port of test child process.
This can be a number, or a function that takes no arguments and returns a
number. If a nullish value is provided, each process gets its own port,
incremented from the primary's `process.debugPort`. This option is ignored
if the `isolation` option is set to `'none'` as no child processes are
spawned. **Default:** `undefined`.
* `isolation` {string} Configures the type of test isolation. If set to
`'process'`, each test file is run in a separate child process. If set to
`'none'`, all test files run in the current process. **Default:**
`'process'`.
* `only`: {boolean} If truthy, the test context will only run tests that
have the `only` option set
* `setup` {Function} A function that accepts the `TestsStream` instance
and can be used to setup listeners before any tests are run.
**Default:** `undefined`.
* `execArgv` {Array} An array of CLI flags to pass to the `node` executable when
spawning the subprocesses. This option has no effect when `isolation` is `'none`'.
**Default:** `[]`
* `argv` {Array} An array of CLI flags to pass to each test file when spawning the
subprocesses. This option has no effect when `isolation` is `'none'`.
**Default:** `[]`.
* `signal` {AbortSignal} Allows aborting an in-progress test execution.
* `testNamePatterns` {string|RegExp|Array} A String, RegExp or a RegExp Array,
that can be used to only run tests whose name matches the provided pattern.
Test name patterns are interpreted as JavaScript regular expressions.
For each test that is executed, any corresponding test hooks, such as
`beforeEach()`, are also run.
**Default:** `undefined`.
* `testSkipPatterns` {string|RegExp|Array} A String, RegExp or a RegExp Array,
that can be used to exclude running tests whose name matches the provided pattern.
Test name patterns are interpreted as JavaScript regular expressions.
For each test that is executed, any corresponding test hooks, such as
`beforeEach()`, are also run.
**Default:** `undefined`.
* `timeout` {number} A number of milliseconds the test execution will
fail after.
If unspecified, subtests inherit this value from their parent.
**Default:** `Infinity`.
* `watch` {boolean} Whether to run in watch mode or not. **Default:** `false`.
* `shard` {Object} Running tests in a specific shard. **Default:** `undefined`.
* `index` {number} is a positive integer between 1 and `<total>`
that specifies the index of the shard to run. This option is _required_.
* `total` {number} is a positive integer that specifies the total number
of shards to split the test files to. This option is _required_.
* `coverage` {boolean} enable [code coverage][] collection.
**Default:** `false`.
* `coverageExcludeGlobs` {string|Array} Excludes specific files from code coverage
using a glob pattern, which can match both absolute and relative file paths.
This property is only applicable when `coverage` was set to `true`.
If both `coverageExcludeGlobs` and `coverageIncludeGlobs` are provided,
files must meet **both** criteria to be included in the coverage report.
**Default:** `undefined`.
* `coverageIncludeGlobs` {string|Array} Includes specific files in code coverage
using a glob pattern, which can match both absolute and relative file paths.
This property is only applicable when `coverage` was set to `true`.
If both `coverageExcludeGlobs` and `coverageIncludeGlobs` are provided,
files must meet **both** criteria to be included in the coverage report.
**Default:** `undefined`.
* `lineCoverage` {number} Require a minimum percent of covered lines. If code
coverage does not reach the threshold specified, the process will exit with code `1`.
**Default:** `0`.
* `branchCoverage` {number} Require a minimum percent of covered branches. If code
coverage does not reach the threshold specified, the process will exit with code `1`.
**Default:** `0`.
* `functionCoverage` {number} Require a minimum percent of covered functions. If code
coverage does not reach the threshold specified, the process will exit with code `1`.
**Default:** `0`.
* Returns: {TestsStream}
**Note:** `shard` is used to horizontally parallelize test running across
machines or processes, ideal for large-scale executions across varied
environments. It's incompatible with `watch` mode, tailored for rapid
code iteration by automatically rerunning tests on file changes.
```mjs
import { tap } from 'node:test/reporters';
import { run } from 'node:test';
import process from 'node:process';
import path from 'node:path';
run({ files: [path.resolve('./tests/test.js')] })
.on('test:fail', () => {
process.exitCode = 1;
})
.compose(tap)
.pipe(process.stdout);
```
```cjs
const { tap } = require('node:test/reporters');
const { run } = require('node:test');
const path = require('node:path');
run({ files: [path.resolve('./tests/test.js')] })
.on('test:fail', () => {
process.exitCode = 1;
})
.compose(tap)
.pipe(process.stdout);
```
## `suite([name][, options][, fn])`
<!-- YAML
2024-05-07, Version 20.13.0 'Iron' (LTS) Notable changes: benchmark: * add AbortSignal.abort benchmarks (Raz Luvaton) https://github.com/nodejs/node/pull/52408 buffer: * improve `base64` and `base64url` performance (Yagiz Nizipli) https://github.com/nodejs/node/pull/52428 crypto: * deprecate implicitly shortened GCM tags (Tobias Nießen) https://github.com/nodejs/node/pull/52345 deps: * (SEMVER-MINOR) update simdutf to 5.0.0 (Daniel Lemire) https://github.com/nodejs/node/pull/52138 * (SEMVER-MINOR) update undici to 6.3.0 (Node.js GitHub Bot) https://github.com/nodejs/node/pull/51462 * (SEMVER-MINOR) update undici to 6.2.1 (Node.js GitHub Bot) https://github.com/nodejs/node/pull/51278 dns: * (SEMVER-MINOR) add order option and support ipv6first (Paolo Insogna) https://github.com/nodejs/node/pull/52492 doc: * update release gpg keyserver (marco-ippolito) https://github.com/nodejs/node/pull/52257 * add release key for marco-ippolito (marco-ippolito) https://github.com/nodejs/node/pull/52257 * add UlisesGascon as a collaborator (Ulises Gascón) https://github.com/nodejs/node/pull/51991 * (SEMVER-MINOR) deprecate fs.Stats public constructor (Marco Ippolito) https://github.com/nodejs/node/pull/51879 events,doc: * mark CustomEvent as stable (Daeyeon Jeong) https://github.com/nodejs/node/pull/52618 fs: * add stacktrace to fs/promises (翠 / green) https://github.com/nodejs/node/pull/49849 lib, url: * (SEMVER-MINOR) add a `windows` option to path parsing (Aviv Keller) https://github.com/nodejs/node/pull/52509 net: * (SEMVER-MINOR) add CLI option for autoSelectFamilyAttemptTimeout (Paolo Insogna) https://github.com/nodejs/node/pull/52474 report: * (SEMVER-MINOR) add `--report-exclude-network` option (Ethan Arrowood) https://github.com/nodejs/node/pull/51645 src: * (SEMVER-MINOR) add `string_view` overload to snapshot FromBlob (Anna Henningsen) https://github.com/nodejs/node/pull/52595 * (SEMVER-MINOR) add C++ ProcessEmitWarningSync() (Joyee Cheung) https://github.com/nodejs/node/pull/51977 * (SEMVER-MINOR) add uv_get_available_memory to report and process (theanarkh) https://github.com/nodejs/node/pull/52023 * (SEMVER-MINOR) preload function for Environment (Cheng Zhao) https://github.com/nodejs/node/pull/51539 stream: * (SEMVER-MINOR) support typed arrays (IlyasShabi) https://github.com/nodejs/node/pull/51866 test_runner: * (SEMVER-MINOR) add suite() (Colin Ihrig) https://github.com/nodejs/node/pull/52127 * (SEMVER-MINOR) add `test:complete` event to reflect execution order (Moshe Atlow) https://github.com/nodejs/node/pull/51909 util: * (SEMVER-MINOR) support array of formats in util.styleText (Marco Ippolito) https://github.com/nodejs/node/pull/52040 v8: * (SEMVER-MINOR) implement v8.queryObjects() for memory leak regression testing (Joyee Cheung) https://github.com/nodejs/node/pull/51927 watch: * mark as stable (Moshe Atlow) https://github.com/nodejs/node/pull/52074 PR-URL: https://github.com/nodejs/node/pull/52793
2024-05-02 11:31:36 +02:00
added:
- v22.0.0
- v20.13.0
changes:
- version:
- REPLACEME
pr-url: https://github.com/nodejs/node/pull/56664
description: This function no longer returns a `Promise`.
-->
* `name` {string} The name of the suite, which is displayed when reporting test
results. **Default:** The `name` property of `fn`, or `'<anonymous>'` if `fn`
does not have a name.
* `options` {Object} Optional configuration options for the suite.
This supports the same options as `test([name][, options][, fn])`.
* `fn` {Function|AsyncFunction} The suite function declaring nested tests and
suites. The first argument to this function is a [`SuiteContext`][] object.
**Default:** A no-op function.
The `suite()` function is imported from the `node:test` module.
## `suite.skip([name][, options][, fn])`
<!-- YAML
2024-05-07, Version 20.13.0 'Iron' (LTS) Notable changes: benchmark: * add AbortSignal.abort benchmarks (Raz Luvaton) https://github.com/nodejs/node/pull/52408 buffer: * improve `base64` and `base64url` performance (Yagiz Nizipli) https://github.com/nodejs/node/pull/52428 crypto: * deprecate implicitly shortened GCM tags (Tobias Nießen) https://github.com/nodejs/node/pull/52345 deps: * (SEMVER-MINOR) update simdutf to 5.0.0 (Daniel Lemire) https://github.com/nodejs/node/pull/52138 * (SEMVER-MINOR) update undici to 6.3.0 (Node.js GitHub Bot) https://github.com/nodejs/node/pull/51462 * (SEMVER-MINOR) update undici to 6.2.1 (Node.js GitHub Bot) https://github.com/nodejs/node/pull/51278 dns: * (SEMVER-MINOR) add order option and support ipv6first (Paolo Insogna) https://github.com/nodejs/node/pull/52492 doc: * update release gpg keyserver (marco-ippolito) https://github.com/nodejs/node/pull/52257 * add release key for marco-ippolito (marco-ippolito) https://github.com/nodejs/node/pull/52257 * add UlisesGascon as a collaborator (Ulises Gascón) https://github.com/nodejs/node/pull/51991 * (SEMVER-MINOR) deprecate fs.Stats public constructor (Marco Ippolito) https://github.com/nodejs/node/pull/51879 events,doc: * mark CustomEvent as stable (Daeyeon Jeong) https://github.com/nodejs/node/pull/52618 fs: * add stacktrace to fs/promises (翠 / green) https://github.com/nodejs/node/pull/49849 lib, url: * (SEMVER-MINOR) add a `windows` option to path parsing (Aviv Keller) https://github.com/nodejs/node/pull/52509 net: * (SEMVER-MINOR) add CLI option for autoSelectFamilyAttemptTimeout (Paolo Insogna) https://github.com/nodejs/node/pull/52474 report: * (SEMVER-MINOR) add `--report-exclude-network` option (Ethan Arrowood) https://github.com/nodejs/node/pull/51645 src: * (SEMVER-MINOR) add `string_view` overload to snapshot FromBlob (Anna Henningsen) https://github.com/nodejs/node/pull/52595 * (SEMVER-MINOR) add C++ ProcessEmitWarningSync() (Joyee Cheung) https://github.com/nodejs/node/pull/51977 * (SEMVER-MINOR) add uv_get_available_memory to report and process (theanarkh) https://github.com/nodejs/node/pull/52023 * (SEMVER-MINOR) preload function for Environment (Cheng Zhao) https://github.com/nodejs/node/pull/51539 stream: * (SEMVER-MINOR) support typed arrays (IlyasShabi) https://github.com/nodejs/node/pull/51866 test_runner: * (SEMVER-MINOR) add suite() (Colin Ihrig) https://github.com/nodejs/node/pull/52127 * (SEMVER-MINOR) add `test:complete` event to reflect execution order (Moshe Atlow) https://github.com/nodejs/node/pull/51909 util: * (SEMVER-MINOR) support array of formats in util.styleText (Marco Ippolito) https://github.com/nodejs/node/pull/52040 v8: * (SEMVER-MINOR) implement v8.queryObjects() for memory leak regression testing (Joyee Cheung) https://github.com/nodejs/node/pull/51927 watch: * mark as stable (Moshe Atlow) https://github.com/nodejs/node/pull/52074 PR-URL: https://github.com/nodejs/node/pull/52793
2024-05-02 11:31:36 +02:00
added:
- v22.0.0
- v20.13.0
-->
Shorthand for skipping a suite. This is the same as
[`suite([name], { skip: true }[, fn])`][suite options].
## `suite.todo([name][, options][, fn])`
<!-- YAML
2024-05-07, Version 20.13.0 'Iron' (LTS) Notable changes: benchmark: * add AbortSignal.abort benchmarks (Raz Luvaton) https://github.com/nodejs/node/pull/52408 buffer: * improve `base64` and `base64url` performance (Yagiz Nizipli) https://github.com/nodejs/node/pull/52428 crypto: * deprecate implicitly shortened GCM tags (Tobias Nießen) https://github.com/nodejs/node/pull/52345 deps: * (SEMVER-MINOR) update simdutf to 5.0.0 (Daniel Lemire) https://github.com/nodejs/node/pull/52138 * (SEMVER-MINOR) update undici to 6.3.0 (Node.js GitHub Bot) https://github.com/nodejs/node/pull/51462 * (SEMVER-MINOR) update undici to 6.2.1 (Node.js GitHub Bot) https://github.com/nodejs/node/pull/51278 dns: * (SEMVER-MINOR) add order option and support ipv6first (Paolo Insogna) https://github.com/nodejs/node/pull/52492 doc: * update release gpg keyserver (marco-ippolito) https://github.com/nodejs/node/pull/52257 * add release key for marco-ippolito (marco-ippolito) https://github.com/nodejs/node/pull/52257 * add UlisesGascon as a collaborator (Ulises Gascón) https://github.com/nodejs/node/pull/51991 * (SEMVER-MINOR) deprecate fs.Stats public constructor (Marco Ippolito) https://github.com/nodejs/node/pull/51879 events,doc: * mark CustomEvent as stable (Daeyeon Jeong) https://github.com/nodejs/node/pull/52618 fs: * add stacktrace to fs/promises (翠 / green) https://github.com/nodejs/node/pull/49849 lib, url: * (SEMVER-MINOR) add a `windows` option to path parsing (Aviv Keller) https://github.com/nodejs/node/pull/52509 net: * (SEMVER-MINOR) add CLI option for autoSelectFamilyAttemptTimeout (Paolo Insogna) https://github.com/nodejs/node/pull/52474 report: * (SEMVER-MINOR) add `--report-exclude-network` option (Ethan Arrowood) https://github.com/nodejs/node/pull/51645 src: * (SEMVER-MINOR) add `string_view` overload to snapshot FromBlob (Anna Henningsen) https://github.com/nodejs/node/pull/52595 * (SEMVER-MINOR) add C++ ProcessEmitWarningSync() (Joyee Cheung) https://github.com/nodejs/node/pull/51977 * (SEMVER-MINOR) add uv_get_available_memory to report and process (theanarkh) https://github.com/nodejs/node/pull/52023 * (SEMVER-MINOR) preload function for Environment (Cheng Zhao) https://github.com/nodejs/node/pull/51539 stream: * (SEMVER-MINOR) support typed arrays (IlyasShabi) https://github.com/nodejs/node/pull/51866 test_runner: * (SEMVER-MINOR) add suite() (Colin Ihrig) https://github.com/nodejs/node/pull/52127 * (SEMVER-MINOR) add `test:complete` event to reflect execution order (Moshe Atlow) https://github.com/nodejs/node/pull/51909 util: * (SEMVER-MINOR) support array of formats in util.styleText (Marco Ippolito) https://github.com/nodejs/node/pull/52040 v8: * (SEMVER-MINOR) implement v8.queryObjects() for memory leak regression testing (Joyee Cheung) https://github.com/nodejs/node/pull/51927 watch: * mark as stable (Moshe Atlow) https://github.com/nodejs/node/pull/52074 PR-URL: https://github.com/nodejs/node/pull/52793
2024-05-02 11:31:36 +02:00
added:
- v22.0.0
- v20.13.0
-->
Shorthand for marking a suite as `TODO`. This is the same as
[`suite([name], { todo: true }[, fn])`][suite options].
## `suite.only([name][, options][, fn])`
<!-- YAML
2024-05-07, Version 20.13.0 'Iron' (LTS) Notable changes: benchmark: * add AbortSignal.abort benchmarks (Raz Luvaton) https://github.com/nodejs/node/pull/52408 buffer: * improve `base64` and `base64url` performance (Yagiz Nizipli) https://github.com/nodejs/node/pull/52428 crypto: * deprecate implicitly shortened GCM tags (Tobias Nießen) https://github.com/nodejs/node/pull/52345 deps: * (SEMVER-MINOR) update simdutf to 5.0.0 (Daniel Lemire) https://github.com/nodejs/node/pull/52138 * (SEMVER-MINOR) update undici to 6.3.0 (Node.js GitHub Bot) https://github.com/nodejs/node/pull/51462 * (SEMVER-MINOR) update undici to 6.2.1 (Node.js GitHub Bot) https://github.com/nodejs/node/pull/51278 dns: * (SEMVER-MINOR) add order option and support ipv6first (Paolo Insogna) https://github.com/nodejs/node/pull/52492 doc: * update release gpg keyserver (marco-ippolito) https://github.com/nodejs/node/pull/52257 * add release key for marco-ippolito (marco-ippolito) https://github.com/nodejs/node/pull/52257 * add UlisesGascon as a collaborator (Ulises Gascón) https://github.com/nodejs/node/pull/51991 * (SEMVER-MINOR) deprecate fs.Stats public constructor (Marco Ippolito) https://github.com/nodejs/node/pull/51879 events,doc: * mark CustomEvent as stable (Daeyeon Jeong) https://github.com/nodejs/node/pull/52618 fs: * add stacktrace to fs/promises (翠 / green) https://github.com/nodejs/node/pull/49849 lib, url: * (SEMVER-MINOR) add a `windows` option to path parsing (Aviv Keller) https://github.com/nodejs/node/pull/52509 net: * (SEMVER-MINOR) add CLI option for autoSelectFamilyAttemptTimeout (Paolo Insogna) https://github.com/nodejs/node/pull/52474 report: * (SEMVER-MINOR) add `--report-exclude-network` option (Ethan Arrowood) https://github.com/nodejs/node/pull/51645 src: * (SEMVER-MINOR) add `string_view` overload to snapshot FromBlob (Anna Henningsen) https://github.com/nodejs/node/pull/52595 * (SEMVER-MINOR) add C++ ProcessEmitWarningSync() (Joyee Cheung) https://github.com/nodejs/node/pull/51977 * (SEMVER-MINOR) add uv_get_available_memory to report and process (theanarkh) https://github.com/nodejs/node/pull/52023 * (SEMVER-MINOR) preload function for Environment (Cheng Zhao) https://github.com/nodejs/node/pull/51539 stream: * (SEMVER-MINOR) support typed arrays (IlyasShabi) https://github.com/nodejs/node/pull/51866 test_runner: * (SEMVER-MINOR) add suite() (Colin Ihrig) https://github.com/nodejs/node/pull/52127 * (SEMVER-MINOR) add `test:complete` event to reflect execution order (Moshe Atlow) https://github.com/nodejs/node/pull/51909 util: * (SEMVER-MINOR) support array of formats in util.styleText (Marco Ippolito) https://github.com/nodejs/node/pull/52040 v8: * (SEMVER-MINOR) implement v8.queryObjects() for memory leak regression testing (Joyee Cheung) https://github.com/nodejs/node/pull/51927 watch: * mark as stable (Moshe Atlow) https://github.com/nodejs/node/pull/52074 PR-URL: https://github.com/nodejs/node/pull/52793
2024-05-02 11:31:36 +02:00
added:
- v22.0.0
- v20.13.0
-->
Shorthand for marking a suite as `only`. This is the same as
[`suite([name], { only: true }[, fn])`][suite options].
## `test([name][, options][, fn])`
<!-- YAML
2022-08-16, Version 16.17.0 'Gallium' (LTS) Notable changes: Adds `util.parseArgs` helper for higher level command-line argument parsing. Contributed by Benjamin Coe, John Gee, Darcy Clarke, Joe Sepi, Kevin Gibbons, Aaron Casanova, Jessica Nahulan, and Jordan Harband. https://github.com/nodejs/node/pull/42675 Node.js ESM Loader hooks now support multiple custom loaders, and composition is achieved via "chaining": `foo-loader` calls `bar-loader` calls `qux-loader` (a custom loader _must_ now signal a short circuit when intentionally not calling the next). See the ESM docs (https://nodejs.org/dist/latest-v16.x/docs/api/esm.html) for details. Contributed by Jacob Smith, Geoffrey Booth, and Bradley Farias. https://github.com/nodejs/node/pull/42623 The `node:test` module, which was initially introduced in Node.js v18.0.0, is now available with all the changes done to it up to Node.js v18.7.0. To better align Node.js' experimental implementation of the Web Crypto API with other runtimes, several changes were made: * Support for CFRG curves was added, with the `'Ed25519'`, `'Ed448'`, `'X25519'`, and `'X448'` algorithms. * The proprietary `'NODE-DSA'`, `'NODE-DH'`, `'NODE-SCRYPT'`, `'NODE-ED25519'`, `'NODE-ED448'`, `'NODE-X25519'`, and `'NODE-X448'` algorithms were removed. * The proprietary `'node.keyObject'` import/export format was removed. Contributed by Filip Skokan. https://github.com/nodejs/node/pull/42507 https://github.com/nodejs/node/pull/43310 Updated Corepack to 0.12.1 - https://github.com/nodejs/node/pull/43965 Updated ICU to 71.1 - https://github.com/nodejs/node/pull/42655 Updated npm to 8.15.0 - https://github.com/nodejs/node/pull/43917 Updated Undici to 5.8.0 - https://github.com/nodejs/node/pull/43886 (SEMVER-MINOR) crypto: make authTagLength optional for CC20P1305 (Tobias Nießen) https://github.com/nodejs/node/pull/42427 (SEMVER-MINOR) crypto: align webcrypto RSA key import/export with other implementations (Filip Skokan) https://github.com/nodejs/node/pull/42816 (SEMVER-MINOR) dns: export error code constants from `dns/promises` (Feng Yu) https://github.com/nodejs/node/pull/43176 doc: deprecate coercion to integer in process.exit (Daeyeon Jeong) https://github.com/nodejs/node/pull/43738 (SEMVER-MINOR) doc: deprecate diagnostics_channel object subscribe method (Stephen Belanger) https://github.com/nodejs/node/pull/42714 (SEMVER-MINOR) errors: add support for cause in aborterror (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) events: expose CustomEvent on global with CLI flag (Daeyeon Jeong) https://github.com/nodejs/node/pull/43885 (SEMVER-MINOR) events: add `CustomEvent` (Daeyeon Jeong) https://github.com/nodejs/node/pull/43514 (SEMVER-MINOR) events: propagate abortsignal reason in new AbortError ctor in events (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) fs: propagate abortsignal reason in new AbortSignal constructors (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) fs: make params in writing methods optional (LiviaMedeiros) https://github.com/nodejs/node/pull/42601 (SEMVER-MINOR) fs: add `read(buffer[, options])` versions (LiviaMedeiros) https://github.com/nodejs/node/pull/42768 (SEMVER-MINOR) http: add drop request event for http server (theanarkh) https://github.com/nodejs/node/pull/43806 (SEMVER-MINOR) http: add diagnostics channel for http client (theanarkh) https://github.com/nodejs/node/pull/43580 (SEMVER-MINOR) http: add perf_hooks detail for http request and client (theanarkh) https://github.com/nodejs/node/pull/43361 (SEMVER-MINOR) http: add uniqueHeaders option to request and createServer (Paolo Insogna) https://github.com/nodejs/node/pull/41397 (SEMVER-MINOR) http2: propagate abortsignal reason in new AbortError constructor (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) http2: compat support for array headers (OneNail) https://github.com/nodejs/node/pull/42901 (SEMVER-MINOR) lib: propagate abortsignal reason in new AbortError constructor in blob (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) lib: add abortSignal.throwIfAborted() (James M Snell) https://github.com/nodejs/node/pull/40951 (SEMVER-MINOR) lib: improved diagnostics_channel subscribe/unsubscribe (Stephen Belanger) https://github.com/nodejs/node/pull/42714 (SEMVER-MINOR) module: add isBuiltIn method (hemanth.hm) https://github.com/nodejs/node/pull/43396 (SEMVER-MINOR) module,repl: support 'node:'-only core modules (Colin Ihrig) https://github.com/nodejs/node/pull/42325 (SEMVER-MINOR) net: add drop event for net server (theanarkh) https://github.com/nodejs/node/pull/43582 (SEMVER-MINOR) net: add ability to reset a tcp socket (pupilTong) https://github.com/nodejs/node/pull/43112 (SEMVER-MINOR) node-api: emit uncaught-exception on unhandled tsfn callbacks (Chengzhong Wu) https://github.com/nodejs/node/pull/36510 (SEMVER-MINOR) perf_hooks: add PerformanceResourceTiming (RafaelGSS) https://github.com/nodejs/node/pull/42725 (SEMVER-MINOR) report: add more heap infos in process report (theanarkh) https://github.com/nodejs/node/pull/43116 (SEMVER-MINOR) src: add --openssl-legacy-provider option (Daniel Bevenius) https://github.com/nodejs/node/pull/40478 (SEMVER-MINOR) src: define fs.constants.S_IWUSR & S_IRUSR for Win (Liviu Ionescu) https://github.com/nodejs/node/pull/42757 (SEMVER-MINOR) src,doc,test: add --openssl-shared-config option (Daniel Bevenius) https://github.com/nodejs/node/pull/43124 (SEMVER-MINOR) stream: use cause options in AbortError constructors (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) stream: add iterator helper find (Nitzan Uziely) https://github.com/nodejs/node/pull/41849 (SEMVER-MINOR) stream: add writableAborted (Robert Nagy) https://github.com/nodejs/node/pull/40802 (SEMVER-MINOR) timers: propagate signal.reason in awaitable timers (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) v8: add v8.startupSnapshot utils (Joyee Cheung) https://github.com/nodejs/node/pull/43329 (SEMVER-MINOR) v8: export more fields in getHeapStatistics (theanarkh) https://github.com/nodejs/node/pull/42784 (SEMVER-MINOR) worker: add hasRef() to MessagePort (Darshan Sen) https://github.com/nodejs/node/pull/42849 PR-URL: https://github.com/nodejs/node/pull/44098
2022-08-02 14:34:18 +02:00
added:
- v18.0.0
- v16.17.0
changes:
- version:
- REPLACEME
pr-url: https://github.com/nodejs/node/pull/56664
description: This function no longer returns a `Promise`.
2023-07-18, Version 18.17.0 'Hydrogen' (LTS) Notable changes: Ada 2.0 Node.js v18.17.0 comes with the latest version of the URL parser, Ada. This update brings significant performance improvements to URL parsing, including enhancements to the url.domainToASCII and url.domainToUnicode functions in node:url. Ada 2.0 has been integrated into the Node.js codebase, ensuring that all parts of the application can benefit from the improved performance. Additionally, Ada 2.0 features a significant performance boost over its predecessor, Ada 1.0.4, while also eliminating the need for the ICU requirement for URL hostname parsing. Contributed by Yagiz Nizipli and Daniel Lemire in https://github.com/nodejs/node/pull/47339 Web Crypto API Web Crypto API functions' arguments are now coerced and validated as per their WebIDL definitions like in other Web Crypto API implementations. This further improves interoperability with other implementations of Web Crypto API. Contributed by Filip Skokan in https://github.com/nodejs/node/pull/46067 crypto: * update root certificates to NSS 3.89 (Node.js GitHub Bot) https://github.com/nodejs/node/pull/47659 dns: * (SEMVER-MINOR) expose getDefaultResultOrder (btea) https://github.com/nodejs/node/pull/46973 doc: * add ovflowd to collaborators (Claudio Wunder) https://github.com/nodejs/node/pull/47844 * add KhafraDev to collaborators (Matthew Aitken) https://github.com/nodejs/node/pull/47510 * events: * (SEMVER-MINOR) add getMaxListeners method (Matthew Aitken) https://github.com/nodejs/node/pull/47039 fs: * (SEMVER-MINOR) add support for mode flag to specify the copy behavior (Tetsuharu Ohzeki) https://github.com/nodejs/node/pull/47084 * (SEMVER-MINOR) add recursive option to readdir and opendir (Ethan Arrowood) https://github.com/nodejs/node/pull/41439 * (SEMVER-MINOR) add support for mode flag to specify the copy behavior (Tetsuharu Ohzeki) https://github.com/nodejs/node/pull/47084 * (SEMVER-MINOR) implement byob mode for readableWebStream() (Debadree Chatterjee) https://github.com/nodejs/node/pull/46933 http: * (SEMVER-MINOR) prevent writing to the body when not allowed by HTTP spec (Gerrard Lindsay) https://github.com/nodejs/node/pull/47732 * (SEMVER-MINOR) remove internal error in assignSocket (Matteo Collina) https://github.com/nodejs/node/pull/47723 * (SEMVER-MINOR) add highWaterMark opt in http.createServer (HinataKah0) https://github.com/nodejs/node/pull/47405 lib: * (SEMVER-MINOR) add webstreams to Duplex.from() (Debadree Chatterjee) https://github.com/nodejs/node/pull/46190 * (SEMVER-MINOR) implement AbortSignal.any() (Chemi Atlow) https://github.com/nodejs/node/pull/47821 module: * change default resolver to not throw on unknown scheme (Gil Tayar) https://github.com/nodejs/node/pull/47824 node-api: * (SEMVER-MINOR) define version 9 (Chengzhong Wu) https://github.com/nodejs/node/pull/48151 * (SEMVER-MINOR) deprecate napi_module_register (Vladimir Morozov) https://github.com/nodejs/node/pull/46319 stream: * (SEMVER-MINOR) preserve object mode in compose (Raz Luvaton) https://github.com/nodejs/node/pull/47413 * (SEMVER-MINOR) add setter & getter for default highWaterMark (#46929) (Robert Nagy) https://github.com/nodejs/node/pull/46929 test: * unflake test-vm-timeout-escape-nexttick (Santiago Gimeno) https://github.com/nodejs/node/pull/48078 test_runner: * (SEMVER-MINOR) add shorthands to `test` (Chemi Atlow) https://github.com/nodejs/node/pull/47909 * (SEMVER-MINOR) support combining coverage reports (Colin Ihrig) https://github.com/nodejs/node/pull/47686 * (SEMVER-MINOR) execute before hook on test (Chemi Atlow) https://github.com/nodejs/node/pull/47586 * (SEMVER-MINOR) expose reporter for use in run api (Chemi Atlow) https://github.com/nodejs/node/pull/47238 tools: * update LICENSE and license-builder.sh (Santiago Gimeno) https://github.com/nodejs/node/pull/48078 url: * (SEMVER-MINOR) implement URL.canParse (Matthew Aitken) https://github.com/nodejs/node/pull/47179 wasi: * (SEMVER-MINOR) no longer require flag to enable wasi (Michael Dawson) https://github.com/nodejs/node/pull/47286 PR-URL: https://github.com/nodejs/node/pull/48694
2023-07-10 08:12:52 -04:00
- version:
- v20.2.0
- v18.17.0
pr-url: https://github.com/nodejs/node/pull/47909
description: Added the `skip`, `todo`, and `only` shorthands.
2022-10-12, Version 16.18.0 'Gallium' (LTS) Notable changes: assert: add `getCalls` and `reset` to callTracker (Moshe Atlow) https://github.com/nodejs/node/pull/44191 crypto: allow zero-length secret KeyObject (Filip Skokan) https://github.com/nodejs/node/pull/44201 crypto: allow zero-length IKM in HKDF and in webcrypto PBKDF2 (Filip Skokan) https://github.com/nodejs/node/pull/44201 doc: deprecate modp1, modp2, and modp5 groups (Tobias Nießen) https://github.com/nodejs/node/pull/44588 http: make idle http parser count configurable (theanarkh) https://github.com/nodejs/node/pull/43974 http: throw error on content-length mismatch (sidwebworks) https://github.com/nodejs/node/pull/44378 lib: add diagnostics channel for process and worker (theanarkh) https://github.com/nodejs/node/pull/44045 net,tls: pass a valid socket on `tlsClientError` (Daeyeon Jeong) https://github.com/nodejs/node/pull/44021 net: add local family (theanarkh) https://github.com/nodejs/node/pull/43975 report: expose report public native apis (Chengzhong Wu) https://github.com/nodejs/node/pull/44255 src: expose environment RequestInterrupt api (Chengzhong Wu) https://github.com/nodejs/node/pull/44362 stream: add `ReadableByteStream.tee()` (Daeyeon Jeong) https://github.com/nodejs/node/pull/44505 test_runner: add before/after/each hooks (Moshe Atlow) https://github.com/nodejs/node/pull/43730 util: add `maxArrayLength` option to Set and Map (Kohei Ueno) https://github.com/nodejs/node/pull/43576 PR-URL: https://github.com/nodejs/node/pull/44886
2022-10-11 14:54:19 -05:00
- version:
- v18.8.0
- v16.18.0
pr-url: https://github.com/nodejs/node/pull/43554
description: Add a `signal` option.
2022-08-16, Version 16.17.0 'Gallium' (LTS) Notable changes: Adds `util.parseArgs` helper for higher level command-line argument parsing. Contributed by Benjamin Coe, John Gee, Darcy Clarke, Joe Sepi, Kevin Gibbons, Aaron Casanova, Jessica Nahulan, and Jordan Harband. https://github.com/nodejs/node/pull/42675 Node.js ESM Loader hooks now support multiple custom loaders, and composition is achieved via "chaining": `foo-loader` calls `bar-loader` calls `qux-loader` (a custom loader _must_ now signal a short circuit when intentionally not calling the next). See the ESM docs (https://nodejs.org/dist/latest-v16.x/docs/api/esm.html) for details. Contributed by Jacob Smith, Geoffrey Booth, and Bradley Farias. https://github.com/nodejs/node/pull/42623 The `node:test` module, which was initially introduced in Node.js v18.0.0, is now available with all the changes done to it up to Node.js v18.7.0. To better align Node.js' experimental implementation of the Web Crypto API with other runtimes, several changes were made: * Support for CFRG curves was added, with the `'Ed25519'`, `'Ed448'`, `'X25519'`, and `'X448'` algorithms. * The proprietary `'NODE-DSA'`, `'NODE-DH'`, `'NODE-SCRYPT'`, `'NODE-ED25519'`, `'NODE-ED448'`, `'NODE-X25519'`, and `'NODE-X448'` algorithms were removed. * The proprietary `'node.keyObject'` import/export format was removed. Contributed by Filip Skokan. https://github.com/nodejs/node/pull/42507 https://github.com/nodejs/node/pull/43310 Updated Corepack to 0.12.1 - https://github.com/nodejs/node/pull/43965 Updated ICU to 71.1 - https://github.com/nodejs/node/pull/42655 Updated npm to 8.15.0 - https://github.com/nodejs/node/pull/43917 Updated Undici to 5.8.0 - https://github.com/nodejs/node/pull/43886 (SEMVER-MINOR) crypto: make authTagLength optional for CC20P1305 (Tobias Nießen) https://github.com/nodejs/node/pull/42427 (SEMVER-MINOR) crypto: align webcrypto RSA key import/export with other implementations (Filip Skokan) https://github.com/nodejs/node/pull/42816 (SEMVER-MINOR) dns: export error code constants from `dns/promises` (Feng Yu) https://github.com/nodejs/node/pull/43176 doc: deprecate coercion to integer in process.exit (Daeyeon Jeong) https://github.com/nodejs/node/pull/43738 (SEMVER-MINOR) doc: deprecate diagnostics_channel object subscribe method (Stephen Belanger) https://github.com/nodejs/node/pull/42714 (SEMVER-MINOR) errors: add support for cause in aborterror (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) events: expose CustomEvent on global with CLI flag (Daeyeon Jeong) https://github.com/nodejs/node/pull/43885 (SEMVER-MINOR) events: add `CustomEvent` (Daeyeon Jeong) https://github.com/nodejs/node/pull/43514 (SEMVER-MINOR) events: propagate abortsignal reason in new AbortError ctor in events (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) fs: propagate abortsignal reason in new AbortSignal constructors (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) fs: make params in writing methods optional (LiviaMedeiros) https://github.com/nodejs/node/pull/42601 (SEMVER-MINOR) fs: add `read(buffer[, options])` versions (LiviaMedeiros) https://github.com/nodejs/node/pull/42768 (SEMVER-MINOR) http: add drop request event for http server (theanarkh) https://github.com/nodejs/node/pull/43806 (SEMVER-MINOR) http: add diagnostics channel for http client (theanarkh) https://github.com/nodejs/node/pull/43580 (SEMVER-MINOR) http: add perf_hooks detail for http request and client (theanarkh) https://github.com/nodejs/node/pull/43361 (SEMVER-MINOR) http: add uniqueHeaders option to request and createServer (Paolo Insogna) https://github.com/nodejs/node/pull/41397 (SEMVER-MINOR) http2: propagate abortsignal reason in new AbortError constructor (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) http2: compat support for array headers (OneNail) https://github.com/nodejs/node/pull/42901 (SEMVER-MINOR) lib: propagate abortsignal reason in new AbortError constructor in blob (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) lib: add abortSignal.throwIfAborted() (James M Snell) https://github.com/nodejs/node/pull/40951 (SEMVER-MINOR) lib: improved diagnostics_channel subscribe/unsubscribe (Stephen Belanger) https://github.com/nodejs/node/pull/42714 (SEMVER-MINOR) module: add isBuiltIn method (hemanth.hm) https://github.com/nodejs/node/pull/43396 (SEMVER-MINOR) module,repl: support 'node:'-only core modules (Colin Ihrig) https://github.com/nodejs/node/pull/42325 (SEMVER-MINOR) net: add drop event for net server (theanarkh) https://github.com/nodejs/node/pull/43582 (SEMVER-MINOR) net: add ability to reset a tcp socket (pupilTong) https://github.com/nodejs/node/pull/43112 (SEMVER-MINOR) node-api: emit uncaught-exception on unhandled tsfn callbacks (Chengzhong Wu) https://github.com/nodejs/node/pull/36510 (SEMVER-MINOR) perf_hooks: add PerformanceResourceTiming (RafaelGSS) https://github.com/nodejs/node/pull/42725 (SEMVER-MINOR) report: add more heap infos in process report (theanarkh) https://github.com/nodejs/node/pull/43116 (SEMVER-MINOR) src: add --openssl-legacy-provider option (Daniel Bevenius) https://github.com/nodejs/node/pull/40478 (SEMVER-MINOR) src: define fs.constants.S_IWUSR & S_IRUSR for Win (Liviu Ionescu) https://github.com/nodejs/node/pull/42757 (SEMVER-MINOR) src,doc,test: add --openssl-shared-config option (Daniel Bevenius) https://github.com/nodejs/node/pull/43124 (SEMVER-MINOR) stream: use cause options in AbortError constructors (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) stream: add iterator helper find (Nitzan Uziely) https://github.com/nodejs/node/pull/41849 (SEMVER-MINOR) stream: add writableAborted (Robert Nagy) https://github.com/nodejs/node/pull/40802 (SEMVER-MINOR) timers: propagate signal.reason in awaitable timers (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) v8: add v8.startupSnapshot utils (Joyee Cheung) https://github.com/nodejs/node/pull/43329 (SEMVER-MINOR) v8: export more fields in getHeapStatistics (theanarkh) https://github.com/nodejs/node/pull/42784 (SEMVER-MINOR) worker: add hasRef() to MessagePort (Darshan Sen) https://github.com/nodejs/node/pull/42849 PR-URL: https://github.com/nodejs/node/pull/44098
2022-08-02 14:34:18 +02:00
- version:
- v18.7.0
- v16.17.0
pr-url: https://github.com/nodejs/node/pull/43505
description: Add a `timeout` option.
-->
* `name` {string} The name of the test, which is displayed when reporting test
results. **Default:** The `name` property of `fn`, or `'<anonymous>'` if `fn`
does not have a name.
* `options` {Object} Configuration options for the test. The following
properties are supported:
* `concurrency` {number|boolean} If a number is provided,
then that many tests would run in parallel within the application thread.
If `true`, all scheduled asynchronous tests run concurrently within the
thread. If `false`, only one test runs at a time.
If unspecified, subtests inherit this value from their parent.
**Default:** `false`.
* `only` {boolean} If truthy, and the test context is configured to run
`only` tests, then this test will be run. Otherwise, the test is skipped.
**Default:** `false`.
* `signal` {AbortSignal} Allows aborting an in-progress test.
* `skip` {boolean|string} If truthy, the test is skipped. If a string is
provided, that string is displayed in the test results as the reason for
skipping the test. **Default:** `false`.
* `todo` {boolean|string} If truthy, the test marked as `TODO`. If a string
is provided, that string is displayed in the test results as the reason why
the test is `TODO`. **Default:** `false`.
* `timeout` {number} A number of milliseconds the test will fail after.
If unspecified, subtests inherit this value from their parent.
**Default:** `Infinity`.
* `plan` {number} The number of assertions and subtests expected to be run in the test.
If the number of assertions run in the test does not match the number
specified in the plan, the test will fail.
**Default:** `undefined`.
* `fn` {Function|AsyncFunction} The function under test. The first argument
to this function is a [`TestContext`][] object. If the test uses callbacks,
the callback function is passed as the second argument. **Default:** A no-op
function.
The `test()` function is the value imported from the `test` module. Each
invocation of this function results in reporting the test to the {TestsStream}.
The `TestContext` object passed to the `fn` argument can be used to perform
actions related to the current test. Examples include skipping the test, adding
additional diagnostic information, or creating subtests.
The `timeout` option can be used to fail the test if it takes longer than
`timeout` milliseconds to complete. However, it is not a reliable mechanism for
canceling tests because a running test might block the application thread and
thus prevent the scheduled cancellation.
## `test.skip([name][, options][, fn])`
Shorthand for skipping a test,
same as [`test([name], { skip: true }[, fn])`][it options].
## `test.todo([name][, options][, fn])`
Shorthand for marking a test as `TODO`,
same as [`test([name], { todo: true }[, fn])`][it options].
## `test.only([name][, options][, fn])`
Shorthand for marking a test as `only`,
same as [`test([name], { only: true }[, fn])`][it options].
## `describe([name][, options][, fn])`
Alias for [`suite()`][].
The `describe()` function is imported from the `node:test` module.
## `describe.skip([name][, options][, fn])`
Shorthand for skipping a suite. This is the same as
[`describe([name], { skip: true }[, fn])`][describe options].
## `describe.todo([name][, options][, fn])`
Shorthand for marking a suite as `TODO`. This is the same as
[`describe([name], { todo: true }[, fn])`][describe options].
## `describe.only([name][, options][, fn])`
<!-- YAML
added:
- v19.8.0
- v18.15.0
-->
Shorthand for marking a suite as `only`. This is the same as
[`describe([name], { only: true }[, fn])`][describe options].
## `it([name][, options][, fn])`
<!-- YAML
added:
- v18.6.0
- v16.17.0
changes:
2023-04-12, Version 18.16.0 'Hydrogen' (LTS) Notable changes: Add initial support for single executable applications Compile a JavaScript file into a single executable application: ```console $ echo 'console.log(`Hello, ${process.argv[2]}!`);' > hello.js $ cp $(command -v node) hello $ npx postject hello NODE_JS_CODE hello.js \ --sentinel-fuse NODE_JS_FUSE_fce680ab2cc467b6e072b8b5df1996b2 $ npx postject hello NODE_JS_CODE hello.js \ --sentinel-fuse NODE_JS_FUSE_fce680ab2cc467b6e072b8b5df1996b2 \ --macho-segment-name NODE_JS $ ./hello world Hello, world! ``` Contributed by Darshan Sen in https://github.com/nodejs/node/pull/45038 Replace url parser with Ada Node.js gets a new URL parser called Ada that is compliant with the WHATWG URL Specification and provides more than 100% performance improvement to the existing implementation. Contributed by Yagiz Nizipli in https://github.com/nodejs/node/pull/46410 Other notable changes: * buffer: * (SEMVER-MINOR) add Buffer.copyBytesFrom(...) (James M Snell) https://github.com/nodejs/node/pull/46500 * doc: * add marco-ippolito to collaborators (Marco Ippolito) https://github.com/nodejs/node/pull/46816 * add debadree25 to collaborators (Debadree Chatterjee) https://github.com/nodejs/node/pull/46716 * add deokjinkim to collaborators (Deokjin Kim) https://github.com/nodejs/node/pull/46444 * events: * (SEMVER-MINOR) add listener argument to listenerCount (Paolo Insogna) https://github.com/nodejs/node/pull/46523 * lib: * (SEMVER-MINOR) add AsyncLocalStorage.bind() and .snapshot() (flakey5) https://github.com/nodejs/node/pull/46387 * (SEMVER-MINOR) add aborted() utility function (Debadree Chatterjee) https://github.com/nodejs/node/pull/46494 * src: * (SEMVER-MINOR) allow optional Isolate termination in node::Stop() (Shelley Vohr) https://github.com/nodejs/node/pull/46583 * (SEMVER-MINOR) allow embedder control of code generation policy (Shelley Vohr) https://github.com/nodejs/node/pull/46368 * stream: * (SEMVER-MINOR) add abort signal for ReadableStream and WritableStream (Debadree Chatterjee) https://github.com/nodejs/node/pull/46273 * tls: * (SEMVER-MINOR) support automatic DHE (Tobias Nießen) https://github.com/nodejs/node/pull/46978 * url: * (SEMVER-MINOR) implement URLSearchParams size getter (James M Snell) https://github.com/nodejs/node/pull/46308 * worker: * (SEMVER-MINOR) add support for worker name in inspector and trace_events (Debadree Chatterjee) https://github.com/nodejs/node/pull/46832 PR-URL: https://github.com/nodejs/node/pull/47502
2023-04-10 23:02:28 -04:00
- version:
- v19.8.0
- v18.16.0
pr-url: https://github.com/nodejs/node/pull/46889
description: Calling `it()` is now equivalent to calling `test()`.
-->
Alias for [`test()`][].
The `it()` function is imported from the `node:test` module.
## `it.skip([name][, options][, fn])`
Shorthand for skipping a test,
same as [`it([name], { skip: true }[, fn])`][it options].
## `it.todo([name][, options][, fn])`
Shorthand for marking a test as `TODO`,
same as [`it([name], { todo: true }[, fn])`][it options].
## `it.only([name][, options][, fn])`
<!-- YAML
added:
- v19.8.0
- v18.15.0
-->
Shorthand for marking a test as `only`,
same as [`it([name], { only: true }[, fn])`][it options].
## `before([fn][, options])`
<!-- YAML
2022-10-12, Version 16.18.0 'Gallium' (LTS) Notable changes: assert: add `getCalls` and `reset` to callTracker (Moshe Atlow) https://github.com/nodejs/node/pull/44191 crypto: allow zero-length secret KeyObject (Filip Skokan) https://github.com/nodejs/node/pull/44201 crypto: allow zero-length IKM in HKDF and in webcrypto PBKDF2 (Filip Skokan) https://github.com/nodejs/node/pull/44201 doc: deprecate modp1, modp2, and modp5 groups (Tobias Nießen) https://github.com/nodejs/node/pull/44588 http: make idle http parser count configurable (theanarkh) https://github.com/nodejs/node/pull/43974 http: throw error on content-length mismatch (sidwebworks) https://github.com/nodejs/node/pull/44378 lib: add diagnostics channel for process and worker (theanarkh) https://github.com/nodejs/node/pull/44045 net,tls: pass a valid socket on `tlsClientError` (Daeyeon Jeong) https://github.com/nodejs/node/pull/44021 net: add local family (theanarkh) https://github.com/nodejs/node/pull/43975 report: expose report public native apis (Chengzhong Wu) https://github.com/nodejs/node/pull/44255 src: expose environment RequestInterrupt api (Chengzhong Wu) https://github.com/nodejs/node/pull/44362 stream: add `ReadableByteStream.tee()` (Daeyeon Jeong) https://github.com/nodejs/node/pull/44505 test_runner: add before/after/each hooks (Moshe Atlow) https://github.com/nodejs/node/pull/43730 util: add `maxArrayLength` option to Set and Map (Kohei Ueno) https://github.com/nodejs/node/pull/43576 PR-URL: https://github.com/nodejs/node/pull/44886
2022-10-11 14:54:19 -05:00
added:
- v18.8.0
- v16.18.0
-->
* `fn` {Function|AsyncFunction} The hook function.
If the hook uses callbacks,
the callback function is passed as the second argument. **Default:** A no-op
function.
* `options` {Object} Configuration options for the hook. The following
properties are supported:
* `signal` {AbortSignal} Allows aborting an in-progress hook.
* `timeout` {number} A number of milliseconds the hook will fail after.
If unspecified, subtests inherit this value from their parent.
**Default:** `Infinity`.
This function creates a hook that runs before executing a suite.
```js
describe('tests', async () => {
before(() => console.log('about to run some test'));
it('is a subtest', () => {
assert.ok('some relevant assertion here');
});
});
```
## `after([fn][, options])`
<!-- YAML
2022-10-12, Version 16.18.0 'Gallium' (LTS) Notable changes: assert: add `getCalls` and `reset` to callTracker (Moshe Atlow) https://github.com/nodejs/node/pull/44191 crypto: allow zero-length secret KeyObject (Filip Skokan) https://github.com/nodejs/node/pull/44201 crypto: allow zero-length IKM in HKDF and in webcrypto PBKDF2 (Filip Skokan) https://github.com/nodejs/node/pull/44201 doc: deprecate modp1, modp2, and modp5 groups (Tobias Nießen) https://github.com/nodejs/node/pull/44588 http: make idle http parser count configurable (theanarkh) https://github.com/nodejs/node/pull/43974 http: throw error on content-length mismatch (sidwebworks) https://github.com/nodejs/node/pull/44378 lib: add diagnostics channel for process and worker (theanarkh) https://github.com/nodejs/node/pull/44045 net,tls: pass a valid socket on `tlsClientError` (Daeyeon Jeong) https://github.com/nodejs/node/pull/44021 net: add local family (theanarkh) https://github.com/nodejs/node/pull/43975 report: expose report public native apis (Chengzhong Wu) https://github.com/nodejs/node/pull/44255 src: expose environment RequestInterrupt api (Chengzhong Wu) https://github.com/nodejs/node/pull/44362 stream: add `ReadableByteStream.tee()` (Daeyeon Jeong) https://github.com/nodejs/node/pull/44505 test_runner: add before/after/each hooks (Moshe Atlow) https://github.com/nodejs/node/pull/43730 util: add `maxArrayLength` option to Set and Map (Kohei Ueno) https://github.com/nodejs/node/pull/43576 PR-URL: https://github.com/nodejs/node/pull/44886
2022-10-11 14:54:19 -05:00
added:
- v18.8.0
- v16.18.0
-->
* `fn` {Function|AsyncFunction} The hook function.
If the hook uses callbacks,
the callback function is passed as the second argument. **Default:** A no-op
function.
* `options` {Object} Configuration options for the hook. The following
properties are supported:
* `signal` {AbortSignal} Allows aborting an in-progress hook.
* `timeout` {number} A number of milliseconds the hook will fail after.
If unspecified, subtests inherit this value from their parent.
**Default:** `Infinity`.
This function creates a hook that runs after executing a suite.
```js
describe('tests', async () => {
after(() => console.log('finished running tests'));
it('is a subtest', () => {
assert.ok('some relevant assertion here');
});
});
```
**Note:** The `after` hook is guaranteed to run,
even if tests within the suite fail.
## `beforeEach([fn][, options])`
<!-- YAML
2022-10-12, Version 16.18.0 'Gallium' (LTS) Notable changes: assert: add `getCalls` and `reset` to callTracker (Moshe Atlow) https://github.com/nodejs/node/pull/44191 crypto: allow zero-length secret KeyObject (Filip Skokan) https://github.com/nodejs/node/pull/44201 crypto: allow zero-length IKM in HKDF and in webcrypto PBKDF2 (Filip Skokan) https://github.com/nodejs/node/pull/44201 doc: deprecate modp1, modp2, and modp5 groups (Tobias Nießen) https://github.com/nodejs/node/pull/44588 http: make idle http parser count configurable (theanarkh) https://github.com/nodejs/node/pull/43974 http: throw error on content-length mismatch (sidwebworks) https://github.com/nodejs/node/pull/44378 lib: add diagnostics channel for process and worker (theanarkh) https://github.com/nodejs/node/pull/44045 net,tls: pass a valid socket on `tlsClientError` (Daeyeon Jeong) https://github.com/nodejs/node/pull/44021 net: add local family (theanarkh) https://github.com/nodejs/node/pull/43975 report: expose report public native apis (Chengzhong Wu) https://github.com/nodejs/node/pull/44255 src: expose environment RequestInterrupt api (Chengzhong Wu) https://github.com/nodejs/node/pull/44362 stream: add `ReadableByteStream.tee()` (Daeyeon Jeong) https://github.com/nodejs/node/pull/44505 test_runner: add before/after/each hooks (Moshe Atlow) https://github.com/nodejs/node/pull/43730 util: add `maxArrayLength` option to Set and Map (Kohei Ueno) https://github.com/nodejs/node/pull/43576 PR-URL: https://github.com/nodejs/node/pull/44886
2022-10-11 14:54:19 -05:00
added:
- v18.8.0
- v16.18.0
-->
* `fn` {Function|AsyncFunction} The hook function.
If the hook uses callbacks,
the callback function is passed as the second argument. **Default:** A no-op
function.
* `options` {Object} Configuration options for the hook. The following
properties are supported:
* `signal` {AbortSignal} Allows aborting an in-progress hook.
* `timeout` {number} A number of milliseconds the hook will fail after.
If unspecified, subtests inherit this value from their parent.
**Default:** `Infinity`.
This function creates a hook that runs before each test in the current suite.
```js
describe('tests', async () => {
beforeEach(() => console.log('about to run a test'));
it('is a subtest', () => {
assert.ok('some relevant assertion here');
});
});
```
## `afterEach([fn][, options])`
<!-- YAML
2022-10-12, Version 16.18.0 'Gallium' (LTS) Notable changes: assert: add `getCalls` and `reset` to callTracker (Moshe Atlow) https://github.com/nodejs/node/pull/44191 crypto: allow zero-length secret KeyObject (Filip Skokan) https://github.com/nodejs/node/pull/44201 crypto: allow zero-length IKM in HKDF and in webcrypto PBKDF2 (Filip Skokan) https://github.com/nodejs/node/pull/44201 doc: deprecate modp1, modp2, and modp5 groups (Tobias Nießen) https://github.com/nodejs/node/pull/44588 http: make idle http parser count configurable (theanarkh) https://github.com/nodejs/node/pull/43974 http: throw error on content-length mismatch (sidwebworks) https://github.com/nodejs/node/pull/44378 lib: add diagnostics channel for process and worker (theanarkh) https://github.com/nodejs/node/pull/44045 net,tls: pass a valid socket on `tlsClientError` (Daeyeon Jeong) https://github.com/nodejs/node/pull/44021 net: add local family (theanarkh) https://github.com/nodejs/node/pull/43975 report: expose report public native apis (Chengzhong Wu) https://github.com/nodejs/node/pull/44255 src: expose environment RequestInterrupt api (Chengzhong Wu) https://github.com/nodejs/node/pull/44362 stream: add `ReadableByteStream.tee()` (Daeyeon Jeong) https://github.com/nodejs/node/pull/44505 test_runner: add before/after/each hooks (Moshe Atlow) https://github.com/nodejs/node/pull/43730 util: add `maxArrayLength` option to Set and Map (Kohei Ueno) https://github.com/nodejs/node/pull/43576 PR-URL: https://github.com/nodejs/node/pull/44886
2022-10-11 14:54:19 -05:00
added:
- v18.8.0
- v16.18.0
-->
* `fn` {Function|AsyncFunction} The hook function.
If the hook uses callbacks,
the callback function is passed as the second argument. **Default:** A no-op
function.
* `options` {Object} Configuration options for the hook. The following
properties are supported:
* `signal` {AbortSignal} Allows aborting an in-progress hook.
* `timeout` {number} A number of milliseconds the hook will fail after.
If unspecified, subtests inherit this value from their parent.
**Default:** `Infinity`.
This function creates a hook that runs after each test in the current suite.
The `afterEach()` hook is run even if the test fails.
```js
describe('tests', async () => {
afterEach(() => console.log('finished running a test'));
it('is a subtest', () => {
assert.ok('some relevant assertion here');
});
});
```
## `assert`
<!-- YAML
2025-02-11, Version 22.14.0 'Jod' (LTS) Notable changes: crypto: * update root certificates to NSS 3.107 (Node.js GitHub Bot) https://github.com/nodejs/node/pull/56566 fs: * (SEMVER-MINOR) allow `exclude` option in globs to accept glob patterns (Daeyeon Jeong) https://github.com/nodejs/node/pull/56489 lib: * (SEMVER-MINOR) add typescript support to STDIN eval (Marco Ippolito) https://github.com/nodejs/node/pull/56359 module: * (SEMVER-MINOR) add ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX (Marco Ippolito) https://github.com/nodejs/node/pull/56610 * (SEMVER-MINOR) add `findPackageJSON` util (Jacob Smith) https://github.com/nodejs/node/pull/55412 process: * (SEMVER-MINOR) add process.ref() and process.unref() methods (James M Snell) https://github.com/nodejs/node/pull/56400 sqlite: * (SEMVER-MINOR) support TypedArray and DataView in `StatementSync` (Alex Yang) https://github.com/nodejs/node/pull/56385 src: * (SEMVER-MINOR) add --disable-sigusr1 to prevent signal i/o thread (Rafael Gonzaga) https://github.com/nodejs/node/pull/56441 src,worker: * (SEMVER-MINOR) add isInternalWorker (Carlos Espa) https://github.com/nodejs/node/pull/56469 test_runner: * (SEMVER-MINOR) add TestContext.prototype.waitFor() (Colin Ihrig) https://github.com/nodejs/node/pull/56595 * (SEMVER-MINOR) add t.assert.fileSnapshot() (Colin Ihrig) https://github.com/nodejs/node/pull/56459 * (SEMVER-MINOR) add assert.register() API (Colin Ihrig) https://github.com/nodejs/node/pull/56434 worker: * (SEMVER-MINOR) add eval ts input (Marco Ippolito) https://github.com/nodejs/node/pull/56394 PR-URL: https://github.com/nodejs/node/pull/56910
2025-02-06 11:04:25 +01:00
added:
- v23.7.0
- v22.14.0
-->
An object whose methods are used to configure available assertions on the
`TestContext` objects in the current process. The methods from `node:assert`
and snapshot testing functions are available by default.
It is possible to apply the same configuration to all files by placing common
configuration code in a module
preloaded with `--require` or `--import`.
### `assert.register(name, fn)`
<!-- YAML
2025-02-11, Version 22.14.0 'Jod' (LTS) Notable changes: crypto: * update root certificates to NSS 3.107 (Node.js GitHub Bot) https://github.com/nodejs/node/pull/56566 fs: * (SEMVER-MINOR) allow `exclude` option in globs to accept glob patterns (Daeyeon Jeong) https://github.com/nodejs/node/pull/56489 lib: * (SEMVER-MINOR) add typescript support to STDIN eval (Marco Ippolito) https://github.com/nodejs/node/pull/56359 module: * (SEMVER-MINOR) add ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX (Marco Ippolito) https://github.com/nodejs/node/pull/56610 * (SEMVER-MINOR) add `findPackageJSON` util (Jacob Smith) https://github.com/nodejs/node/pull/55412 process: * (SEMVER-MINOR) add process.ref() and process.unref() methods (James M Snell) https://github.com/nodejs/node/pull/56400 sqlite: * (SEMVER-MINOR) support TypedArray and DataView in `StatementSync` (Alex Yang) https://github.com/nodejs/node/pull/56385 src: * (SEMVER-MINOR) add --disable-sigusr1 to prevent signal i/o thread (Rafael Gonzaga) https://github.com/nodejs/node/pull/56441 src,worker: * (SEMVER-MINOR) add isInternalWorker (Carlos Espa) https://github.com/nodejs/node/pull/56469 test_runner: * (SEMVER-MINOR) add TestContext.prototype.waitFor() (Colin Ihrig) https://github.com/nodejs/node/pull/56595 * (SEMVER-MINOR) add t.assert.fileSnapshot() (Colin Ihrig) https://github.com/nodejs/node/pull/56459 * (SEMVER-MINOR) add assert.register() API (Colin Ihrig) https://github.com/nodejs/node/pull/56434 worker: * (SEMVER-MINOR) add eval ts input (Marco Ippolito) https://github.com/nodejs/node/pull/56394 PR-URL: https://github.com/nodejs/node/pull/56910
2025-02-06 11:04:25 +01:00
added:
- v23.7.0
- v22.14.0
-->
Defines a new assertion function with the provided name and function. If an
assertion already exists with the same name, it is overwritten.
## `snapshot`
<!-- YAML
2024-06-11, Version 22.3.0 (Current) Notable changes: buffer: * (SEMVER-MINOR) add .bytes() method to Blob (Matthew Aitken) https://github.com/nodejs/node/pull/53221 cli: * (SEMVER-MINOR) add `NODE_RUN_PACKAGE_JSON_PATH` env (Yagiz Nizipli) https://github.com/nodejs/node/pull/53058 * (SEMVER-MINOR) add `NODE_RUN_SCRIPT_NAME` env to `node --run` (Yagiz Nizipli) https://github.com/nodejs/node/pull/53032 doc: * (SEMVER-MINOR) add context.assert docs (Colin Ihrig) https://github.com/nodejs/node/pull/53169 * (SEMVER-MINOR) improve explanation about built-in modules (Joyee Cheung) https://github.com/nodejs/node/pull/52762 * add StefanStojanovic to collaborators (StefanStojanovic) https://github.com/nodejs/node/pull/53118 * add Marco Ippolito to TSC (Rafael Gonzaga) https://github.com/nodejs/node/pull/53008 fs: * mark recursive cp methods as stable (Théo LUDWIG) https://github.com/nodejs/node/pull/53127 lib: * (SEMVER-MINOR) add EventSource Client (Aras Abbasi) https://github.com/nodejs/node/pull/51575 * (SEMVER-MINOR) replace MessageEvent with undici's (Matthew Aitken) https://github.com/nodejs/node/pull/52370 module: * (SEMVER-MINOR) print amount of load time of a cjs module (Vinicius Lourenço) https://github.com/nodejs/node/pull/52213 net: * (SEMVER-MINOR) add new net.server.listen tracing channel (Paolo Insogna) https://github.com/nodejs/node/pull/53136 process: * (SEMVER-MINOR) add process.getBuiltinModule(id) (Joyee Cheung) https://github.com/nodejs/node/pull/52762 src: * (SEMVER-MINOR) traverse parent folders while running `--run` (Yagiz Nizipli) https://github.com/nodejs/node/pull/53154 src,permission: * (SEMVER-MINOR) --allow-wasi & prevent WASI exec (Rafael Gonzaga) https://github.com/nodejs/node/pull/53124 test_runner: * (SEMVER-MINOR) add snapshot testing (Colin Ihrig) https://github.com/nodejs/node/pull/53169 * (SEMVER-MINOR) add context.fullName (Colin Ihrig) https://github.com/nodejs/node/pull/53169 * (SEMVER-MINOR) support module mocking (Colin Ihrig) https://github.com/nodejs/node/pull/52848 PR-URL: https://github.com/nodejs/node/pull/53379
2024-06-07 10:47:50 -03:00
added: v22.3.0
-->
An object whose methods are used to configure default snapshot settings in the
current process. It is possible to apply the same configuration to all files by
placing common configuration code in a module preloaded with `--require` or
`--import`.
### `snapshot.setDefaultSnapshotSerializers(serializers)`
<!-- YAML
2024-06-11, Version 22.3.0 (Current) Notable changes: buffer: * (SEMVER-MINOR) add .bytes() method to Blob (Matthew Aitken) https://github.com/nodejs/node/pull/53221 cli: * (SEMVER-MINOR) add `NODE_RUN_PACKAGE_JSON_PATH` env (Yagiz Nizipli) https://github.com/nodejs/node/pull/53058 * (SEMVER-MINOR) add `NODE_RUN_SCRIPT_NAME` env to `node --run` (Yagiz Nizipli) https://github.com/nodejs/node/pull/53032 doc: * (SEMVER-MINOR) add context.assert docs (Colin Ihrig) https://github.com/nodejs/node/pull/53169 * (SEMVER-MINOR) improve explanation about built-in modules (Joyee Cheung) https://github.com/nodejs/node/pull/52762 * add StefanStojanovic to collaborators (StefanStojanovic) https://github.com/nodejs/node/pull/53118 * add Marco Ippolito to TSC (Rafael Gonzaga) https://github.com/nodejs/node/pull/53008 fs: * mark recursive cp methods as stable (Théo LUDWIG) https://github.com/nodejs/node/pull/53127 lib: * (SEMVER-MINOR) add EventSource Client (Aras Abbasi) https://github.com/nodejs/node/pull/51575 * (SEMVER-MINOR) replace MessageEvent with undici's (Matthew Aitken) https://github.com/nodejs/node/pull/52370 module: * (SEMVER-MINOR) print amount of load time of a cjs module (Vinicius Lourenço) https://github.com/nodejs/node/pull/52213 net: * (SEMVER-MINOR) add new net.server.listen tracing channel (Paolo Insogna) https://github.com/nodejs/node/pull/53136 process: * (SEMVER-MINOR) add process.getBuiltinModule(id) (Joyee Cheung) https://github.com/nodejs/node/pull/52762 src: * (SEMVER-MINOR) traverse parent folders while running `--run` (Yagiz Nizipli) https://github.com/nodejs/node/pull/53154 src,permission: * (SEMVER-MINOR) --allow-wasi & prevent WASI exec (Rafael Gonzaga) https://github.com/nodejs/node/pull/53124 test_runner: * (SEMVER-MINOR) add snapshot testing (Colin Ihrig) https://github.com/nodejs/node/pull/53169 * (SEMVER-MINOR) add context.fullName (Colin Ihrig) https://github.com/nodejs/node/pull/53169 * (SEMVER-MINOR) support module mocking (Colin Ihrig) https://github.com/nodejs/node/pull/52848 PR-URL: https://github.com/nodejs/node/pull/53379
2024-06-07 10:47:50 -03:00
added: v22.3.0
-->
* `serializers` {Array} An array of synchronous functions used as the default
serializers for snapshot tests.
This function is used to customize the default serialization mechanism used by
the test runner. By default, the test runner performs serialization by calling
`JSON.stringify(value, null, 2)` on the provided value. `JSON.stringify()` does
have limitations regarding circular structures and supported data types. If a
more robust serialization mechanism is required, this function should be used.
### `snapshot.setResolveSnapshotPath(fn)`
<!-- YAML
2024-06-11, Version 22.3.0 (Current) Notable changes: buffer: * (SEMVER-MINOR) add .bytes() method to Blob (Matthew Aitken) https://github.com/nodejs/node/pull/53221 cli: * (SEMVER-MINOR) add `NODE_RUN_PACKAGE_JSON_PATH` env (Yagiz Nizipli) https://github.com/nodejs/node/pull/53058 * (SEMVER-MINOR) add `NODE_RUN_SCRIPT_NAME` env to `node --run` (Yagiz Nizipli) https://github.com/nodejs/node/pull/53032 doc: * (SEMVER-MINOR) add context.assert docs (Colin Ihrig) https://github.com/nodejs/node/pull/53169 * (SEMVER-MINOR) improve explanation about built-in modules (Joyee Cheung) https://github.com/nodejs/node/pull/52762 * add StefanStojanovic to collaborators (StefanStojanovic) https://github.com/nodejs/node/pull/53118 * add Marco Ippolito to TSC (Rafael Gonzaga) https://github.com/nodejs/node/pull/53008 fs: * mark recursive cp methods as stable (Théo LUDWIG) https://github.com/nodejs/node/pull/53127 lib: * (SEMVER-MINOR) add EventSource Client (Aras Abbasi) https://github.com/nodejs/node/pull/51575 * (SEMVER-MINOR) replace MessageEvent with undici's (Matthew Aitken) https://github.com/nodejs/node/pull/52370 module: * (SEMVER-MINOR) print amount of load time of a cjs module (Vinicius Lourenço) https://github.com/nodejs/node/pull/52213 net: * (SEMVER-MINOR) add new net.server.listen tracing channel (Paolo Insogna) https://github.com/nodejs/node/pull/53136 process: * (SEMVER-MINOR) add process.getBuiltinModule(id) (Joyee Cheung) https://github.com/nodejs/node/pull/52762 src: * (SEMVER-MINOR) traverse parent folders while running `--run` (Yagiz Nizipli) https://github.com/nodejs/node/pull/53154 src,permission: * (SEMVER-MINOR) --allow-wasi & prevent WASI exec (Rafael Gonzaga) https://github.com/nodejs/node/pull/53124 test_runner: * (SEMVER-MINOR) add snapshot testing (Colin Ihrig) https://github.com/nodejs/node/pull/53169 * (SEMVER-MINOR) add context.fullName (Colin Ihrig) https://github.com/nodejs/node/pull/53169 * (SEMVER-MINOR) support module mocking (Colin Ihrig) https://github.com/nodejs/node/pull/52848 PR-URL: https://github.com/nodejs/node/pull/53379
2024-06-07 10:47:50 -03:00
added: v22.3.0
-->
* `fn` {Function} A function used to compute the location of the snapshot file.
The function receives the path of the test file as its only argument. If the
test is not associated with a file (for example in the REPL), the input is
undefined. `fn()` must return a string specifying the location of the snapshot
snapshot file.
This function is used to customize the location of the snapshot file used for
snapshot testing. By default, the snapshot filename is the same as the entry
point filename with a `.snapshot` file extension.
## Class: `MockFunctionContext`
<!-- YAML
2023-01-05, Version 18.13.0 'Hydrogen' (LTS) Notable changes: Add support for externally shared js builtins: By default Node.js is built so that all dependencies are bundled into the Node.js binary itself. Some Node.js distributions prefer to manage dependencies externally. There are existing build options that allow dependencies with native code to be externalized. This commit adds additional options so that dependencies with JavaScript code (including WASM) can also be externalized. This addition does not affect binaries shipped by the Node.js project but will allow other distributions to externalize additional dependencies when needed. Contributed by Michael Dawson in https://github.com/nodejs/node/pull/44376 Introduce `File`: The File class is part of the [FileAPI](https://w3c.github.io/FileAPI/). It can be used anywhere a Blob can, for example in `URL.createObjectURL` and `FormData`. It contains two properties that Blobs do not have: `lastModified`, the last time the file was modified in ms, and `name`, the name of the file. Contributed by Khafra in https://github.com/nodejs/node/pull/45139 Support function mocking on Node.js test runner: The `node:test` module supports mocking during testing via a top-level `mock` object. ```js test('spies on an object method', (t) => { const number = { value: 5, add(a) { return this.value + a; }, }; t.mock.method(number, 'add'); assert.strictEqual(number.add(3), 8); assert.strictEqual(number.add.mock.calls.length, 1); }); ``` Contributed by Colin Ihrig in https://github.com/nodejs/node/pull/45326 Other notable changes: build: * disable v8 snapshot compression by default (Joyee Cheung) https://github.com/nodejs/node/pull/45716 crypto: * update root certificates (Luigi Pinca) https://github.com/nodejs/node/pull/45490 deps: * update ICU to 72.1 (Michaël Zasso) https://github.com/nodejs/node/pull/45068 doc: * add doc-only deprecation for headers/trailers setters (Rich Trott) https://github.com/nodejs/node/pull/45697 * add Rafael to the tsc (Michael Dawson) https://github.com/nodejs/node/pull/45691 * deprecate use of invalid ports in `url.parse` (Antoine du Hamel) https://github.com/nodejs/node/pull/45576 * add lukekarrys to collaborators (Luke Karrys) https://github.com/nodejs/node/pull/45180 * add anonrig to collaborators (Yagiz Nizipli) https://github.com/nodejs/node/pull/45002 * deprecate url.parse() (Rich Trott) https://github.com/nodejs/node/pull/44919 lib: * drop fetch experimental warning (Matteo Collina) https://github.com/nodejs/node/pull/45287 net: * (SEMVER-MINOR) add autoSelectFamily and autoSelectFamilyAttemptTimeout options (Paolo Insogna) https://github.com/nodejs/node/pull/44731 * src: * (SEMVER-MINOR) add uvwasi version (Jithil P Ponnan) https://github.com/nodejs/node/pull/45639 * (SEMVER-MINOR) add initial shadow realm support (Chengzhong Wu) https://github.com/nodejs/node/pull/42869 test_runner: * (SEMVER-MINOR) add t.after() hook (Colin Ihrig) https://github.com/nodejs/node/pull/45792 * (SEMVER-MINOR) don't use a symbol for runHook() (Colin Ihrig) https://github.com/nodejs/node/pull/45792 tls: * (SEMVER-MINOR) add "ca" property to certificate object (Ben Noordhuis) https://github.com/nodejs/node/pull/44935 * remove trustcor root ca certificates (Ben Noordhuis) https://github.com/nodejs/node/pull/45776 tools: * update certdata.txt (Luigi Pinca) https://github.com/nodejs/node/pull/45490 util: * add fast path for utf8 encoding (Yagiz Nizipli) https://github.com/nodejs/node/pull/45412 * improve textdecoder decode performance (Yagiz Nizipli) https://github.com/nodejs/node/pull/45294 * (SEMVER-MINOR) add MIME utilities (#21128) (Bradley Farias) https://github.com/nodejs/node/pull/21128 PR-URL: https://github.com/nodejs/node/pull/46025
2022-12-30 15:18:44 -05:00
added:
- v19.1.0
- v18.13.0
-->
The `MockFunctionContext` class is used to inspect or manipulate the behavior of
mocks created via the [`MockTracker`][] APIs.
### `ctx.calls`
<!-- YAML
2023-01-05, Version 18.13.0 'Hydrogen' (LTS) Notable changes: Add support for externally shared js builtins: By default Node.js is built so that all dependencies are bundled into the Node.js binary itself. Some Node.js distributions prefer to manage dependencies externally. There are existing build options that allow dependencies with native code to be externalized. This commit adds additional options so that dependencies with JavaScript code (including WASM) can also be externalized. This addition does not affect binaries shipped by the Node.js project but will allow other distributions to externalize additional dependencies when needed. Contributed by Michael Dawson in https://github.com/nodejs/node/pull/44376 Introduce `File`: The File class is part of the [FileAPI](https://w3c.github.io/FileAPI/). It can be used anywhere a Blob can, for example in `URL.createObjectURL` and `FormData`. It contains two properties that Blobs do not have: `lastModified`, the last time the file was modified in ms, and `name`, the name of the file. Contributed by Khafra in https://github.com/nodejs/node/pull/45139 Support function mocking on Node.js test runner: The `node:test` module supports mocking during testing via a top-level `mock` object. ```js test('spies on an object method', (t) => { const number = { value: 5, add(a) { return this.value + a; }, }; t.mock.method(number, 'add'); assert.strictEqual(number.add(3), 8); assert.strictEqual(number.add.mock.calls.length, 1); }); ``` Contributed by Colin Ihrig in https://github.com/nodejs/node/pull/45326 Other notable changes: build: * disable v8 snapshot compression by default (Joyee Cheung) https://github.com/nodejs/node/pull/45716 crypto: * update root certificates (Luigi Pinca) https://github.com/nodejs/node/pull/45490 deps: * update ICU to 72.1 (Michaël Zasso) https://github.com/nodejs/node/pull/45068 doc: * add doc-only deprecation for headers/trailers setters (Rich Trott) https://github.com/nodejs/node/pull/45697 * add Rafael to the tsc (Michael Dawson) https://github.com/nodejs/node/pull/45691 * deprecate use of invalid ports in `url.parse` (Antoine du Hamel) https://github.com/nodejs/node/pull/45576 * add lukekarrys to collaborators (Luke Karrys) https://github.com/nodejs/node/pull/45180 * add anonrig to collaborators (Yagiz Nizipli) https://github.com/nodejs/node/pull/45002 * deprecate url.parse() (Rich Trott) https://github.com/nodejs/node/pull/44919 lib: * drop fetch experimental warning (Matteo Collina) https://github.com/nodejs/node/pull/45287 net: * (SEMVER-MINOR) add autoSelectFamily and autoSelectFamilyAttemptTimeout options (Paolo Insogna) https://github.com/nodejs/node/pull/44731 * src: * (SEMVER-MINOR) add uvwasi version (Jithil P Ponnan) https://github.com/nodejs/node/pull/45639 * (SEMVER-MINOR) add initial shadow realm support (Chengzhong Wu) https://github.com/nodejs/node/pull/42869 test_runner: * (SEMVER-MINOR) add t.after() hook (Colin Ihrig) https://github.com/nodejs/node/pull/45792 * (SEMVER-MINOR) don't use a symbol for runHook() (Colin Ihrig) https://github.com/nodejs/node/pull/45792 tls: * (SEMVER-MINOR) add "ca" property to certificate object (Ben Noordhuis) https://github.com/nodejs/node/pull/44935 * remove trustcor root ca certificates (Ben Noordhuis) https://github.com/nodejs/node/pull/45776 tools: * update certdata.txt (Luigi Pinca) https://github.com/nodejs/node/pull/45490 util: * add fast path for utf8 encoding (Yagiz Nizipli) https://github.com/nodejs/node/pull/45412 * improve textdecoder decode performance (Yagiz Nizipli) https://github.com/nodejs/node/pull/45294 * (SEMVER-MINOR) add MIME utilities (#21128) (Bradley Farias) https://github.com/nodejs/node/pull/21128 PR-URL: https://github.com/nodejs/node/pull/46025
2022-12-30 15:18:44 -05:00
added:
- v19.1.0
- v18.13.0
-->
* {Array}
A getter that returns a copy of the internal array used to track calls to the
mock. Each entry in the array is an object with the following properties.
* `arguments` {Array} An array of the arguments passed to the mock function.
* `error` {any} If the mocked function threw then this property contains the
thrown value. **Default:** `undefined`.
* `result` {any} The value returned by the mocked function.
* `stack` {Error} An `Error` object whose stack can be used to determine the
callsite of the mocked function invocation.
* `target` {Function|undefined} If the mocked function is a constructor, this
field contains the class being constructed. Otherwise this will be
`undefined`.
* `this` {any} The mocked function's `this` value.
### `ctx.callCount()`
<!-- YAML
2023-01-05, Version 18.13.0 'Hydrogen' (LTS) Notable changes: Add support for externally shared js builtins: By default Node.js is built so that all dependencies are bundled into the Node.js binary itself. Some Node.js distributions prefer to manage dependencies externally. There are existing build options that allow dependencies with native code to be externalized. This commit adds additional options so that dependencies with JavaScript code (including WASM) can also be externalized. This addition does not affect binaries shipped by the Node.js project but will allow other distributions to externalize additional dependencies when needed. Contributed by Michael Dawson in https://github.com/nodejs/node/pull/44376 Introduce `File`: The File class is part of the [FileAPI](https://w3c.github.io/FileAPI/). It can be used anywhere a Blob can, for example in `URL.createObjectURL` and `FormData`. It contains two properties that Blobs do not have: `lastModified`, the last time the file was modified in ms, and `name`, the name of the file. Contributed by Khafra in https://github.com/nodejs/node/pull/45139 Support function mocking on Node.js test runner: The `node:test` module supports mocking during testing via a top-level `mock` object. ```js test('spies on an object method', (t) => { const number = { value: 5, add(a) { return this.value + a; }, }; t.mock.method(number, 'add'); assert.strictEqual(number.add(3), 8); assert.strictEqual(number.add.mock.calls.length, 1); }); ``` Contributed by Colin Ihrig in https://github.com/nodejs/node/pull/45326 Other notable changes: build: * disable v8 snapshot compression by default (Joyee Cheung) https://github.com/nodejs/node/pull/45716 crypto: * update root certificates (Luigi Pinca) https://github.com/nodejs/node/pull/45490 deps: * update ICU to 72.1 (Michaël Zasso) https://github.com/nodejs/node/pull/45068 doc: * add doc-only deprecation for headers/trailers setters (Rich Trott) https://github.com/nodejs/node/pull/45697 * add Rafael to the tsc (Michael Dawson) https://github.com/nodejs/node/pull/45691 * deprecate use of invalid ports in `url.parse` (Antoine du Hamel) https://github.com/nodejs/node/pull/45576 * add lukekarrys to collaborators (Luke Karrys) https://github.com/nodejs/node/pull/45180 * add anonrig to collaborators (Yagiz Nizipli) https://github.com/nodejs/node/pull/45002 * deprecate url.parse() (Rich Trott) https://github.com/nodejs/node/pull/44919 lib: * drop fetch experimental warning (Matteo Collina) https://github.com/nodejs/node/pull/45287 net: * (SEMVER-MINOR) add autoSelectFamily and autoSelectFamilyAttemptTimeout options (Paolo Insogna) https://github.com/nodejs/node/pull/44731 * src: * (SEMVER-MINOR) add uvwasi version (Jithil P Ponnan) https://github.com/nodejs/node/pull/45639 * (SEMVER-MINOR) add initial shadow realm support (Chengzhong Wu) https://github.com/nodejs/node/pull/42869 test_runner: * (SEMVER-MINOR) add t.after() hook (Colin Ihrig) https://github.com/nodejs/node/pull/45792 * (SEMVER-MINOR) don't use a symbol for runHook() (Colin Ihrig) https://github.com/nodejs/node/pull/45792 tls: * (SEMVER-MINOR) add "ca" property to certificate object (Ben Noordhuis) https://github.com/nodejs/node/pull/44935 * remove trustcor root ca certificates (Ben Noordhuis) https://github.com/nodejs/node/pull/45776 tools: * update certdata.txt (Luigi Pinca) https://github.com/nodejs/node/pull/45490 util: * add fast path for utf8 encoding (Yagiz Nizipli) https://github.com/nodejs/node/pull/45412 * improve textdecoder decode performance (Yagiz Nizipli) https://github.com/nodejs/node/pull/45294 * (SEMVER-MINOR) add MIME utilities (#21128) (Bradley Farias) https://github.com/nodejs/node/pull/21128 PR-URL: https://github.com/nodejs/node/pull/46025
2022-12-30 15:18:44 -05:00
added:
- v19.1.0
- v18.13.0
-->
* Returns: {integer} The number of times that this mock has been invoked.
This function returns the number of times that this mock has been invoked. This
function is more efficient than checking `ctx.calls.length` because `ctx.calls`
is a getter that creates a copy of the internal call tracking array.
### `ctx.mockImplementation(implementation)`
<!-- YAML
2023-01-05, Version 18.13.0 'Hydrogen' (LTS) Notable changes: Add support for externally shared js builtins: By default Node.js is built so that all dependencies are bundled into the Node.js binary itself. Some Node.js distributions prefer to manage dependencies externally. There are existing build options that allow dependencies with native code to be externalized. This commit adds additional options so that dependencies with JavaScript code (including WASM) can also be externalized. This addition does not affect binaries shipped by the Node.js project but will allow other distributions to externalize additional dependencies when needed. Contributed by Michael Dawson in https://github.com/nodejs/node/pull/44376 Introduce `File`: The File class is part of the [FileAPI](https://w3c.github.io/FileAPI/). It can be used anywhere a Blob can, for example in `URL.createObjectURL` and `FormData`. It contains two properties that Blobs do not have: `lastModified`, the last time the file was modified in ms, and `name`, the name of the file. Contributed by Khafra in https://github.com/nodejs/node/pull/45139 Support function mocking on Node.js test runner: The `node:test` module supports mocking during testing via a top-level `mock` object. ```js test('spies on an object method', (t) => { const number = { value: 5, add(a) { return this.value + a; }, }; t.mock.method(number, 'add'); assert.strictEqual(number.add(3), 8); assert.strictEqual(number.add.mock.calls.length, 1); }); ``` Contributed by Colin Ihrig in https://github.com/nodejs/node/pull/45326 Other notable changes: build: * disable v8 snapshot compression by default (Joyee Cheung) https://github.com/nodejs/node/pull/45716 crypto: * update root certificates (Luigi Pinca) https://github.com/nodejs/node/pull/45490 deps: * update ICU to 72.1 (Michaël Zasso) https://github.com/nodejs/node/pull/45068 doc: * add doc-only deprecation for headers/trailers setters (Rich Trott) https://github.com/nodejs/node/pull/45697 * add Rafael to the tsc (Michael Dawson) https://github.com/nodejs/node/pull/45691 * deprecate use of invalid ports in `url.parse` (Antoine du Hamel) https://github.com/nodejs/node/pull/45576 * add lukekarrys to collaborators (Luke Karrys) https://github.com/nodejs/node/pull/45180 * add anonrig to collaborators (Yagiz Nizipli) https://github.com/nodejs/node/pull/45002 * deprecate url.parse() (Rich Trott) https://github.com/nodejs/node/pull/44919 lib: * drop fetch experimental warning (Matteo Collina) https://github.com/nodejs/node/pull/45287 net: * (SEMVER-MINOR) add autoSelectFamily and autoSelectFamilyAttemptTimeout options (Paolo Insogna) https://github.com/nodejs/node/pull/44731 * src: * (SEMVER-MINOR) add uvwasi version (Jithil P Ponnan) https://github.com/nodejs/node/pull/45639 * (SEMVER-MINOR) add initial shadow realm support (Chengzhong Wu) https://github.com/nodejs/node/pull/42869 test_runner: * (SEMVER-MINOR) add t.after() hook (Colin Ihrig) https://github.com/nodejs/node/pull/45792 * (SEMVER-MINOR) don't use a symbol for runHook() (Colin Ihrig) https://github.com/nodejs/node/pull/45792 tls: * (SEMVER-MINOR) add "ca" property to certificate object (Ben Noordhuis) https://github.com/nodejs/node/pull/44935 * remove trustcor root ca certificates (Ben Noordhuis) https://github.com/nodejs/node/pull/45776 tools: * update certdata.txt (Luigi Pinca) https://github.com/nodejs/node/pull/45490 util: * add fast path for utf8 encoding (Yagiz Nizipli) https://github.com/nodejs/node/pull/45412 * improve textdecoder decode performance (Yagiz Nizipli) https://github.com/nodejs/node/pull/45294 * (SEMVER-MINOR) add MIME utilities (#21128) (Bradley Farias) https://github.com/nodejs/node/pull/21128 PR-URL: https://github.com/nodejs/node/pull/46025
2022-12-30 15:18:44 -05:00
added:
- v19.1.0
- v18.13.0
-->
* `implementation` {Function|AsyncFunction} The function to be used as the
mock's new implementation.
This function is used to change the behavior of an existing mock.
The following example creates a mock function using `t.mock.fn()`, calls the
mock function, and then changes the mock implementation to a different function.
```js
test('changes a mock behavior', (t) => {
let cnt = 0;
function addOne() {
cnt++;
return cnt;
}
function addTwo() {
cnt += 2;
return cnt;
}
const fn = t.mock.fn(addOne);
assert.strictEqual(fn(), 1);
fn.mock.mockImplementation(addTwo);
assert.strictEqual(fn(), 3);
assert.strictEqual(fn(), 5);
});
```
### `ctx.mockImplementationOnce(implementation[, onCall])`
<!-- YAML
2023-01-05, Version 18.13.0 'Hydrogen' (LTS) Notable changes: Add support for externally shared js builtins: By default Node.js is built so that all dependencies are bundled into the Node.js binary itself. Some Node.js distributions prefer to manage dependencies externally. There are existing build options that allow dependencies with native code to be externalized. This commit adds additional options so that dependencies with JavaScript code (including WASM) can also be externalized. This addition does not affect binaries shipped by the Node.js project but will allow other distributions to externalize additional dependencies when needed. Contributed by Michael Dawson in https://github.com/nodejs/node/pull/44376 Introduce `File`: The File class is part of the [FileAPI](https://w3c.github.io/FileAPI/). It can be used anywhere a Blob can, for example in `URL.createObjectURL` and `FormData`. It contains two properties that Blobs do not have: `lastModified`, the last time the file was modified in ms, and `name`, the name of the file. Contributed by Khafra in https://github.com/nodejs/node/pull/45139 Support function mocking on Node.js test runner: The `node:test` module supports mocking during testing via a top-level `mock` object. ```js test('spies on an object method', (t) => { const number = { value: 5, add(a) { return this.value + a; }, }; t.mock.method(number, 'add'); assert.strictEqual(number.add(3), 8); assert.strictEqual(number.add.mock.calls.length, 1); }); ``` Contributed by Colin Ihrig in https://github.com/nodejs/node/pull/45326 Other notable changes: build: * disable v8 snapshot compression by default (Joyee Cheung) https://github.com/nodejs/node/pull/45716 crypto: * update root certificates (Luigi Pinca) https://github.com/nodejs/node/pull/45490 deps: * update ICU to 72.1 (Michaël Zasso) https://github.com/nodejs/node/pull/45068 doc: * add doc-only deprecation for headers/trailers setters (Rich Trott) https://github.com/nodejs/node/pull/45697 * add Rafael to the tsc (Michael Dawson) https://github.com/nodejs/node/pull/45691 * deprecate use of invalid ports in `url.parse` (Antoine du Hamel) https://github.com/nodejs/node/pull/45576 * add lukekarrys to collaborators (Luke Karrys) https://github.com/nodejs/node/pull/45180 * add anonrig to collaborators (Yagiz Nizipli) https://github.com/nodejs/node/pull/45002 * deprecate url.parse() (Rich Trott) https://github.com/nodejs/node/pull/44919 lib: * drop fetch experimental warning (Matteo Collina) https://github.com/nodejs/node/pull/45287 net: * (SEMVER-MINOR) add autoSelectFamily and autoSelectFamilyAttemptTimeout options (Paolo Insogna) https://github.com/nodejs/node/pull/44731 * src: * (SEMVER-MINOR) add uvwasi version (Jithil P Ponnan) https://github.com/nodejs/node/pull/45639 * (SEMVER-MINOR) add initial shadow realm support (Chengzhong Wu) https://github.com/nodejs/node/pull/42869 test_runner: * (SEMVER-MINOR) add t.after() hook (Colin Ihrig) https://github.com/nodejs/node/pull/45792 * (SEMVER-MINOR) don't use a symbol for runHook() (Colin Ihrig) https://github.com/nodejs/node/pull/45792 tls: * (SEMVER-MINOR) add "ca" property to certificate object (Ben Noordhuis) https://github.com/nodejs/node/pull/44935 * remove trustcor root ca certificates (Ben Noordhuis) https://github.com/nodejs/node/pull/45776 tools: * update certdata.txt (Luigi Pinca) https://github.com/nodejs/node/pull/45490 util: * add fast path for utf8 encoding (Yagiz Nizipli) https://github.com/nodejs/node/pull/45412 * improve textdecoder decode performance (Yagiz Nizipli) https://github.com/nodejs/node/pull/45294 * (SEMVER-MINOR) add MIME utilities (#21128) (Bradley Farias) https://github.com/nodejs/node/pull/21128 PR-URL: https://github.com/nodejs/node/pull/46025
2022-12-30 15:18:44 -05:00
added:
- v19.1.0
- v18.13.0
-->
* `implementation` {Function|AsyncFunction} The function to be used as the
mock's implementation for the invocation number specified by `onCall`.
* `onCall` {integer} The invocation number that will use `implementation`. If
the specified invocation has already occurred then an exception is thrown.
**Default:** The number of the next invocation.
This function is used to change the behavior of an existing mock for a single
invocation. Once invocation `onCall` has occurred, the mock will revert to
whatever behavior it would have used had `mockImplementationOnce()` not been
called.
The following example creates a mock function using `t.mock.fn()`, calls the
mock function, changes the mock implementation to a different function for the
next invocation, and then resumes its previous behavior.
```js
test('changes a mock behavior once', (t) => {
let cnt = 0;
function addOne() {
cnt++;
return cnt;
}
function addTwo() {
cnt += 2;
return cnt;
}
const fn = t.mock.fn(addOne);
assert.strictEqual(fn(), 1);
fn.mock.mockImplementationOnce(addTwo);
assert.strictEqual(fn(), 3);
assert.strictEqual(fn(), 4);
});
```
### `ctx.resetCalls()`
<!-- YAML
2023-01-05, Version 18.13.0 'Hydrogen' (LTS) Notable changes: Add support for externally shared js builtins: By default Node.js is built so that all dependencies are bundled into the Node.js binary itself. Some Node.js distributions prefer to manage dependencies externally. There are existing build options that allow dependencies with native code to be externalized. This commit adds additional options so that dependencies with JavaScript code (including WASM) can also be externalized. This addition does not affect binaries shipped by the Node.js project but will allow other distributions to externalize additional dependencies when needed. Contributed by Michael Dawson in https://github.com/nodejs/node/pull/44376 Introduce `File`: The File class is part of the [FileAPI](https://w3c.github.io/FileAPI/). It can be used anywhere a Blob can, for example in `URL.createObjectURL` and `FormData`. It contains two properties that Blobs do not have: `lastModified`, the last time the file was modified in ms, and `name`, the name of the file. Contributed by Khafra in https://github.com/nodejs/node/pull/45139 Support function mocking on Node.js test runner: The `node:test` module supports mocking during testing via a top-level `mock` object. ```js test('spies on an object method', (t) => { const number = { value: 5, add(a) { return this.value + a; }, }; t.mock.method(number, 'add'); assert.strictEqual(number.add(3), 8); assert.strictEqual(number.add.mock.calls.length, 1); }); ``` Contributed by Colin Ihrig in https://github.com/nodejs/node/pull/45326 Other notable changes: build: * disable v8 snapshot compression by default (Joyee Cheung) https://github.com/nodejs/node/pull/45716 crypto: * update root certificates (Luigi Pinca) https://github.com/nodejs/node/pull/45490 deps: * update ICU to 72.1 (Michaël Zasso) https://github.com/nodejs/node/pull/45068 doc: * add doc-only deprecation for headers/trailers setters (Rich Trott) https://github.com/nodejs/node/pull/45697 * add Rafael to the tsc (Michael Dawson) https://github.com/nodejs/node/pull/45691 * deprecate use of invalid ports in `url.parse` (Antoine du Hamel) https://github.com/nodejs/node/pull/45576 * add lukekarrys to collaborators (Luke Karrys) https://github.com/nodejs/node/pull/45180 * add anonrig to collaborators (Yagiz Nizipli) https://github.com/nodejs/node/pull/45002 * deprecate url.parse() (Rich Trott) https://github.com/nodejs/node/pull/44919 lib: * drop fetch experimental warning (Matteo Collina) https://github.com/nodejs/node/pull/45287 net: * (SEMVER-MINOR) add autoSelectFamily and autoSelectFamilyAttemptTimeout options (Paolo Insogna) https://github.com/nodejs/node/pull/44731 * src: * (SEMVER-MINOR) add uvwasi version (Jithil P Ponnan) https://github.com/nodejs/node/pull/45639 * (SEMVER-MINOR) add initial shadow realm support (Chengzhong Wu) https://github.com/nodejs/node/pull/42869 test_runner: * (SEMVER-MINOR) add t.after() hook (Colin Ihrig) https://github.com/nodejs/node/pull/45792 * (SEMVER-MINOR) don't use a symbol for runHook() (Colin Ihrig) https://github.com/nodejs/node/pull/45792 tls: * (SEMVER-MINOR) add "ca" property to certificate object (Ben Noordhuis) https://github.com/nodejs/node/pull/44935 * remove trustcor root ca certificates (Ben Noordhuis) https://github.com/nodejs/node/pull/45776 tools: * update certdata.txt (Luigi Pinca) https://github.com/nodejs/node/pull/45490 util: * add fast path for utf8 encoding (Yagiz Nizipli) https://github.com/nodejs/node/pull/45412 * improve textdecoder decode performance (Yagiz Nizipli) https://github.com/nodejs/node/pull/45294 * (SEMVER-MINOR) add MIME utilities (#21128) (Bradley Farias) https://github.com/nodejs/node/pull/21128 PR-URL: https://github.com/nodejs/node/pull/46025
2022-12-30 15:18:44 -05:00
added:
- v19.3.0
- v18.13.0
-->
Resets the call history of the mock function.
### `ctx.restore()`
<!-- YAML
2023-01-05, Version 18.13.0 'Hydrogen' (LTS) Notable changes: Add support for externally shared js builtins: By default Node.js is built so that all dependencies are bundled into the Node.js binary itself. Some Node.js distributions prefer to manage dependencies externally. There are existing build options that allow dependencies with native code to be externalized. This commit adds additional options so that dependencies with JavaScript code (including WASM) can also be externalized. This addition does not affect binaries shipped by the Node.js project but will allow other distributions to externalize additional dependencies when needed. Contributed by Michael Dawson in https://github.com/nodejs/node/pull/44376 Introduce `File`: The File class is part of the [FileAPI](https://w3c.github.io/FileAPI/). It can be used anywhere a Blob can, for example in `URL.createObjectURL` and `FormData`. It contains two properties that Blobs do not have: `lastModified`, the last time the file was modified in ms, and `name`, the name of the file. Contributed by Khafra in https://github.com/nodejs/node/pull/45139 Support function mocking on Node.js test runner: The `node:test` module supports mocking during testing via a top-level `mock` object. ```js test('spies on an object method', (t) => { const number = { value: 5, add(a) { return this.value + a; }, }; t.mock.method(number, 'add'); assert.strictEqual(number.add(3), 8); assert.strictEqual(number.add.mock.calls.length, 1); }); ``` Contributed by Colin Ihrig in https://github.com/nodejs/node/pull/45326 Other notable changes: build: * disable v8 snapshot compression by default (Joyee Cheung) https://github.com/nodejs/node/pull/45716 crypto: * update root certificates (Luigi Pinca) https://github.com/nodejs/node/pull/45490 deps: * update ICU to 72.1 (Michaël Zasso) https://github.com/nodejs/node/pull/45068 doc: * add doc-only deprecation for headers/trailers setters (Rich Trott) https://github.com/nodejs/node/pull/45697 * add Rafael to the tsc (Michael Dawson) https://github.com/nodejs/node/pull/45691 * deprecate use of invalid ports in `url.parse` (Antoine du Hamel) https://github.com/nodejs/node/pull/45576 * add lukekarrys to collaborators (Luke Karrys) https://github.com/nodejs/node/pull/45180 * add anonrig to collaborators (Yagiz Nizipli) https://github.com/nodejs/node/pull/45002 * deprecate url.parse() (Rich Trott) https://github.com/nodejs/node/pull/44919 lib: * drop fetch experimental warning (Matteo Collina) https://github.com/nodejs/node/pull/45287 net: * (SEMVER-MINOR) add autoSelectFamily and autoSelectFamilyAttemptTimeout options (Paolo Insogna) https://github.com/nodejs/node/pull/44731 * src: * (SEMVER-MINOR) add uvwasi version (Jithil P Ponnan) https://github.com/nodejs/node/pull/45639 * (SEMVER-MINOR) add initial shadow realm support (Chengzhong Wu) https://github.com/nodejs/node/pull/42869 test_runner: * (SEMVER-MINOR) add t.after() hook (Colin Ihrig) https://github.com/nodejs/node/pull/45792 * (SEMVER-MINOR) don't use a symbol for runHook() (Colin Ihrig) https://github.com/nodejs/node/pull/45792 tls: * (SEMVER-MINOR) add "ca" property to certificate object (Ben Noordhuis) https://github.com/nodejs/node/pull/44935 * remove trustcor root ca certificates (Ben Noordhuis) https://github.com/nodejs/node/pull/45776 tools: * update certdata.txt (Luigi Pinca) https://github.com/nodejs/node/pull/45490 util: * add fast path for utf8 encoding (Yagiz Nizipli) https://github.com/nodejs/node/pull/45412 * improve textdecoder decode performance (Yagiz Nizipli) https://github.com/nodejs/node/pull/45294 * (SEMVER-MINOR) add MIME utilities (#21128) (Bradley Farias) https://github.com/nodejs/node/pull/21128 PR-URL: https://github.com/nodejs/node/pull/46025
2022-12-30 15:18:44 -05:00
added:
- v19.1.0
- v18.13.0
-->
Resets the implementation of the mock function to its original behavior. The
mock can still be used after calling this function.
## Class: `MockModuleContext`
<!-- YAML
added:
- v22.3.0
- v20.18.0
-->
> Stability: 1.0 - Early development
The `MockModuleContext` class is used to manipulate the behavior of module mocks
created via the [`MockTracker`][] APIs.
### `ctx.restore()`
<!-- YAML
added:
- v22.3.0
- v20.18.0
-->
Resets the implementation of the mock module.
## Class: `MockTracker`
<!-- YAML
2023-01-05, Version 18.13.0 'Hydrogen' (LTS) Notable changes: Add support for externally shared js builtins: By default Node.js is built so that all dependencies are bundled into the Node.js binary itself. Some Node.js distributions prefer to manage dependencies externally. There are existing build options that allow dependencies with native code to be externalized. This commit adds additional options so that dependencies with JavaScript code (including WASM) can also be externalized. This addition does not affect binaries shipped by the Node.js project but will allow other distributions to externalize additional dependencies when needed. Contributed by Michael Dawson in https://github.com/nodejs/node/pull/44376 Introduce `File`: The File class is part of the [FileAPI](https://w3c.github.io/FileAPI/). It can be used anywhere a Blob can, for example in `URL.createObjectURL` and `FormData`. It contains two properties that Blobs do not have: `lastModified`, the last time the file was modified in ms, and `name`, the name of the file. Contributed by Khafra in https://github.com/nodejs/node/pull/45139 Support function mocking on Node.js test runner: The `node:test` module supports mocking during testing via a top-level `mock` object. ```js test('spies on an object method', (t) => { const number = { value: 5, add(a) { return this.value + a; }, }; t.mock.method(number, 'add'); assert.strictEqual(number.add(3), 8); assert.strictEqual(number.add.mock.calls.length, 1); }); ``` Contributed by Colin Ihrig in https://github.com/nodejs/node/pull/45326 Other notable changes: build: * disable v8 snapshot compression by default (Joyee Cheung) https://github.com/nodejs/node/pull/45716 crypto: * update root certificates (Luigi Pinca) https://github.com/nodejs/node/pull/45490 deps: * update ICU to 72.1 (Michaël Zasso) https://github.com/nodejs/node/pull/45068 doc: * add doc-only deprecation for headers/trailers setters (Rich Trott) https://github.com/nodejs/node/pull/45697 * add Rafael to the tsc (Michael Dawson) https://github.com/nodejs/node/pull/45691 * deprecate use of invalid ports in `url.parse` (Antoine du Hamel) https://github.com/nodejs/node/pull/45576 * add lukekarrys to collaborators (Luke Karrys) https://github.com/nodejs/node/pull/45180 * add anonrig to collaborators (Yagiz Nizipli) https://github.com/nodejs/node/pull/45002 * deprecate url.parse() (Rich Trott) https://github.com/nodejs/node/pull/44919 lib: * drop fetch experimental warning (Matteo Collina) https://github.com/nodejs/node/pull/45287 net: * (SEMVER-MINOR) add autoSelectFamily and autoSelectFamilyAttemptTimeout options (Paolo Insogna) https://github.com/nodejs/node/pull/44731 * src: * (SEMVER-MINOR) add uvwasi version (Jithil P Ponnan) https://github.com/nodejs/node/pull/45639 * (SEMVER-MINOR) add initial shadow realm support (Chengzhong Wu) https://github.com/nodejs/node/pull/42869 test_runner: * (SEMVER-MINOR) add t.after() hook (Colin Ihrig) https://github.com/nodejs/node/pull/45792 * (SEMVER-MINOR) don't use a symbol for runHook() (Colin Ihrig) https://github.com/nodejs/node/pull/45792 tls: * (SEMVER-MINOR) add "ca" property to certificate object (Ben Noordhuis) https://github.com/nodejs/node/pull/44935 * remove trustcor root ca certificates (Ben Noordhuis) https://github.com/nodejs/node/pull/45776 tools: * update certdata.txt (Luigi Pinca) https://github.com/nodejs/node/pull/45490 util: * add fast path for utf8 encoding (Yagiz Nizipli) https://github.com/nodejs/node/pull/45412 * improve textdecoder decode performance (Yagiz Nizipli) https://github.com/nodejs/node/pull/45294 * (SEMVER-MINOR) add MIME utilities (#21128) (Bradley Farias) https://github.com/nodejs/node/pull/21128 PR-URL: https://github.com/nodejs/node/pull/46025
2022-12-30 15:18:44 -05:00
added:
- v19.1.0
- v18.13.0
-->
The `MockTracker` class is used to manage mocking functionality. The test runner
module provides a top level `mock` export which is a `MockTracker` instance.
Each test also provides its own `MockTracker` instance via the test context's
`mock` property.
### `mock.fn([original[, implementation]][, options])`
<!-- YAML
2023-01-05, Version 18.13.0 'Hydrogen' (LTS) Notable changes: Add support for externally shared js builtins: By default Node.js is built so that all dependencies are bundled into the Node.js binary itself. Some Node.js distributions prefer to manage dependencies externally. There are existing build options that allow dependencies with native code to be externalized. This commit adds additional options so that dependencies with JavaScript code (including WASM) can also be externalized. This addition does not affect binaries shipped by the Node.js project but will allow other distributions to externalize additional dependencies when needed. Contributed by Michael Dawson in https://github.com/nodejs/node/pull/44376 Introduce `File`: The File class is part of the [FileAPI](https://w3c.github.io/FileAPI/). It can be used anywhere a Blob can, for example in `URL.createObjectURL` and `FormData`. It contains two properties that Blobs do not have: `lastModified`, the last time the file was modified in ms, and `name`, the name of the file. Contributed by Khafra in https://github.com/nodejs/node/pull/45139 Support function mocking on Node.js test runner: The `node:test` module supports mocking during testing via a top-level `mock` object. ```js test('spies on an object method', (t) => { const number = { value: 5, add(a) { return this.value + a; }, }; t.mock.method(number, 'add'); assert.strictEqual(number.add(3), 8); assert.strictEqual(number.add.mock.calls.length, 1); }); ``` Contributed by Colin Ihrig in https://github.com/nodejs/node/pull/45326 Other notable changes: build: * disable v8 snapshot compression by default (Joyee Cheung) https://github.com/nodejs/node/pull/45716 crypto: * update root certificates (Luigi Pinca) https://github.com/nodejs/node/pull/45490 deps: * update ICU to 72.1 (Michaël Zasso) https://github.com/nodejs/node/pull/45068 doc: * add doc-only deprecation for headers/trailers setters (Rich Trott) https://github.com/nodejs/node/pull/45697 * add Rafael to the tsc (Michael Dawson) https://github.com/nodejs/node/pull/45691 * deprecate use of invalid ports in `url.parse` (Antoine du Hamel) https://github.com/nodejs/node/pull/45576 * add lukekarrys to collaborators (Luke Karrys) https://github.com/nodejs/node/pull/45180 * add anonrig to collaborators (Yagiz Nizipli) https://github.com/nodejs/node/pull/45002 * deprecate url.parse() (Rich Trott) https://github.com/nodejs/node/pull/44919 lib: * drop fetch experimental warning (Matteo Collina) https://github.com/nodejs/node/pull/45287 net: * (SEMVER-MINOR) add autoSelectFamily and autoSelectFamilyAttemptTimeout options (Paolo Insogna) https://github.com/nodejs/node/pull/44731 * src: * (SEMVER-MINOR) add uvwasi version (Jithil P Ponnan) https://github.com/nodejs/node/pull/45639 * (SEMVER-MINOR) add initial shadow realm support (Chengzhong Wu) https://github.com/nodejs/node/pull/42869 test_runner: * (SEMVER-MINOR) add t.after() hook (Colin Ihrig) https://github.com/nodejs/node/pull/45792 * (SEMVER-MINOR) don't use a symbol for runHook() (Colin Ihrig) https://github.com/nodejs/node/pull/45792 tls: * (SEMVER-MINOR) add "ca" property to certificate object (Ben Noordhuis) https://github.com/nodejs/node/pull/44935 * remove trustcor root ca certificates (Ben Noordhuis) https://github.com/nodejs/node/pull/45776 tools: * update certdata.txt (Luigi Pinca) https://github.com/nodejs/node/pull/45490 util: * add fast path for utf8 encoding (Yagiz Nizipli) https://github.com/nodejs/node/pull/45412 * improve textdecoder decode performance (Yagiz Nizipli) https://github.com/nodejs/node/pull/45294 * (SEMVER-MINOR) add MIME utilities (#21128) (Bradley Farias) https://github.com/nodejs/node/pull/21128 PR-URL: https://github.com/nodejs/node/pull/46025
2022-12-30 15:18:44 -05:00
added:
- v19.1.0
- v18.13.0
-->
* `original` {Function|AsyncFunction} An optional function to create a mock on.
**Default:** A no-op function.
* `implementation` {Function|AsyncFunction} An optional function used as the
mock implementation for `original`. This is useful for creating mocks that
exhibit one behavior for a specified number of calls and then restore the
behavior of `original`. **Default:** The function specified by `original`.
* `options` {Object} Optional configuration options for the mock function. The
following properties are supported:
* `times` {integer} The number of times that the mock will use the behavior of
`implementation`. Once the mock function has been called `times` times, it
will automatically restore the behavior of `original`. This value must be an
integer greater than zero. **Default:** `Infinity`.
* Returns: {Proxy} The mocked function. The mocked function contains a special
`mock` property, which is an instance of [`MockFunctionContext`][], and can
be used for inspecting and changing the behavior of the mocked function.
This function is used to create a mock function.
The following example creates a mock function that increments a counter by one
on each invocation. The `times` option is used to modify the mock behavior such
that the first two invocations add two to the counter instead of one.
```js
test('mocks a counting function', (t) => {
let cnt = 0;
function addOne() {
cnt++;
return cnt;
}
function addTwo() {
cnt += 2;
return cnt;
}
const fn = t.mock.fn(addOne, addTwo, { times: 2 });
assert.strictEqual(fn(), 2);
assert.strictEqual(fn(), 4);
assert.strictEqual(fn(), 5);
assert.strictEqual(fn(), 6);
});
```
### `mock.getter(object, methodName[, implementation][, options])`
<!-- YAML
2023-01-05, Version 18.13.0 'Hydrogen' (LTS) Notable changes: Add support for externally shared js builtins: By default Node.js is built so that all dependencies are bundled into the Node.js binary itself. Some Node.js distributions prefer to manage dependencies externally. There are existing build options that allow dependencies with native code to be externalized. This commit adds additional options so that dependencies with JavaScript code (including WASM) can also be externalized. This addition does not affect binaries shipped by the Node.js project but will allow other distributions to externalize additional dependencies when needed. Contributed by Michael Dawson in https://github.com/nodejs/node/pull/44376 Introduce `File`: The File class is part of the [FileAPI](https://w3c.github.io/FileAPI/). It can be used anywhere a Blob can, for example in `URL.createObjectURL` and `FormData`. It contains two properties that Blobs do not have: `lastModified`, the last time the file was modified in ms, and `name`, the name of the file. Contributed by Khafra in https://github.com/nodejs/node/pull/45139 Support function mocking on Node.js test runner: The `node:test` module supports mocking during testing via a top-level `mock` object. ```js test('spies on an object method', (t) => { const number = { value: 5, add(a) { return this.value + a; }, }; t.mock.method(number, 'add'); assert.strictEqual(number.add(3), 8); assert.strictEqual(number.add.mock.calls.length, 1); }); ``` Contributed by Colin Ihrig in https://github.com/nodejs/node/pull/45326 Other notable changes: build: * disable v8 snapshot compression by default (Joyee Cheung) https://github.com/nodejs/node/pull/45716 crypto: * update root certificates (Luigi Pinca) https://github.com/nodejs/node/pull/45490 deps: * update ICU to 72.1 (Michaël Zasso) https://github.com/nodejs/node/pull/45068 doc: * add doc-only deprecation for headers/trailers setters (Rich Trott) https://github.com/nodejs/node/pull/45697 * add Rafael to the tsc (Michael Dawson) https://github.com/nodejs/node/pull/45691 * deprecate use of invalid ports in `url.parse` (Antoine du Hamel) https://github.com/nodejs/node/pull/45576 * add lukekarrys to collaborators (Luke Karrys) https://github.com/nodejs/node/pull/45180 * add anonrig to collaborators (Yagiz Nizipli) https://github.com/nodejs/node/pull/45002 * deprecate url.parse() (Rich Trott) https://github.com/nodejs/node/pull/44919 lib: * drop fetch experimental warning (Matteo Collina) https://github.com/nodejs/node/pull/45287 net: * (SEMVER-MINOR) add autoSelectFamily and autoSelectFamilyAttemptTimeout options (Paolo Insogna) https://github.com/nodejs/node/pull/44731 * src: * (SEMVER-MINOR) add uvwasi version (Jithil P Ponnan) https://github.com/nodejs/node/pull/45639 * (SEMVER-MINOR) add initial shadow realm support (Chengzhong Wu) https://github.com/nodejs/node/pull/42869 test_runner: * (SEMVER-MINOR) add t.after() hook (Colin Ihrig) https://github.com/nodejs/node/pull/45792 * (SEMVER-MINOR) don't use a symbol for runHook() (Colin Ihrig) https://github.com/nodejs/node/pull/45792 tls: * (SEMVER-MINOR) add "ca" property to certificate object (Ben Noordhuis) https://github.com/nodejs/node/pull/44935 * remove trustcor root ca certificates (Ben Noordhuis) https://github.com/nodejs/node/pull/45776 tools: * update certdata.txt (Luigi Pinca) https://github.com/nodejs/node/pull/45490 util: * add fast path for utf8 encoding (Yagiz Nizipli) https://github.com/nodejs/node/pull/45412 * improve textdecoder decode performance (Yagiz Nizipli) https://github.com/nodejs/node/pull/45294 * (SEMVER-MINOR) add MIME utilities (#21128) (Bradley Farias) https://github.com/nodejs/node/pull/21128 PR-URL: https://github.com/nodejs/node/pull/46025
2022-12-30 15:18:44 -05:00
added:
- v19.3.0
- v18.13.0
-->
This function is syntax sugar for [`MockTracker.method`][] with `options.getter`
set to `true`.
### `mock.method(object, methodName[, implementation][, options])`
<!-- YAML
2023-01-05, Version 18.13.0 'Hydrogen' (LTS) Notable changes: Add support for externally shared js builtins: By default Node.js is built so that all dependencies are bundled into the Node.js binary itself. Some Node.js distributions prefer to manage dependencies externally. There are existing build options that allow dependencies with native code to be externalized. This commit adds additional options so that dependencies with JavaScript code (including WASM) can also be externalized. This addition does not affect binaries shipped by the Node.js project but will allow other distributions to externalize additional dependencies when needed. Contributed by Michael Dawson in https://github.com/nodejs/node/pull/44376 Introduce `File`: The File class is part of the [FileAPI](https://w3c.github.io/FileAPI/). It can be used anywhere a Blob can, for example in `URL.createObjectURL` and `FormData`. It contains two properties that Blobs do not have: `lastModified`, the last time the file was modified in ms, and `name`, the name of the file. Contributed by Khafra in https://github.com/nodejs/node/pull/45139 Support function mocking on Node.js test runner: The `node:test` module supports mocking during testing via a top-level `mock` object. ```js test('spies on an object method', (t) => { const number = { value: 5, add(a) { return this.value + a; }, }; t.mock.method(number, 'add'); assert.strictEqual(number.add(3), 8); assert.strictEqual(number.add.mock.calls.length, 1); }); ``` Contributed by Colin Ihrig in https://github.com/nodejs/node/pull/45326 Other notable changes: build: * disable v8 snapshot compression by default (Joyee Cheung) https://github.com/nodejs/node/pull/45716 crypto: * update root certificates (Luigi Pinca) https://github.com/nodejs/node/pull/45490 deps: * update ICU to 72.1 (Michaël Zasso) https://github.com/nodejs/node/pull/45068 doc: * add doc-only deprecation for headers/trailers setters (Rich Trott) https://github.com/nodejs/node/pull/45697 * add Rafael to the tsc (Michael Dawson) https://github.com/nodejs/node/pull/45691 * deprecate use of invalid ports in `url.parse` (Antoine du Hamel) https://github.com/nodejs/node/pull/45576 * add lukekarrys to collaborators (Luke Karrys) https://github.com/nodejs/node/pull/45180 * add anonrig to collaborators (Yagiz Nizipli) https://github.com/nodejs/node/pull/45002 * deprecate url.parse() (Rich Trott) https://github.com/nodejs/node/pull/44919 lib: * drop fetch experimental warning (Matteo Collina) https://github.com/nodejs/node/pull/45287 net: * (SEMVER-MINOR) add autoSelectFamily and autoSelectFamilyAttemptTimeout options (Paolo Insogna) https://github.com/nodejs/node/pull/44731 * src: * (SEMVER-MINOR) add uvwasi version (Jithil P Ponnan) https://github.com/nodejs/node/pull/45639 * (SEMVER-MINOR) add initial shadow realm support (Chengzhong Wu) https://github.com/nodejs/node/pull/42869 test_runner: * (SEMVER-MINOR) add t.after() hook (Colin Ihrig) https://github.com/nodejs/node/pull/45792 * (SEMVER-MINOR) don't use a symbol for runHook() (Colin Ihrig) https://github.com/nodejs/node/pull/45792 tls: * (SEMVER-MINOR) add "ca" property to certificate object (Ben Noordhuis) https://github.com/nodejs/node/pull/44935 * remove trustcor root ca certificates (Ben Noordhuis) https://github.com/nodejs/node/pull/45776 tools: * update certdata.txt (Luigi Pinca) https://github.com/nodejs/node/pull/45490 util: * add fast path for utf8 encoding (Yagiz Nizipli) https://github.com/nodejs/node/pull/45412 * improve textdecoder decode performance (Yagiz Nizipli) https://github.com/nodejs/node/pull/45294 * (SEMVER-MINOR) add MIME utilities (#21128) (Bradley Farias) https://github.com/nodejs/node/pull/21128 PR-URL: https://github.com/nodejs/node/pull/46025
2022-12-30 15:18:44 -05:00
added:
- v19.1.0
- v18.13.0
-->
* `object` {Object} The object whose method is being mocked.
* `methodName` {string|symbol} The identifier of the method on `object` to mock.
If `object[methodName]` is not a function, an error is thrown.
* `implementation` {Function|AsyncFunction} An optional function used as the
mock implementation for `object[methodName]`. **Default:** The original method
specified by `object[methodName]`.
* `options` {Object} Optional configuration options for the mock method. The
following properties are supported:
* `getter` {boolean} If `true`, `object[methodName]` is treated as a getter.
This option cannot be used with the `setter` option. **Default:** false.
* `setter` {boolean} If `true`, `object[methodName]` is treated as a setter.
This option cannot be used with the `getter` option. **Default:** false.
* `times` {integer} The number of times that the mock will use the behavior of
`implementation`. Once the mocked method has been called `times` times, it
will automatically restore the original behavior. This value must be an
integer greater than zero. **Default:** `Infinity`.
* Returns: {Proxy} The mocked method. The mocked method contains a special
`mock` property, which is an instance of [`MockFunctionContext`][], and can
be used for inspecting and changing the behavior of the mocked method.
This function is used to create a mock on an existing object method. The
following example demonstrates how a mock is created on an existing object
method.
```js
test('spies on an object method', (t) => {
const number = {
value: 5,
subtract(a) {
return this.value - a;
},
};
t.mock.method(number, 'subtract');
assert.strictEqual(number.subtract.mock.callCount(), 0);
assert.strictEqual(number.subtract(3), 2);
assert.strictEqual(number.subtract.mock.callCount(), 1);
const call = number.subtract.mock.calls[0];
assert.deepStrictEqual(call.arguments, [3]);
assert.strictEqual(call.result, 2);
assert.strictEqual(call.error, undefined);
assert.strictEqual(call.target, undefined);
assert.strictEqual(call.this, number);
});
```
### `mock.module(specifier[, options])`
<!-- YAML
added:
- v22.3.0
- v20.18.0
changes:
- version:
- REPLACEME
pr-url: https://github.com/nodejs/node/pull/58007
description: Support JSON modules.
-->
> Stability: 1.0 - Early development
* `specifier` {string|URL} A string identifying the module to mock.
* `options` {Object} Optional configuration options for the mock module. The
following properties are supported:
* `cache` {boolean} If `false`, each call to `require()` or `import()`
generates a new mock module. If `true`, subsequent calls will return the same
module mock, and the mock module is inserted into the CommonJS cache.
**Default:** false.
* `defaultExport` {any} An optional value used as the mocked module's default
export. If this value is not provided, ESM mocks do not include a default
export. If the mock is a CommonJS or builtin module, this setting is used as
the value of `module.exports`. If this value is not provided, CJS and builtin
mocks use an empty object as the value of `module.exports`.
* `namedExports` {Object} An optional object whose keys and values are used to
create the named exports of the mock module. If the mock is a CommonJS or
builtin module, these values are copied onto `module.exports`. Therefore, if a
mock is created with both named exports and a non-object default export, the
mock will throw an exception when used as a CJS or builtin module.
* Returns: {MockModuleContext} An object that can be used to manipulate the mock.
This function is used to mock the exports of ECMAScript modules, CommonJS modules, JSON modules, and
Node.js builtin modules. Any references to the original module prior to mocking are not impacted. In
order to enable module mocking, Node.js must be started with the
[`--experimental-test-module-mocks`][] command-line flag.
The following example demonstrates how a mock is created for a module.
```js
test('mocks a builtin module in both module systems', async (t) => {
// Create a mock of 'node:readline' with a named export named 'fn', which
// does not exist in the original 'node:readline' module.
const mock = t.mock.module('node:readline', {
namedExports: { fn() { return 42; } },
});
let esmImpl = await import('node:readline');
let cjsImpl = require('node:readline');
// cursorTo() is an export of the original 'node:readline' module.
assert.strictEqual(esmImpl.cursorTo, undefined);
assert.strictEqual(cjsImpl.cursorTo, undefined);
assert.strictEqual(esmImpl.fn(), 42);
assert.strictEqual(cjsImpl.fn(), 42);
mock.restore();
// The mock is restored, so the original builtin module is returned.
esmImpl = await import('node:readline');
cjsImpl = require('node:readline');
assert.strictEqual(typeof esmImpl.cursorTo, 'function');
assert.strictEqual(typeof cjsImpl.cursorTo, 'function');
assert.strictEqual(esmImpl.fn, undefined);
assert.strictEqual(cjsImpl.fn, undefined);
});
```
### `mock.reset()`
<!-- YAML
2023-01-05, Version 18.13.0 'Hydrogen' (LTS) Notable changes: Add support for externally shared js builtins: By default Node.js is built so that all dependencies are bundled into the Node.js binary itself. Some Node.js distributions prefer to manage dependencies externally. There are existing build options that allow dependencies with native code to be externalized. This commit adds additional options so that dependencies with JavaScript code (including WASM) can also be externalized. This addition does not affect binaries shipped by the Node.js project but will allow other distributions to externalize additional dependencies when needed. Contributed by Michael Dawson in https://github.com/nodejs/node/pull/44376 Introduce `File`: The File class is part of the [FileAPI](https://w3c.github.io/FileAPI/). It can be used anywhere a Blob can, for example in `URL.createObjectURL` and `FormData`. It contains two properties that Blobs do not have: `lastModified`, the last time the file was modified in ms, and `name`, the name of the file. Contributed by Khafra in https://github.com/nodejs/node/pull/45139 Support function mocking on Node.js test runner: The `node:test` module supports mocking during testing via a top-level `mock` object. ```js test('spies on an object method', (t) => { const number = { value: 5, add(a) { return this.value + a; }, }; t.mock.method(number, 'add'); assert.strictEqual(number.add(3), 8); assert.strictEqual(number.add.mock.calls.length, 1); }); ``` Contributed by Colin Ihrig in https://github.com/nodejs/node/pull/45326 Other notable changes: build: * disable v8 snapshot compression by default (Joyee Cheung) https://github.com/nodejs/node/pull/45716 crypto: * update root certificates (Luigi Pinca) https://github.com/nodejs/node/pull/45490 deps: * update ICU to 72.1 (Michaël Zasso) https://github.com/nodejs/node/pull/45068 doc: * add doc-only deprecation for headers/trailers setters (Rich Trott) https://github.com/nodejs/node/pull/45697 * add Rafael to the tsc (Michael Dawson) https://github.com/nodejs/node/pull/45691 * deprecate use of invalid ports in `url.parse` (Antoine du Hamel) https://github.com/nodejs/node/pull/45576 * add lukekarrys to collaborators (Luke Karrys) https://github.com/nodejs/node/pull/45180 * add anonrig to collaborators (Yagiz Nizipli) https://github.com/nodejs/node/pull/45002 * deprecate url.parse() (Rich Trott) https://github.com/nodejs/node/pull/44919 lib: * drop fetch experimental warning (Matteo Collina) https://github.com/nodejs/node/pull/45287 net: * (SEMVER-MINOR) add autoSelectFamily and autoSelectFamilyAttemptTimeout options (Paolo Insogna) https://github.com/nodejs/node/pull/44731 * src: * (SEMVER-MINOR) add uvwasi version (Jithil P Ponnan) https://github.com/nodejs/node/pull/45639 * (SEMVER-MINOR) add initial shadow realm support (Chengzhong Wu) https://github.com/nodejs/node/pull/42869 test_runner: * (SEMVER-MINOR) add t.after() hook (Colin Ihrig) https://github.com/nodejs/node/pull/45792 * (SEMVER-MINOR) don't use a symbol for runHook() (Colin Ihrig) https://github.com/nodejs/node/pull/45792 tls: * (SEMVER-MINOR) add "ca" property to certificate object (Ben Noordhuis) https://github.com/nodejs/node/pull/44935 * remove trustcor root ca certificates (Ben Noordhuis) https://github.com/nodejs/node/pull/45776 tools: * update certdata.txt (Luigi Pinca) https://github.com/nodejs/node/pull/45490 util: * add fast path for utf8 encoding (Yagiz Nizipli) https://github.com/nodejs/node/pull/45412 * improve textdecoder decode performance (Yagiz Nizipli) https://github.com/nodejs/node/pull/45294 * (SEMVER-MINOR) add MIME utilities (#21128) (Bradley Farias) https://github.com/nodejs/node/pull/21128 PR-URL: https://github.com/nodejs/node/pull/46025
2022-12-30 15:18:44 -05:00
added:
- v19.1.0
- v18.13.0
-->
This function restores the default behavior of all mocks that were previously
created by this `MockTracker` and disassociates the mocks from the
`MockTracker` instance. Once disassociated, the mocks can still be used, but the
`MockTracker` instance can no longer be used to reset their behavior or
otherwise interact with them.
After each test completes, this function is called on the test context's
`MockTracker`. If the global `MockTracker` is used extensively, calling this
function manually is recommended.
### `mock.restoreAll()`
<!-- YAML
2023-01-05, Version 18.13.0 'Hydrogen' (LTS) Notable changes: Add support for externally shared js builtins: By default Node.js is built so that all dependencies are bundled into the Node.js binary itself. Some Node.js distributions prefer to manage dependencies externally. There are existing build options that allow dependencies with native code to be externalized. This commit adds additional options so that dependencies with JavaScript code (including WASM) can also be externalized. This addition does not affect binaries shipped by the Node.js project but will allow other distributions to externalize additional dependencies when needed. Contributed by Michael Dawson in https://github.com/nodejs/node/pull/44376 Introduce `File`: The File class is part of the [FileAPI](https://w3c.github.io/FileAPI/). It can be used anywhere a Blob can, for example in `URL.createObjectURL` and `FormData`. It contains two properties that Blobs do not have: `lastModified`, the last time the file was modified in ms, and `name`, the name of the file. Contributed by Khafra in https://github.com/nodejs/node/pull/45139 Support function mocking on Node.js test runner: The `node:test` module supports mocking during testing via a top-level `mock` object. ```js test('spies on an object method', (t) => { const number = { value: 5, add(a) { return this.value + a; }, }; t.mock.method(number, 'add'); assert.strictEqual(number.add(3), 8); assert.strictEqual(number.add.mock.calls.length, 1); }); ``` Contributed by Colin Ihrig in https://github.com/nodejs/node/pull/45326 Other notable changes: build: * disable v8 snapshot compression by default (Joyee Cheung) https://github.com/nodejs/node/pull/45716 crypto: * update root certificates (Luigi Pinca) https://github.com/nodejs/node/pull/45490 deps: * update ICU to 72.1 (Michaël Zasso) https://github.com/nodejs/node/pull/45068 doc: * add doc-only deprecation for headers/trailers setters (Rich Trott) https://github.com/nodejs/node/pull/45697 * add Rafael to the tsc (Michael Dawson) https://github.com/nodejs/node/pull/45691 * deprecate use of invalid ports in `url.parse` (Antoine du Hamel) https://github.com/nodejs/node/pull/45576 * add lukekarrys to collaborators (Luke Karrys) https://github.com/nodejs/node/pull/45180 * add anonrig to collaborators (Yagiz Nizipli) https://github.com/nodejs/node/pull/45002 * deprecate url.parse() (Rich Trott) https://github.com/nodejs/node/pull/44919 lib: * drop fetch experimental warning (Matteo Collina) https://github.com/nodejs/node/pull/45287 net: * (SEMVER-MINOR) add autoSelectFamily and autoSelectFamilyAttemptTimeout options (Paolo Insogna) https://github.com/nodejs/node/pull/44731 * src: * (SEMVER-MINOR) add uvwasi version (Jithil P Ponnan) https://github.com/nodejs/node/pull/45639 * (SEMVER-MINOR) add initial shadow realm support (Chengzhong Wu) https://github.com/nodejs/node/pull/42869 test_runner: * (SEMVER-MINOR) add t.after() hook (Colin Ihrig) https://github.com/nodejs/node/pull/45792 * (SEMVER-MINOR) don't use a symbol for runHook() (Colin Ihrig) https://github.com/nodejs/node/pull/45792 tls: * (SEMVER-MINOR) add "ca" property to certificate object (Ben Noordhuis) https://github.com/nodejs/node/pull/44935 * remove trustcor root ca certificates (Ben Noordhuis) https://github.com/nodejs/node/pull/45776 tools: * update certdata.txt (Luigi Pinca) https://github.com/nodejs/node/pull/45490 util: * add fast path for utf8 encoding (Yagiz Nizipli) https://github.com/nodejs/node/pull/45412 * improve textdecoder decode performance (Yagiz Nizipli) https://github.com/nodejs/node/pull/45294 * (SEMVER-MINOR) add MIME utilities (#21128) (Bradley Farias) https://github.com/nodejs/node/pull/21128 PR-URL: https://github.com/nodejs/node/pull/46025
2022-12-30 15:18:44 -05:00
added:
- v19.1.0
- v18.13.0
-->
This function restores the default behavior of all mocks that were previously
created by this `MockTracker`. Unlike `mock.reset()`, `mock.restoreAll()` does
not disassociate the mocks from the `MockTracker` instance.
### `mock.setter(object, methodName[, implementation][, options])`
<!-- YAML
2023-01-05, Version 18.13.0 'Hydrogen' (LTS) Notable changes: Add support for externally shared js builtins: By default Node.js is built so that all dependencies are bundled into the Node.js binary itself. Some Node.js distributions prefer to manage dependencies externally. There are existing build options that allow dependencies with native code to be externalized. This commit adds additional options so that dependencies with JavaScript code (including WASM) can also be externalized. This addition does not affect binaries shipped by the Node.js project but will allow other distributions to externalize additional dependencies when needed. Contributed by Michael Dawson in https://github.com/nodejs/node/pull/44376 Introduce `File`: The File class is part of the [FileAPI](https://w3c.github.io/FileAPI/). It can be used anywhere a Blob can, for example in `URL.createObjectURL` and `FormData`. It contains two properties that Blobs do not have: `lastModified`, the last time the file was modified in ms, and `name`, the name of the file. Contributed by Khafra in https://github.com/nodejs/node/pull/45139 Support function mocking on Node.js test runner: The `node:test` module supports mocking during testing via a top-level `mock` object. ```js test('spies on an object method', (t) => { const number = { value: 5, add(a) { return this.value + a; }, }; t.mock.method(number, 'add'); assert.strictEqual(number.add(3), 8); assert.strictEqual(number.add.mock.calls.length, 1); }); ``` Contributed by Colin Ihrig in https://github.com/nodejs/node/pull/45326 Other notable changes: build: * disable v8 snapshot compression by default (Joyee Cheung) https://github.com/nodejs/node/pull/45716 crypto: * update root certificates (Luigi Pinca) https://github.com/nodejs/node/pull/45490 deps: * update ICU to 72.1 (Michaël Zasso) https://github.com/nodejs/node/pull/45068 doc: * add doc-only deprecation for headers/trailers setters (Rich Trott) https://github.com/nodejs/node/pull/45697 * add Rafael to the tsc (Michael Dawson) https://github.com/nodejs/node/pull/45691 * deprecate use of invalid ports in `url.parse` (Antoine du Hamel) https://github.com/nodejs/node/pull/45576 * add lukekarrys to collaborators (Luke Karrys) https://github.com/nodejs/node/pull/45180 * add anonrig to collaborators (Yagiz Nizipli) https://github.com/nodejs/node/pull/45002 * deprecate url.parse() (Rich Trott) https://github.com/nodejs/node/pull/44919 lib: * drop fetch experimental warning (Matteo Collina) https://github.com/nodejs/node/pull/45287 net: * (SEMVER-MINOR) add autoSelectFamily and autoSelectFamilyAttemptTimeout options (Paolo Insogna) https://github.com/nodejs/node/pull/44731 * src: * (SEMVER-MINOR) add uvwasi version (Jithil P Ponnan) https://github.com/nodejs/node/pull/45639 * (SEMVER-MINOR) add initial shadow realm support (Chengzhong Wu) https://github.com/nodejs/node/pull/42869 test_runner: * (SEMVER-MINOR) add t.after() hook (Colin Ihrig) https://github.com/nodejs/node/pull/45792 * (SEMVER-MINOR) don't use a symbol for runHook() (Colin Ihrig) https://github.com/nodejs/node/pull/45792 tls: * (SEMVER-MINOR) add "ca" property to certificate object (Ben Noordhuis) https://github.com/nodejs/node/pull/44935 * remove trustcor root ca certificates (Ben Noordhuis) https://github.com/nodejs/node/pull/45776 tools: * update certdata.txt (Luigi Pinca) https://github.com/nodejs/node/pull/45490 util: * add fast path for utf8 encoding (Yagiz Nizipli) https://github.com/nodejs/node/pull/45412 * improve textdecoder decode performance (Yagiz Nizipli) https://github.com/nodejs/node/pull/45294 * (SEMVER-MINOR) add MIME utilities (#21128) (Bradley Farias) https://github.com/nodejs/node/pull/21128 PR-URL: https://github.com/nodejs/node/pull/46025
2022-12-30 15:18:44 -05:00
added:
- v19.3.0
- v18.13.0
-->
This function is syntax sugar for [`MockTracker.method`][] with `options.setter`
set to `true`.
## Class: `MockTimers`
<!-- YAML
added:
- v20.4.0
2023-11-29, Version 18.19.0 'Hydrogen' (LTS) Notable changes: deps: * (SEMVER-MINOR) update uvwasi to 0.0.19 (Node.js GitHub Bot) https://github.com/nodejs/node/pull/49908 * (SEMVER-MINOR) upgrade npm to 10.2.3 (npm team) https://github.com/nodejs/node/pull/50531 doc: * move and rename loaders section (Geoffrey Booth) https://github.com/nodejs/node/pull/49261 esm: * use import attributes instead of import assertions (Antoine du Hamel) https://github.com/nodejs/node/pull/50140 * --experimental-default-type flag to flip module defaults (Geoffrey Booth) https://github.com/nodejs/node/pull/49869 * unflag import.meta.resolve (Guy Bedford) https://github.com/nodejs/node/pull/49028 * move hook execution to separate thread (Jacob Smith) https://github.com/nodejs/node/pull/44710 * leverage loaders when resolving subsequent loaders (Maël Nison) https://github.com/nodejs/node/pull/43772 lib: * (SEMVER-MINOR) add api to detect whether source-maps are enabled (翠 / green) https://github.com/nodejs/node/pull/46391 * (SEMVER-MINOR) add tracing channel to diagnostics_channel (Stephen Belanger) https://github.com/nodejs/node/pull/44943 src: * (SEMVER-MINOR) add cjs_module_lexer_version base64_version (Jithil P Ponnan) https://github.com/nodejs/node/pull/45629 stream: * use bitmap in readable state (Benjamin Gruenbaum) https://github.com/nodejs/node/pull/49745 test_runner: * (SEMVER-MINOR) accept `testOnly` in `run` (Moshe Atlow) https://github.com/nodejs/node/pull/49753 * (SEMVER-MINOR) add junit reporter (Moshe Atlow) https://github.com/nodejs/node/pull/49614 * (SEMVER-MINOR) expose location of tests (Colin Ihrig) https://github.com/nodejs/node/pull/48975 * (SEMVER-MINOR) add shards support (Raz Luvaton) https://github.com/nodejs/node/pull/48639 * (SEMVER-MINOR) add initial draft for fakeTimers (Erick Wendel) https://github.com/nodejs/node/pull/47775 test_runner, cli: * (SEMVER-MINOR) add --test-concurrency flag (Colin Ihrig) https://github.com/nodejs/node/pull/49996 tls: * (SEMVER-MINOR) add ALPNCallback server option for dynamic ALPN negotiation (Tim Perry) https://github.com/nodejs/node/pull/45190 vm: * (SEMVER-MINOR) use import attributes instead of import assertions (Antoine du Hamel) https://github.com/nodejs/node/pull/50141 PR-URL: https://github.com/nodejs/node/pull/50953
2023-11-27 12:19:49 +01:00
- v18.19.0
changes:
- version: v23.1.0
pr-url: https://github.com/nodejs/node/pull/55398
description: The Mock Timers is now stable.
-->
Mocking timers is a technique commonly used in software testing to simulate and
control the behavior of timers, such as `setInterval` and `setTimeout`,
without actually waiting for the specified time intervals.
MockTimers is also able to mock the `Date` object.
The [`MockTracker`][] provides a top-level `timers` export
which is a `MockTimers` instance.
### `timers.enable([enableOptions])`
<!-- YAML
added:
- v20.4.0
2023-11-29, Version 18.19.0 'Hydrogen' (LTS) Notable changes: deps: * (SEMVER-MINOR) update uvwasi to 0.0.19 (Node.js GitHub Bot) https://github.com/nodejs/node/pull/49908 * (SEMVER-MINOR) upgrade npm to 10.2.3 (npm team) https://github.com/nodejs/node/pull/50531 doc: * move and rename loaders section (Geoffrey Booth) https://github.com/nodejs/node/pull/49261 esm: * use import attributes instead of import assertions (Antoine du Hamel) https://github.com/nodejs/node/pull/50140 * --experimental-default-type flag to flip module defaults (Geoffrey Booth) https://github.com/nodejs/node/pull/49869 * unflag import.meta.resolve (Guy Bedford) https://github.com/nodejs/node/pull/49028 * move hook execution to separate thread (Jacob Smith) https://github.com/nodejs/node/pull/44710 * leverage loaders when resolving subsequent loaders (Maël Nison) https://github.com/nodejs/node/pull/43772 lib: * (SEMVER-MINOR) add api to detect whether source-maps are enabled (翠 / green) https://github.com/nodejs/node/pull/46391 * (SEMVER-MINOR) add tracing channel to diagnostics_channel (Stephen Belanger) https://github.com/nodejs/node/pull/44943 src: * (SEMVER-MINOR) add cjs_module_lexer_version base64_version (Jithil P Ponnan) https://github.com/nodejs/node/pull/45629 stream: * use bitmap in readable state (Benjamin Gruenbaum) https://github.com/nodejs/node/pull/49745 test_runner: * (SEMVER-MINOR) accept `testOnly` in `run` (Moshe Atlow) https://github.com/nodejs/node/pull/49753 * (SEMVER-MINOR) add junit reporter (Moshe Atlow) https://github.com/nodejs/node/pull/49614 * (SEMVER-MINOR) expose location of tests (Colin Ihrig) https://github.com/nodejs/node/pull/48975 * (SEMVER-MINOR) add shards support (Raz Luvaton) https://github.com/nodejs/node/pull/48639 * (SEMVER-MINOR) add initial draft for fakeTimers (Erick Wendel) https://github.com/nodejs/node/pull/47775 test_runner, cli: * (SEMVER-MINOR) add --test-concurrency flag (Colin Ihrig) https://github.com/nodejs/node/pull/49996 tls: * (SEMVER-MINOR) add ALPNCallback server option for dynamic ALPN negotiation (Tim Perry) https://github.com/nodejs/node/pull/45190 vm: * (SEMVER-MINOR) use import attributes instead of import assertions (Antoine du Hamel) https://github.com/nodejs/node/pull/50141 PR-URL: https://github.com/nodejs/node/pull/50953
2023-11-27 12:19:49 +01:00
- v18.19.0
changes:
2024-01-09, Version 20.11.0 'Iron' (LTS) Notable changes: crypto: * update root certificates to NSS 3.95 (Node.js GitHub Bot) https://github.com/nodejs/node/pull/50805 doc: * add MrJithil to collaborators (Jithil P Ponnan) https://github.com/nodejs/node/pull/50666 * add Ethan-Arrowood as a collaborator (Ethan Arrowood) https://github.com/nodejs/node/pull/50393 esm: * (SEMVER-MINOR) add import.meta.dirname and import.meta.filename (James Sumners) https://github.com/nodejs/node/pull/48740 fs: * add c++ fast path for writeFileSync utf8 (CanadaHonk) https://github.com/nodejs/node/pull/49884 module: * (SEMVER-MINOR) remove useCustomLoadersIfPresent flag (Chengzhong Wu) https://github.com/nodejs/node/pull/48655 * (SEMVER-MINOR) bootstrap module loaders in shadow realm (Chengzhong Wu) https://github.com/nodejs/node/pull/48655 src: * (SEMVER-MINOR) add `--disable-warning` option (Ethan Arrowood) https://github.com/nodejs/node/pull/50661 * (SEMVER-MINOR) create per isolate proxy env template (Chengzhong Wu) https://github.com/nodejs/node/pull/48655 * (SEMVER-MINOR) make process binding data weak (Chengzhong Wu) https://github.com/nodejs/node/pull/48655 stream: * use Array for Readable buffer (Robert Nagy) https://github.com/nodejs/node/pull/50341 * optimize creation (Robert Nagy) https://github.com/nodejs/node/pull/50337 test_runner: * (SEMVER-MINOR) adds built in lcov reporter (Phil Nash) https://github.com/nodejs/node/pull/50018 * (SEMVER-MINOR) add Date to the supported mock APIs (Lucas Santos) https://github.com/nodejs/node/pull/48638 test_runner, cli: * (SEMVER-MINOR) add --test-timeout flag (Shubham Pandey) https://github.com/nodejs/node/pull/50443 PR-URL: https://github.com/nodejs/node/pull/51124
2023-12-12 00:10:33 +00:00
- version:
- v21.2.0
- v20.11.0
pr-url: https://github.com/nodejs/node/pull/48638
description: Updated parameters to be an option object with available APIs
and the default initial epoch.
-->
Enables timer mocking for the specified timers.
* `enableOptions` {Object} Optional configuration options for enabling timer
mocking. The following properties are supported:
* `apis` {Array} An optional array containing the timers to mock.
The currently supported timer values are `'setInterval'`, `'setTimeout'`, `'setImmediate'`,
and `'Date'`. **Default:** `['setInterval', 'setTimeout', 'setImmediate', 'Date']`.
If no array is provided, all time related APIs (`'setInterval'`, `'clearInterval'`,
`'setTimeout'`, `'clearTimeout'`, `'setImmediate'`, `'clearImmediate'`, and
`'Date'`) will be mocked by default.
* `now` {number | Date} An optional number or Date object representing the
initial time (in milliseconds) to use as the value
for `Date.now()`. **Default:** `0`.
**Note:** When you enable mocking for a specific timer, its associated
clear function will also be implicitly mocked.
**Note:** Mocking `Date` will affect the behavior of the mocked timers
as they use the same internal clock.
Example usage without setting initial time:
```mjs
import { mock } from 'node:test';
mock.timers.enable({ apis: ['setInterval'] });
```
```cjs
const { mock } = require('node:test');
mock.timers.enable({ apis: ['setInterval'] });
```
The above example enables mocking for the `setInterval` timer and
implicitly mocks the `clearInterval` function. Only the `setInterval`
and `clearInterval` functions from [node:timers](./timers.md),
[node:timers/promises](./timers.md#timers-promises-api), and
`globalThis` will be mocked.
Example usage with initial time set
```mjs
import { mock } from 'node:test';
mock.timers.enable({ apis: ['Date'], now: 1000 });
```
```cjs
const { mock } = require('node:test');
mock.timers.enable({ apis: ['Date'], now: 1000 });
```
Example usage with initial Date object as time set
```mjs
import { mock } from 'node:test';
mock.timers.enable({ apis: ['Date'], now: new Date() });
```
```cjs
const { mock } = require('node:test');
mock.timers.enable({ apis: ['Date'], now: new Date() });
```
Alternatively, if you call `mock.timers.enable()` without any parameters:
All timers (`'setInterval'`, `'clearInterval'`, `'setTimeout'`, `'clearTimeout'`,
`'setImmediate'`, and `'clearImmediate'`) will be mocked. The `setInterval`,
`clearInterval`, `setTimeout`, `clearTimeout`, `setImmediate`, and
`clearImmediate` functions from `node:timers`, `node:timers/promises`, and
`globalThis` will be mocked. As well as the global `Date` object.
### `timers.reset()`
<!-- YAML
added:
- v20.4.0
2023-11-29, Version 18.19.0 'Hydrogen' (LTS) Notable changes: deps: * (SEMVER-MINOR) update uvwasi to 0.0.19 (Node.js GitHub Bot) https://github.com/nodejs/node/pull/49908 * (SEMVER-MINOR) upgrade npm to 10.2.3 (npm team) https://github.com/nodejs/node/pull/50531 doc: * move and rename loaders section (Geoffrey Booth) https://github.com/nodejs/node/pull/49261 esm: * use import attributes instead of import assertions (Antoine du Hamel) https://github.com/nodejs/node/pull/50140 * --experimental-default-type flag to flip module defaults (Geoffrey Booth) https://github.com/nodejs/node/pull/49869 * unflag import.meta.resolve (Guy Bedford) https://github.com/nodejs/node/pull/49028 * move hook execution to separate thread (Jacob Smith) https://github.com/nodejs/node/pull/44710 * leverage loaders when resolving subsequent loaders (Maël Nison) https://github.com/nodejs/node/pull/43772 lib: * (SEMVER-MINOR) add api to detect whether source-maps are enabled (翠 / green) https://github.com/nodejs/node/pull/46391 * (SEMVER-MINOR) add tracing channel to diagnostics_channel (Stephen Belanger) https://github.com/nodejs/node/pull/44943 src: * (SEMVER-MINOR) add cjs_module_lexer_version base64_version (Jithil P Ponnan) https://github.com/nodejs/node/pull/45629 stream: * use bitmap in readable state (Benjamin Gruenbaum) https://github.com/nodejs/node/pull/49745 test_runner: * (SEMVER-MINOR) accept `testOnly` in `run` (Moshe Atlow) https://github.com/nodejs/node/pull/49753 * (SEMVER-MINOR) add junit reporter (Moshe Atlow) https://github.com/nodejs/node/pull/49614 * (SEMVER-MINOR) expose location of tests (Colin Ihrig) https://github.com/nodejs/node/pull/48975 * (SEMVER-MINOR) add shards support (Raz Luvaton) https://github.com/nodejs/node/pull/48639 * (SEMVER-MINOR) add initial draft for fakeTimers (Erick Wendel) https://github.com/nodejs/node/pull/47775 test_runner, cli: * (SEMVER-MINOR) add --test-concurrency flag (Colin Ihrig) https://github.com/nodejs/node/pull/49996 tls: * (SEMVER-MINOR) add ALPNCallback server option for dynamic ALPN negotiation (Tim Perry) https://github.com/nodejs/node/pull/45190 vm: * (SEMVER-MINOR) use import attributes instead of import assertions (Antoine du Hamel) https://github.com/nodejs/node/pull/50141 PR-URL: https://github.com/nodejs/node/pull/50953
2023-11-27 12:19:49 +01:00
- v18.19.0
-->
This function restores the default behavior of all mocks that were previously
created by this `MockTimers` instance and disassociates the mocks
from the `MockTracker` instance.
**Note:** After each test completes, this function is called on
the test context's `MockTracker`.
```mjs
import { mock } from 'node:test';
mock.timers.reset();
```
```cjs
const { mock } = require('node:test');
mock.timers.reset();
```
### `timers[Symbol.dispose]()`
Calls `timers.reset()`.
### `timers.tick([milliseconds])`
<!-- YAML
added:
- v20.4.0
2023-11-29, Version 18.19.0 'Hydrogen' (LTS) Notable changes: deps: * (SEMVER-MINOR) update uvwasi to 0.0.19 (Node.js GitHub Bot) https://github.com/nodejs/node/pull/49908 * (SEMVER-MINOR) upgrade npm to 10.2.3 (npm team) https://github.com/nodejs/node/pull/50531 doc: * move and rename loaders section (Geoffrey Booth) https://github.com/nodejs/node/pull/49261 esm: * use import attributes instead of import assertions (Antoine du Hamel) https://github.com/nodejs/node/pull/50140 * --experimental-default-type flag to flip module defaults (Geoffrey Booth) https://github.com/nodejs/node/pull/49869 * unflag import.meta.resolve (Guy Bedford) https://github.com/nodejs/node/pull/49028 * move hook execution to separate thread (Jacob Smith) https://github.com/nodejs/node/pull/44710 * leverage loaders when resolving subsequent loaders (Maël Nison) https://github.com/nodejs/node/pull/43772 lib: * (SEMVER-MINOR) add api to detect whether source-maps are enabled (翠 / green) https://github.com/nodejs/node/pull/46391 * (SEMVER-MINOR) add tracing channel to diagnostics_channel (Stephen Belanger) https://github.com/nodejs/node/pull/44943 src: * (SEMVER-MINOR) add cjs_module_lexer_version base64_version (Jithil P Ponnan) https://github.com/nodejs/node/pull/45629 stream: * use bitmap in readable state (Benjamin Gruenbaum) https://github.com/nodejs/node/pull/49745 test_runner: * (SEMVER-MINOR) accept `testOnly` in `run` (Moshe Atlow) https://github.com/nodejs/node/pull/49753 * (SEMVER-MINOR) add junit reporter (Moshe Atlow) https://github.com/nodejs/node/pull/49614 * (SEMVER-MINOR) expose location of tests (Colin Ihrig) https://github.com/nodejs/node/pull/48975 * (SEMVER-MINOR) add shards support (Raz Luvaton) https://github.com/nodejs/node/pull/48639 * (SEMVER-MINOR) add initial draft for fakeTimers (Erick Wendel) https://github.com/nodejs/node/pull/47775 test_runner, cli: * (SEMVER-MINOR) add --test-concurrency flag (Colin Ihrig) https://github.com/nodejs/node/pull/49996 tls: * (SEMVER-MINOR) add ALPNCallback server option for dynamic ALPN negotiation (Tim Perry) https://github.com/nodejs/node/pull/45190 vm: * (SEMVER-MINOR) use import attributes instead of import assertions (Antoine du Hamel) https://github.com/nodejs/node/pull/50141 PR-URL: https://github.com/nodejs/node/pull/50953
2023-11-27 12:19:49 +01:00
- v18.19.0
-->
Advances time for all mocked timers.
* `milliseconds` {number} The amount of time, in milliseconds,
to advance the timers. **Default:** `1`.
**Note:** This diverges from how `setTimeout` in Node.js behaves and accepts
only positive numbers. In Node.js, `setTimeout` with negative numbers is
only supported for web compatibility reasons.
The following example mocks a `setTimeout` function and
by using `.tick` advances in
time triggering all pending timers.
```mjs
import assert from 'node:assert';
import { test } from 'node:test';
test('mocks setTimeout to be executed synchronously without having to actually wait for it', (context) => {
const fn = context.mock.fn();
context.mock.timers.enable({ apis: ['setTimeout'] });
setTimeout(fn, 9999);
assert.strictEqual(fn.mock.callCount(), 0);
// Advance in time
context.mock.timers.tick(9999);
assert.strictEqual(fn.mock.callCount(), 1);
});
```
```cjs
const assert = require('node:assert');
const { test } = require('node:test');
test('mocks setTimeout to be executed synchronously without having to actually wait for it', (context) => {
const fn = context.mock.fn();
context.mock.timers.enable({ apis: ['setTimeout'] });
setTimeout(fn, 9999);
assert.strictEqual(fn.mock.callCount(), 0);
// Advance in time
context.mock.timers.tick(9999);
assert.strictEqual(fn.mock.callCount(), 1);
});
```
Alternatively, the `.tick` function can be called many times
```mjs
import assert from 'node:assert';
import { test } from 'node:test';
test('mocks setTimeout to be executed synchronously without having to actually wait for it', (context) => {
const fn = context.mock.fn();
context.mock.timers.enable({ apis: ['setTimeout'] });
const nineSecs = 9000;
setTimeout(fn, nineSecs);
const threeSeconds = 3000;
context.mock.timers.tick(threeSeconds);
context.mock.timers.tick(threeSeconds);
context.mock.timers.tick(threeSeconds);
assert.strictEqual(fn.mock.callCount(), 1);
});
```
```cjs
const assert = require('node:assert');
const { test } = require('node:test');
test('mocks setTimeout to be executed synchronously without having to actually wait for it', (context) => {
const fn = context.mock.fn();
context.mock.timers.enable({ apis: ['setTimeout'] });
const nineSecs = 9000;
setTimeout(fn, nineSecs);
const threeSeconds = 3000;
context.mock.timers.tick(threeSeconds);
context.mock.timers.tick(threeSeconds);
context.mock.timers.tick(threeSeconds);
assert.strictEqual(fn.mock.callCount(), 1);
});
```
Advancing time using `.tick` will also advance the time for any `Date` object
created after the mock was enabled (if `Date` was also set to be mocked).
```mjs
import assert from 'node:assert';
import { test } from 'node:test';
test('mocks setTimeout to be executed synchronously without having to actually wait for it', (context) => {
const fn = context.mock.fn();
context.mock.timers.enable({ apis: ['setTimeout', 'Date'] });
setTimeout(fn, 9999);
assert.strictEqual(fn.mock.callCount(), 0);
assert.strictEqual(Date.now(), 0);
// Advance in time
context.mock.timers.tick(9999);
assert.strictEqual(fn.mock.callCount(), 1);
assert.strictEqual(Date.now(), 9999);
});
```
```cjs
const assert = require('node:assert');
const { test } = require('node:test');
test('mocks setTimeout to be executed synchronously without having to actually wait for it', (context) => {
const fn = context.mock.fn();
context.mock.timers.enable({ apis: ['setTimeout', 'Date'] });
setTimeout(fn, 9999);
assert.strictEqual(fn.mock.callCount(), 0);
assert.strictEqual(Date.now(), 0);
// Advance in time
context.mock.timers.tick(9999);
assert.strictEqual(fn.mock.callCount(), 1);
assert.strictEqual(Date.now(), 9999);
});
```
#### Using clear functions
As mentioned, all clear functions from timers (`clearTimeout`, `clearInterval`,and
`clearImmediate`) are implicitly mocked. Take a look at this example using `setTimeout`:
```mjs
import assert from 'node:assert';
import { test } from 'node:test';
test('mocks setTimeout to be executed synchronously without having to actually wait for it', (context) => {
const fn = context.mock.fn();
// Optionally choose what to mock
context.mock.timers.enable({ apis: ['setTimeout'] });
const id = setTimeout(fn, 9999);
// Implicitly mocked as well
clearTimeout(id);
context.mock.timers.tick(9999);
// As that setTimeout was cleared the mock function will never be called
assert.strictEqual(fn.mock.callCount(), 0);
});
```
```cjs
const assert = require('node:assert');
const { test } = require('node:test');
test('mocks setTimeout to be executed synchronously without having to actually wait for it', (context) => {
const fn = context.mock.fn();
// Optionally choose what to mock
context.mock.timers.enable({ apis: ['setTimeout'] });
const id = setTimeout(fn, 9999);
// Implicitly mocked as well
clearTimeout(id);
context.mock.timers.tick(9999);
// As that setTimeout was cleared the mock function will never be called
assert.strictEqual(fn.mock.callCount(), 0);
});
```
#### Working with Node.js timers modules
Once you enable mocking timers, [node:timers](./timers.md),
[node:timers/promises](./timers.md#timers-promises-api) modules,
and timers from the Node.js global context are enabled:
**Note:** Destructuring functions such as
`import { setTimeout } from 'node:timers'` is currently
not supported by this API.
```mjs
import assert from 'node:assert';
import { test } from 'node:test';
import nodeTimers from 'node:timers';
import nodeTimersPromises from 'node:timers/promises';
test('mocks setTimeout to be executed synchronously without having to actually wait for it', async (context) => {
const globalTimeoutObjectSpy = context.mock.fn();
const nodeTimerSpy = context.mock.fn();
const nodeTimerPromiseSpy = context.mock.fn();
// Optionally choose what to mock
context.mock.timers.enable({ apis: ['setTimeout'] });
setTimeout(globalTimeoutObjectSpy, 9999);
nodeTimers.setTimeout(nodeTimerSpy, 9999);
const promise = nodeTimersPromises.setTimeout(9999).then(nodeTimerPromiseSpy);
// Advance in time
context.mock.timers.tick(9999);
assert.strictEqual(globalTimeoutObjectSpy.mock.callCount(), 1);
assert.strictEqual(nodeTimerSpy.mock.callCount(), 1);
await promise;
assert.strictEqual(nodeTimerPromiseSpy.mock.callCount(), 1);
});
```
```cjs
const assert = require('node:assert');
const { test } = require('node:test');
const nodeTimers = require('node:timers');
const nodeTimersPromises = require('node:timers/promises');
test('mocks setTimeout to be executed synchronously without having to actually wait for it', async (context) => {
const globalTimeoutObjectSpy = context.mock.fn();
const nodeTimerSpy = context.mock.fn();
const nodeTimerPromiseSpy = context.mock.fn();
// Optionally choose what to mock
context.mock.timers.enable({ apis: ['setTimeout'] });
setTimeout(globalTimeoutObjectSpy, 9999);
nodeTimers.setTimeout(nodeTimerSpy, 9999);
const promise = nodeTimersPromises.setTimeout(9999).then(nodeTimerPromiseSpy);
// Advance in time
context.mock.timers.tick(9999);
assert.strictEqual(globalTimeoutObjectSpy.mock.callCount(), 1);
assert.strictEqual(nodeTimerSpy.mock.callCount(), 1);
await promise;
assert.strictEqual(nodeTimerPromiseSpy.mock.callCount(), 1);
});
```
In Node.js, `setInterval` from [node:timers/promises](./timers.md#timers-promises-api)
is an `AsyncGenerator` and is also supported by this API:
```mjs
import assert from 'node:assert';
import { test } from 'node:test';
import nodeTimersPromises from 'node:timers/promises';
test('should tick five times testing a real use case', async (context) => {
context.mock.timers.enable({ apis: ['setInterval'] });
const expectedIterations = 3;
const interval = 1000;
const startedAt = Date.now();
async function run() {
const times = [];
for await (const time of nodeTimersPromises.setInterval(interval, startedAt)) {
times.push(time);
if (times.length === expectedIterations) break;
}
return times;
}
const r = run();
context.mock.timers.tick(interval);
context.mock.timers.tick(interval);
context.mock.timers.tick(interval);
const timeResults = await r;
assert.strictEqual(timeResults.length, expectedIterations);
for (let it = 1; it < expectedIterations; it++) {
assert.strictEqual(timeResults[it - 1], startedAt + (interval * it));
}
});
```
```cjs
const assert = require('node:assert');
const { test } = require('node:test');
const nodeTimersPromises = require('node:timers/promises');
test('should tick five times testing a real use case', async (context) => {
context.mock.timers.enable({ apis: ['setInterval'] });
const expectedIterations = 3;
const interval = 1000;
const startedAt = Date.now();
async function run() {
const times = [];
for await (const time of nodeTimersPromises.setInterval(interval, startedAt)) {
times.push(time);
if (times.length === expectedIterations) break;
}
return times;
}
const r = run();
context.mock.timers.tick(interval);
context.mock.timers.tick(interval);
context.mock.timers.tick(interval);
const timeResults = await r;
assert.strictEqual(timeResults.length, expectedIterations);
for (let it = 1; it < expectedIterations; it++) {
assert.strictEqual(timeResults[it - 1], startedAt + (interval * it));
}
});
```
### `timers.runAll()`
<!-- YAML
added:
- v20.4.0
2023-11-29, Version 18.19.0 'Hydrogen' (LTS) Notable changes: deps: * (SEMVER-MINOR) update uvwasi to 0.0.19 (Node.js GitHub Bot) https://github.com/nodejs/node/pull/49908 * (SEMVER-MINOR) upgrade npm to 10.2.3 (npm team) https://github.com/nodejs/node/pull/50531 doc: * move and rename loaders section (Geoffrey Booth) https://github.com/nodejs/node/pull/49261 esm: * use import attributes instead of import assertions (Antoine du Hamel) https://github.com/nodejs/node/pull/50140 * --experimental-default-type flag to flip module defaults (Geoffrey Booth) https://github.com/nodejs/node/pull/49869 * unflag import.meta.resolve (Guy Bedford) https://github.com/nodejs/node/pull/49028 * move hook execution to separate thread (Jacob Smith) https://github.com/nodejs/node/pull/44710 * leverage loaders when resolving subsequent loaders (Maël Nison) https://github.com/nodejs/node/pull/43772 lib: * (SEMVER-MINOR) add api to detect whether source-maps are enabled (翠 / green) https://github.com/nodejs/node/pull/46391 * (SEMVER-MINOR) add tracing channel to diagnostics_channel (Stephen Belanger) https://github.com/nodejs/node/pull/44943 src: * (SEMVER-MINOR) add cjs_module_lexer_version base64_version (Jithil P Ponnan) https://github.com/nodejs/node/pull/45629 stream: * use bitmap in readable state (Benjamin Gruenbaum) https://github.com/nodejs/node/pull/49745 test_runner: * (SEMVER-MINOR) accept `testOnly` in `run` (Moshe Atlow) https://github.com/nodejs/node/pull/49753 * (SEMVER-MINOR) add junit reporter (Moshe Atlow) https://github.com/nodejs/node/pull/49614 * (SEMVER-MINOR) expose location of tests (Colin Ihrig) https://github.com/nodejs/node/pull/48975 * (SEMVER-MINOR) add shards support (Raz Luvaton) https://github.com/nodejs/node/pull/48639 * (SEMVER-MINOR) add initial draft for fakeTimers (Erick Wendel) https://github.com/nodejs/node/pull/47775 test_runner, cli: * (SEMVER-MINOR) add --test-concurrency flag (Colin Ihrig) https://github.com/nodejs/node/pull/49996 tls: * (SEMVER-MINOR) add ALPNCallback server option for dynamic ALPN negotiation (Tim Perry) https://github.com/nodejs/node/pull/45190 vm: * (SEMVER-MINOR) use import attributes instead of import assertions (Antoine du Hamel) https://github.com/nodejs/node/pull/50141 PR-URL: https://github.com/nodejs/node/pull/50953
2023-11-27 12:19:49 +01:00
- v18.19.0
-->
Triggers all pending mocked timers immediately. If the `Date` object is also
mocked, it will also advance the `Date` object to the furthest timer's time.
The example below triggers all pending timers immediately,
causing them to execute without any delay.
```mjs
import assert from 'node:assert';
import { test } from 'node:test';
test('runAll functions following the given order', (context) => {
context.mock.timers.enable({ apis: ['setTimeout', 'Date'] });
const results = [];
setTimeout(() => results.push(1), 9999);
// Notice that if both timers have the same timeout,
// the order of execution is guaranteed
setTimeout(() => results.push(3), 8888);
setTimeout(() => results.push(2), 8888);
assert.deepStrictEqual(results, []);
context.mock.timers.runAll();
assert.deepStrictEqual(results, [3, 2, 1]);
// The Date object is also advanced to the furthest timer's time
assert.strictEqual(Date.now(), 9999);
});
```
```cjs
const assert = require('node:assert');
const { test } = require('node:test');
test('runAll functions following the given order', (context) => {
context.mock.timers.enable({ apis: ['setTimeout', 'Date'] });
const results = [];
setTimeout(() => results.push(1), 9999);
// Notice that if both timers have the same timeout,
// the order of execution is guaranteed
setTimeout(() => results.push(3), 8888);
setTimeout(() => results.push(2), 8888);
assert.deepStrictEqual(results, []);
context.mock.timers.runAll();
assert.deepStrictEqual(results, [3, 2, 1]);
// The Date object is also advanced to the furthest timer's time
assert.strictEqual(Date.now(), 9999);
});
```
**Note:** The `runAll()` function is specifically designed for
triggering timers in the context of timer mocking.
It does not have any effect on real-time system
clocks or actual timers outside of the mocking environment.
### `timers.setTime(milliseconds)`
<!-- YAML
added:
2023-11-14, Version 21.2.0 (Current) Notable changes: doc: * add MrJithil to collaborators (Jithil P Ponnan) https://github.com/nodejs/node/pull/50666 * add Ethan-Arrowood as a collaborator (Ethan Arrowood) https://github.com/nodejs/node/pull/50393 esm: * (SEMVER-MINOR) add import.meta.dirname and import.meta.filename (James Sumners) https://github.com/nodejs/node/pull/48740 fs: * add stacktrace to fs/promises (翠 / green) https://github.com/nodejs/node/pull/49849 lib: * (SEMVER-MINOR) add `--no-experimental-global-navigator` CLI flag (Antoine du Hamel) https://github.com/nodejs/node/pull/50562 * (SEMVER-MINOR) add navigator.language & navigator.languages (Aras Abbasi) https://github.com/nodejs/node/pull/50303 * (SEMVER-MINOR) add navigator.platform (Aras Abbasi) https://github.com/nodejs/node/pull/50385 stream: * (SEMVER-MINOR) add support for `deflate-raw` format to webstreams compression (Damian Krzeminski) https://github.com/nodejs/node/pull/50097 * use Array for Readable buffer (Robert Nagy) https://github.com/nodejs/node/pull/50341 * optimize creation (Robert Nagy) https://github.com/nodejs/node/pull/50337 test_runner: * (SEMVER-MINOR) adds built in lcov reporter (Phil Nash) https://github.com/nodejs/node/pull/50018 * (SEMVER-MINOR) add Date to the supported mock APIs (Lucas Santos) https://github.com/nodejs/node/pull/48638 test_runner, cli: * (SEMVER-MINOR) add --test-timeout flag (Shubham Pandey) https://github.com/nodejs/node/pull/50443 PR-URL: https://github.com/nodejs/node/pull/50681
2023-11-12 08:29:37 +01:00
- v21.2.0
2024-01-09, Version 20.11.0 'Iron' (LTS) Notable changes: crypto: * update root certificates to NSS 3.95 (Node.js GitHub Bot) https://github.com/nodejs/node/pull/50805 doc: * add MrJithil to collaborators (Jithil P Ponnan) https://github.com/nodejs/node/pull/50666 * add Ethan-Arrowood as a collaborator (Ethan Arrowood) https://github.com/nodejs/node/pull/50393 esm: * (SEMVER-MINOR) add import.meta.dirname and import.meta.filename (James Sumners) https://github.com/nodejs/node/pull/48740 fs: * add c++ fast path for writeFileSync utf8 (CanadaHonk) https://github.com/nodejs/node/pull/49884 module: * (SEMVER-MINOR) remove useCustomLoadersIfPresent flag (Chengzhong Wu) https://github.com/nodejs/node/pull/48655 * (SEMVER-MINOR) bootstrap module loaders in shadow realm (Chengzhong Wu) https://github.com/nodejs/node/pull/48655 src: * (SEMVER-MINOR) add `--disable-warning` option (Ethan Arrowood) https://github.com/nodejs/node/pull/50661 * (SEMVER-MINOR) create per isolate proxy env template (Chengzhong Wu) https://github.com/nodejs/node/pull/48655 * (SEMVER-MINOR) make process binding data weak (Chengzhong Wu) https://github.com/nodejs/node/pull/48655 stream: * use Array for Readable buffer (Robert Nagy) https://github.com/nodejs/node/pull/50341 * optimize creation (Robert Nagy) https://github.com/nodejs/node/pull/50337 test_runner: * (SEMVER-MINOR) adds built in lcov reporter (Phil Nash) https://github.com/nodejs/node/pull/50018 * (SEMVER-MINOR) add Date to the supported mock APIs (Lucas Santos) https://github.com/nodejs/node/pull/48638 test_runner, cli: * (SEMVER-MINOR) add --test-timeout flag (Shubham Pandey) https://github.com/nodejs/node/pull/50443 PR-URL: https://github.com/nodejs/node/pull/51124
2023-12-12 00:10:33 +00:00
- v20.11.0
-->
Sets the current Unix timestamp that will be used as reference for any mocked
`Date` objects.
```mjs
import assert from 'node:assert';
import { test } from 'node:test';
test('runAll functions following the given order', (context) => {
const now = Date.now();
const setTime = 1000;
// Date.now is not mocked
assert.deepStrictEqual(Date.now(), now);
context.mock.timers.enable({ apis: ['Date'] });
context.mock.timers.setTime(setTime);
// Date.now is now 1000
assert.strictEqual(Date.now(), setTime);
});
```
```cjs
const assert = require('node:assert');
const { test } = require('node:test');
test('setTime replaces current time', (context) => {
const now = Date.now();
const setTime = 1000;
// Date.now is not mocked
assert.deepStrictEqual(Date.now(), now);
context.mock.timers.enable({ apis: ['Date'] });
context.mock.timers.setTime(setTime);
// Date.now is now 1000
assert.strictEqual(Date.now(), setTime);
});
```
#### Dates and Timers working together
Dates and timer objects are dependent on each other. If you use `setTime()` to
pass the current time to the mocked `Date` object, the set timers with
`setTimeout` and `setInterval` will **not** be affected.
However, the `tick` method **will** advanced the mocked `Date` object.
```mjs
import assert from 'node:assert';
import { test } from 'node:test';
test('runAll functions following the given order', (context) => {
context.mock.timers.enable({ apis: ['setTimeout', 'Date'] });
const results = [];
setTimeout(() => results.push(1), 9999);
assert.deepStrictEqual(results, []);
context.mock.timers.setTime(12000);
assert.deepStrictEqual(results, []);
// The date is advanced but the timers don't tick
assert.strictEqual(Date.now(), 12000);
});
```
```cjs
const assert = require('node:assert');
const { test } = require('node:test');
test('runAll functions following the given order', (context) => {
context.mock.timers.enable({ apis: ['setTimeout', 'Date'] });
const results = [];
setTimeout(() => results.push(1), 9999);
assert.deepStrictEqual(results, []);
context.mock.timers.setTime(12000);
assert.deepStrictEqual(results, []);
// The date is advanced but the timers don't tick
assert.strictEqual(Date.now(), 12000);
});
```
## Class: `TestsStream`
<!-- YAML
added:
- v18.9.0
- v16.19.0
changes:
- version:
- v20.0.0
- v19.9.0
- v18.17.0
pr-url: https://github.com/nodejs/node/pull/47094
description: added type to test:pass and test:fail events for when the test is a suite.
-->
* Extends {Readable}
A successful call to [`run()`][] method will return a new {TestsStream}
object, streaming a series of events representing the execution of the tests.
`TestsStream` will emit events, in the order of the tests definition
Some of the events are guaranteed to be emitted in the same order as the tests
are defined, while others are emitted in the order that the tests execute.
### Event: `'test:coverage'`
* `data` {Object}
* `summary` {Object} An object containing the coverage report.
* `files` {Array} An array of coverage reports for individual files. Each
report is an object with the following schema:
* `path` {string} The absolute path of the file.
* `totalLineCount` {number} The total number of lines.
* `totalBranchCount` {number} The total number of branches.
* `totalFunctionCount` {number} The total number of functions.
* `coveredLineCount` {number} The number of covered lines.
* `coveredBranchCount` {number} The number of covered branches.
* `coveredFunctionCount` {number} The number of covered functions.
* `coveredLinePercent` {number} The percentage of lines covered.
* `coveredBranchPercent` {number} The percentage of branches covered.
* `coveredFunctionPercent` {number} The percentage of functions covered.
* `functions` {Array} An array of functions representing function
coverage.
* `name` {string} The name of the function.
* `line` {number} The line number where the function is defined.
* `count` {number} The number of times the function was called.
* `branches` {Array} An array of branches representing branch coverage.
* `line` {number} The line number where the branch is defined.
* `count` {number} The number of times the branch was taken.
* `lines` {Array} An array of lines representing line
numbers and the number of times they were covered.
* `line` {number} The line number.
* `count` {number} The number of times the line was covered.
* `thresholds` {Object} An object containing whether or not the coverage for
each coverage type.
* `function` {number} The function coverage threshold.
* `branch` {number} The branch coverage threshold.
* `line` {number} The line coverage threshold.
* `totals` {Object} An object containing a summary of coverage for all
files.
* `totalLineCount` {number} The total number of lines.
* `totalBranchCount` {number} The total number of branches.
* `totalFunctionCount` {number} The total number of functions.
* `coveredLineCount` {number} The number of covered lines.
* `coveredBranchCount` {number} The number of covered branches.
* `coveredFunctionCount` {number} The number of covered functions.
* `coveredLinePercent` {number} The percentage of lines covered.
* `coveredBranchPercent` {number} The percentage of branches covered.
* `coveredFunctionPercent` {number} The percentage of functions covered.
* `workingDirectory` {string} The working directory when code coverage
began. This is useful for displaying relative path names in case the tests
changed the working directory of the Node.js process.
* `nesting` {number} The nesting level of the test.
Emitted when code coverage is enabled and all tests have completed.
### Event: `'test:complete'`
* `data` {Object}
* `column` {number|undefined} The column number where the test is defined, or
`undefined` if the test was run through the REPL.
* `details` {Object} Additional execution metadata.
* `passed` {boolean} Whether the test passed or not.
* `duration_ms` {number} The duration of the test in milliseconds.
* `error` {Error|undefined} An error wrapping the error thrown by the test
if it did not pass.
* `cause` {Error} The actual error thrown by the test.
* `type` {string|undefined} The type of the test, used to denote whether
this is a suite.
* `file` {string|undefined} The path of the test file,
`undefined` if test was run through the REPL.
* `line` {number|undefined} The line number where the test is defined, or
`undefined` if the test was run through the REPL.
* `name` {string} The test name.
* `nesting` {number} The nesting level of the test.
* `testNumber` {number} The ordinal number of the test.
* `todo` {string|boolean|undefined} Present if [`context.todo`][] is called
* `skip` {string|boolean|undefined} Present if [`context.skip`][] is called
Emitted when a test completes its execution.
This event is not emitted in the same order as the tests are
defined.
The corresponding declaration ordered events are `'test:pass'` and `'test:fail'`.
### Event: `'test:dequeue'`
* `data` {Object}
* `column` {number|undefined} The column number where the test is defined, or
`undefined` if the test was run through the REPL.
* `file` {string|undefined} The path of the test file,
`undefined` if test was run through the REPL.
* `line` {number|undefined} The line number where the test is defined, or
`undefined` if the test was run through the REPL.
* `name` {string} The test name.
* `nesting` {number} The nesting level of the test.
* `type` {string} The test type. Either `'suite'` or `'test'`.
Emitted when a test is dequeued, right before it is executed.
This event is not guaranteed to be emitted in the same order as the tests are
defined. The corresponding declaration ordered event is `'test:start'`.
### Event: `'test:diagnostic'`
* `data` {Object}
* `column` {number|undefined} The column number where the test is defined, or
`undefined` if the test was run through the REPL.
* `file` {string|undefined} The path of the test file,
`undefined` if test was run through the REPL.
* `line` {number|undefined} The line number where the test is defined, or
`undefined` if the test was run through the REPL.
* `message` {string} The diagnostic message.
* `nesting` {number} The nesting level of the test.
Emitted when [`context.diagnostic`][] is called.
This event is guaranteed to be emitted in the same order as the tests are
defined.
### Event: `'test:enqueue'`
* `data` {Object}
* `column` {number|undefined} The column number where the test is defined, or
`undefined` if the test was run through the REPL.
* `file` {string|undefined} The path of the test file,
`undefined` if test was run through the REPL.
* `line` {number|undefined} The line number where the test is defined, or
`undefined` if the test was run through the REPL.
* `name` {string} The test name.
* `nesting` {number} The nesting level of the test.
* `type` {string} The test type. Either `'suite'` or `'test'`.
Emitted when a test is enqueued for execution.
### Event: `'test:fail'`
* `data` {Object}
* `column` {number|undefined} The column number where the test is defined, or
`undefined` if the test was run through the REPL.
* `details` {Object} Additional execution metadata.
* `duration_ms` {number} The duration of the test in milliseconds.
* `error` {Error} An error wrapping the error thrown by the test.
* `cause` {Error} The actual error thrown by the test.
* `type` {string|undefined} The type of the test, used to denote whether
this is a suite.
* `file` {string|undefined} The path of the test file,
`undefined` if test was run through the REPL.
* `line` {number|undefined} The line number where the test is defined, or
`undefined` if the test was run through the REPL.
* `name` {string} The test name.
* `nesting` {number} The nesting level of the test.
* `testNumber` {number} The ordinal number of the test.
* `todo` {string|boolean|undefined} Present if [`context.todo`][] is called
* `skip` {string|boolean|undefined} Present if [`context.skip`][] is called
Emitted when a test fails.
This event is guaranteed to be emitted in the same order as the tests are
defined.
The corresponding execution ordered event is `'test:complete'`.
### Event: `'test:pass'`
* `data` {Object}
* `column` {number|undefined} The column number where the test is defined, or
`undefined` if the test was run through the REPL.
* `details` {Object} Additional execution metadata.
* `duration_ms` {number} The duration of the test in milliseconds.
* `type` {string|undefined} The type of the test, used to denote whether
this is a suite.
* `file` {string|undefined} The path of the test file,
`undefined` if test was run through the REPL.
* `line` {number|undefined} The line number where the test is defined, or
`undefined` if the test was run through the REPL.
* `name` {string} The test name.
* `nesting` {number} The nesting level of the test.
* `testNumber` {number} The ordinal number of the test.
* `todo` {string|boolean|undefined} Present if [`context.todo`][] is called
* `skip` {string|boolean|undefined} Present if [`context.skip`][] is called
Emitted when a test passes.
This event is guaranteed to be emitted in the same order as the tests are
defined.
The corresponding execution ordered event is `'test:complete'`.
### Event: `'test:plan'`
* `data` {Object}
* `column` {number|undefined} The column number where the test is defined, or
`undefined` if the test was run through the REPL.
* `file` {string|undefined} The path of the test file,
`undefined` if test was run through the REPL.
* `line` {number|undefined} The line number where the test is defined, or
`undefined` if the test was run through the REPL.
* `nesting` {number} The nesting level of the test.
* `count` {number} The number of subtests that have ran.
Emitted when all subtests have completed for a given test.
This event is guaranteed to be emitted in the same order as the tests are
defined.
### Event: `'test:start'`
* `data` {Object}
* `column` {number|undefined} The column number where the test is defined, or
`undefined` if the test was run through the REPL.
* `file` {string|undefined} The path of the test file,
`undefined` if test was run through the REPL.
* `line` {number|undefined} The line number where the test is defined, or
`undefined` if the test was run through the REPL.
* `name` {string} The test name.
* `nesting` {number} The nesting level of the test.
Emitted when a test starts reporting its own and its subtests status.
This event is guaranteed to be emitted in the same order as the tests are
defined.
The corresponding execution ordered event is `'test:dequeue'`.
### Event: `'test:stderr'`
* `data` {Object}
* `file` {string} The path of the test file.
* `message` {string} The message written to `stderr`.
Emitted when a running test writes to `stderr`.
This event is only emitted if `--test` flag is passed.
This event is not guaranteed to be emitted in the same order as the tests are
defined.
### Event: `'test:stdout'`
* `data` {Object}
* `file` {string} The path of the test file.
* `message` {string} The message written to `stdout`.
Emitted when a running test writes to `stdout`.
This event is only emitted if `--test` flag is passed.
This event is not guaranteed to be emitted in the same order as the tests are
defined.
### Event: `'test:summary'`
* `data` {Object}
* `counts` {Object} An object containing the counts of various test results.
* `cancelled` {number} The total number of cancelled tests.
* `failed` {number} The total number of failed tests.
* `passed` {number} The total number of passed tests.
* `skipped` {number} The total number of skipped tests.
* `suites` {number} The total number of suites run.
* `tests` {number} The total number of tests run, excluding suites.
* `todo` {number} The total number of TODO tests.
* `topLevel` {number} The total number of top level tests and suites.
* `duration_ms` {number} The duration of the test run in milliseconds.
* `file` {string|undefined} The path of the test file that generated the
summary. If the summary corresponds to multiple files, this value is
`undefined`.
* `success` {boolean} Indicates whether or not the test run is considered
successful or not. If any error condition occurs, such as a failing test or
unmet coverage threshold, this value will be set to `false`.
Emitted when a test run completes. This event contains metrics pertaining to
the completed test run, and is useful for determining if a test run passed or
failed. If process-level test isolation is used, a `'test:summary'` event is
generated for each test file in addition to a final cumulative summary.
### Event: `'test:watch:drained'`
Emitted when no more tests are queued for execution in watch mode.
## Class: `TestContext`
<!-- YAML
2022-08-16, Version 16.17.0 'Gallium' (LTS) Notable changes: Adds `util.parseArgs` helper for higher level command-line argument parsing. Contributed by Benjamin Coe, John Gee, Darcy Clarke, Joe Sepi, Kevin Gibbons, Aaron Casanova, Jessica Nahulan, and Jordan Harband. https://github.com/nodejs/node/pull/42675 Node.js ESM Loader hooks now support multiple custom loaders, and composition is achieved via "chaining": `foo-loader` calls `bar-loader` calls `qux-loader` (a custom loader _must_ now signal a short circuit when intentionally not calling the next). See the ESM docs (https://nodejs.org/dist/latest-v16.x/docs/api/esm.html) for details. Contributed by Jacob Smith, Geoffrey Booth, and Bradley Farias. https://github.com/nodejs/node/pull/42623 The `node:test` module, which was initially introduced in Node.js v18.0.0, is now available with all the changes done to it up to Node.js v18.7.0. To better align Node.js' experimental implementation of the Web Crypto API with other runtimes, several changes were made: * Support for CFRG curves was added, with the `'Ed25519'`, `'Ed448'`, `'X25519'`, and `'X448'` algorithms. * The proprietary `'NODE-DSA'`, `'NODE-DH'`, `'NODE-SCRYPT'`, `'NODE-ED25519'`, `'NODE-ED448'`, `'NODE-X25519'`, and `'NODE-X448'` algorithms were removed. * The proprietary `'node.keyObject'` import/export format was removed. Contributed by Filip Skokan. https://github.com/nodejs/node/pull/42507 https://github.com/nodejs/node/pull/43310 Updated Corepack to 0.12.1 - https://github.com/nodejs/node/pull/43965 Updated ICU to 71.1 - https://github.com/nodejs/node/pull/42655 Updated npm to 8.15.0 - https://github.com/nodejs/node/pull/43917 Updated Undici to 5.8.0 - https://github.com/nodejs/node/pull/43886 (SEMVER-MINOR) crypto: make authTagLength optional for CC20P1305 (Tobias Nießen) https://github.com/nodejs/node/pull/42427 (SEMVER-MINOR) crypto: align webcrypto RSA key import/export with other implementations (Filip Skokan) https://github.com/nodejs/node/pull/42816 (SEMVER-MINOR) dns: export error code constants from `dns/promises` (Feng Yu) https://github.com/nodejs/node/pull/43176 doc: deprecate coercion to integer in process.exit (Daeyeon Jeong) https://github.com/nodejs/node/pull/43738 (SEMVER-MINOR) doc: deprecate diagnostics_channel object subscribe method (Stephen Belanger) https://github.com/nodejs/node/pull/42714 (SEMVER-MINOR) errors: add support for cause in aborterror (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) events: expose CustomEvent on global with CLI flag (Daeyeon Jeong) https://github.com/nodejs/node/pull/43885 (SEMVER-MINOR) events: add `CustomEvent` (Daeyeon Jeong) https://github.com/nodejs/node/pull/43514 (SEMVER-MINOR) events: propagate abortsignal reason in new AbortError ctor in events (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) fs: propagate abortsignal reason in new AbortSignal constructors (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) fs: make params in writing methods optional (LiviaMedeiros) https://github.com/nodejs/node/pull/42601 (SEMVER-MINOR) fs: add `read(buffer[, options])` versions (LiviaMedeiros) https://github.com/nodejs/node/pull/42768 (SEMVER-MINOR) http: add drop request event for http server (theanarkh) https://github.com/nodejs/node/pull/43806 (SEMVER-MINOR) http: add diagnostics channel for http client (theanarkh) https://github.com/nodejs/node/pull/43580 (SEMVER-MINOR) http: add perf_hooks detail for http request and client (theanarkh) https://github.com/nodejs/node/pull/43361 (SEMVER-MINOR) http: add uniqueHeaders option to request and createServer (Paolo Insogna) https://github.com/nodejs/node/pull/41397 (SEMVER-MINOR) http2: propagate abortsignal reason in new AbortError constructor (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) http2: compat support for array headers (OneNail) https://github.com/nodejs/node/pull/42901 (SEMVER-MINOR) lib: propagate abortsignal reason in new AbortError constructor in blob (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) lib: add abortSignal.throwIfAborted() (James M Snell) https://github.com/nodejs/node/pull/40951 (SEMVER-MINOR) lib: improved diagnostics_channel subscribe/unsubscribe (Stephen Belanger) https://github.com/nodejs/node/pull/42714 (SEMVER-MINOR) module: add isBuiltIn method (hemanth.hm) https://github.com/nodejs/node/pull/43396 (SEMVER-MINOR) module,repl: support 'node:'-only core modules (Colin Ihrig) https://github.com/nodejs/node/pull/42325 (SEMVER-MINOR) net: add drop event for net server (theanarkh) https://github.com/nodejs/node/pull/43582 (SEMVER-MINOR) net: add ability to reset a tcp socket (pupilTong) https://github.com/nodejs/node/pull/43112 (SEMVER-MINOR) node-api: emit uncaught-exception on unhandled tsfn callbacks (Chengzhong Wu) https://github.com/nodejs/node/pull/36510 (SEMVER-MINOR) perf_hooks: add PerformanceResourceTiming (RafaelGSS) https://github.com/nodejs/node/pull/42725 (SEMVER-MINOR) report: add more heap infos in process report (theanarkh) https://github.com/nodejs/node/pull/43116 (SEMVER-MINOR) src: add --openssl-legacy-provider option (Daniel Bevenius) https://github.com/nodejs/node/pull/40478 (SEMVER-MINOR) src: define fs.constants.S_IWUSR & S_IRUSR for Win (Liviu Ionescu) https://github.com/nodejs/node/pull/42757 (SEMVER-MINOR) src,doc,test: add --openssl-shared-config option (Daniel Bevenius) https://github.com/nodejs/node/pull/43124 (SEMVER-MINOR) stream: use cause options in AbortError constructors (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) stream: add iterator helper find (Nitzan Uziely) https://github.com/nodejs/node/pull/41849 (SEMVER-MINOR) stream: add writableAborted (Robert Nagy) https://github.com/nodejs/node/pull/40802 (SEMVER-MINOR) timers: propagate signal.reason in awaitable timers (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) v8: add v8.startupSnapshot utils (Joyee Cheung) https://github.com/nodejs/node/pull/43329 (SEMVER-MINOR) v8: export more fields in getHeapStatistics (theanarkh) https://github.com/nodejs/node/pull/42784 (SEMVER-MINOR) worker: add hasRef() to MessagePort (Darshan Sen) https://github.com/nodejs/node/pull/42849 PR-URL: https://github.com/nodejs/node/pull/44098
2022-08-02 14:34:18 +02:00
added:
- v18.0.0
- v16.17.0
changes:
2023-07-18, Version 18.17.0 'Hydrogen' (LTS) Notable changes: Ada 2.0 Node.js v18.17.0 comes with the latest version of the URL parser, Ada. This update brings significant performance improvements to URL parsing, including enhancements to the url.domainToASCII and url.domainToUnicode functions in node:url. Ada 2.0 has been integrated into the Node.js codebase, ensuring that all parts of the application can benefit from the improved performance. Additionally, Ada 2.0 features a significant performance boost over its predecessor, Ada 1.0.4, while also eliminating the need for the ICU requirement for URL hostname parsing. Contributed by Yagiz Nizipli and Daniel Lemire in https://github.com/nodejs/node/pull/47339 Web Crypto API Web Crypto API functions' arguments are now coerced and validated as per their WebIDL definitions like in other Web Crypto API implementations. This further improves interoperability with other implementations of Web Crypto API. Contributed by Filip Skokan in https://github.com/nodejs/node/pull/46067 crypto: * update root certificates to NSS 3.89 (Node.js GitHub Bot) https://github.com/nodejs/node/pull/47659 dns: * (SEMVER-MINOR) expose getDefaultResultOrder (btea) https://github.com/nodejs/node/pull/46973 doc: * add ovflowd to collaborators (Claudio Wunder) https://github.com/nodejs/node/pull/47844 * add KhafraDev to collaborators (Matthew Aitken) https://github.com/nodejs/node/pull/47510 * events: * (SEMVER-MINOR) add getMaxListeners method (Matthew Aitken) https://github.com/nodejs/node/pull/47039 fs: * (SEMVER-MINOR) add support for mode flag to specify the copy behavior (Tetsuharu Ohzeki) https://github.com/nodejs/node/pull/47084 * (SEMVER-MINOR) add recursive option to readdir and opendir (Ethan Arrowood) https://github.com/nodejs/node/pull/41439 * (SEMVER-MINOR) add support for mode flag to specify the copy behavior (Tetsuharu Ohzeki) https://github.com/nodejs/node/pull/47084 * (SEMVER-MINOR) implement byob mode for readableWebStream() (Debadree Chatterjee) https://github.com/nodejs/node/pull/46933 http: * (SEMVER-MINOR) prevent writing to the body when not allowed by HTTP spec (Gerrard Lindsay) https://github.com/nodejs/node/pull/47732 * (SEMVER-MINOR) remove internal error in assignSocket (Matteo Collina) https://github.com/nodejs/node/pull/47723 * (SEMVER-MINOR) add highWaterMark opt in http.createServer (HinataKah0) https://github.com/nodejs/node/pull/47405 lib: * (SEMVER-MINOR) add webstreams to Duplex.from() (Debadree Chatterjee) https://github.com/nodejs/node/pull/46190 * (SEMVER-MINOR) implement AbortSignal.any() (Chemi Atlow) https://github.com/nodejs/node/pull/47821 module: * change default resolver to not throw on unknown scheme (Gil Tayar) https://github.com/nodejs/node/pull/47824 node-api: * (SEMVER-MINOR) define version 9 (Chengzhong Wu) https://github.com/nodejs/node/pull/48151 * (SEMVER-MINOR) deprecate napi_module_register (Vladimir Morozov) https://github.com/nodejs/node/pull/46319 stream: * (SEMVER-MINOR) preserve object mode in compose (Raz Luvaton) https://github.com/nodejs/node/pull/47413 * (SEMVER-MINOR) add setter & getter for default highWaterMark (#46929) (Robert Nagy) https://github.com/nodejs/node/pull/46929 test: * unflake test-vm-timeout-escape-nexttick (Santiago Gimeno) https://github.com/nodejs/node/pull/48078 test_runner: * (SEMVER-MINOR) add shorthands to `test` (Chemi Atlow) https://github.com/nodejs/node/pull/47909 * (SEMVER-MINOR) support combining coverage reports (Colin Ihrig) https://github.com/nodejs/node/pull/47686 * (SEMVER-MINOR) execute before hook on test (Chemi Atlow) https://github.com/nodejs/node/pull/47586 * (SEMVER-MINOR) expose reporter for use in run api (Chemi Atlow) https://github.com/nodejs/node/pull/47238 tools: * update LICENSE and license-builder.sh (Santiago Gimeno) https://github.com/nodejs/node/pull/48078 url: * (SEMVER-MINOR) implement URL.canParse (Matthew Aitken) https://github.com/nodejs/node/pull/47179 wasi: * (SEMVER-MINOR) no longer require flag to enable wasi (Michael Dawson) https://github.com/nodejs/node/pull/47286 PR-URL: https://github.com/nodejs/node/pull/48694
2023-07-10 08:12:52 -04:00
- version:
- v20.1.0
- v18.17.0
pr-url: https://github.com/nodejs/node/pull/47586
description: The `before` function was added to TestContext.
-->
An instance of `TestContext` is passed to each test function in order to
interact with the test runner. However, the `TestContext` constructor is not
exposed as part of the API.
### `context.before([fn][, options])`
<!-- YAML
2023-07-18, Version 18.17.0 'Hydrogen' (LTS) Notable changes: Ada 2.0 Node.js v18.17.0 comes with the latest version of the URL parser, Ada. This update brings significant performance improvements to URL parsing, including enhancements to the url.domainToASCII and url.domainToUnicode functions in node:url. Ada 2.0 has been integrated into the Node.js codebase, ensuring that all parts of the application can benefit from the improved performance. Additionally, Ada 2.0 features a significant performance boost over its predecessor, Ada 1.0.4, while also eliminating the need for the ICU requirement for URL hostname parsing. Contributed by Yagiz Nizipli and Daniel Lemire in https://github.com/nodejs/node/pull/47339 Web Crypto API Web Crypto API functions' arguments are now coerced and validated as per their WebIDL definitions like in other Web Crypto API implementations. This further improves interoperability with other implementations of Web Crypto API. Contributed by Filip Skokan in https://github.com/nodejs/node/pull/46067 crypto: * update root certificates to NSS 3.89 (Node.js GitHub Bot) https://github.com/nodejs/node/pull/47659 dns: * (SEMVER-MINOR) expose getDefaultResultOrder (btea) https://github.com/nodejs/node/pull/46973 doc: * add ovflowd to collaborators (Claudio Wunder) https://github.com/nodejs/node/pull/47844 * add KhafraDev to collaborators (Matthew Aitken) https://github.com/nodejs/node/pull/47510 * events: * (SEMVER-MINOR) add getMaxListeners method (Matthew Aitken) https://github.com/nodejs/node/pull/47039 fs: * (SEMVER-MINOR) add support for mode flag to specify the copy behavior (Tetsuharu Ohzeki) https://github.com/nodejs/node/pull/47084 * (SEMVER-MINOR) add recursive option to readdir and opendir (Ethan Arrowood) https://github.com/nodejs/node/pull/41439 * (SEMVER-MINOR) add support for mode flag to specify the copy behavior (Tetsuharu Ohzeki) https://github.com/nodejs/node/pull/47084 * (SEMVER-MINOR) implement byob mode for readableWebStream() (Debadree Chatterjee) https://github.com/nodejs/node/pull/46933 http: * (SEMVER-MINOR) prevent writing to the body when not allowed by HTTP spec (Gerrard Lindsay) https://github.com/nodejs/node/pull/47732 * (SEMVER-MINOR) remove internal error in assignSocket (Matteo Collina) https://github.com/nodejs/node/pull/47723 * (SEMVER-MINOR) add highWaterMark opt in http.createServer (HinataKah0) https://github.com/nodejs/node/pull/47405 lib: * (SEMVER-MINOR) add webstreams to Duplex.from() (Debadree Chatterjee) https://github.com/nodejs/node/pull/46190 * (SEMVER-MINOR) implement AbortSignal.any() (Chemi Atlow) https://github.com/nodejs/node/pull/47821 module: * change default resolver to not throw on unknown scheme (Gil Tayar) https://github.com/nodejs/node/pull/47824 node-api: * (SEMVER-MINOR) define version 9 (Chengzhong Wu) https://github.com/nodejs/node/pull/48151 * (SEMVER-MINOR) deprecate napi_module_register (Vladimir Morozov) https://github.com/nodejs/node/pull/46319 stream: * (SEMVER-MINOR) preserve object mode in compose (Raz Luvaton) https://github.com/nodejs/node/pull/47413 * (SEMVER-MINOR) add setter & getter for default highWaterMark (#46929) (Robert Nagy) https://github.com/nodejs/node/pull/46929 test: * unflake test-vm-timeout-escape-nexttick (Santiago Gimeno) https://github.com/nodejs/node/pull/48078 test_runner: * (SEMVER-MINOR) add shorthands to `test` (Chemi Atlow) https://github.com/nodejs/node/pull/47909 * (SEMVER-MINOR) support combining coverage reports (Colin Ihrig) https://github.com/nodejs/node/pull/47686 * (SEMVER-MINOR) execute before hook on test (Chemi Atlow) https://github.com/nodejs/node/pull/47586 * (SEMVER-MINOR) expose reporter for use in run api (Chemi Atlow) https://github.com/nodejs/node/pull/47238 tools: * update LICENSE and license-builder.sh (Santiago Gimeno) https://github.com/nodejs/node/pull/48078 url: * (SEMVER-MINOR) implement URL.canParse (Matthew Aitken) https://github.com/nodejs/node/pull/47179 wasi: * (SEMVER-MINOR) no longer require flag to enable wasi (Michael Dawson) https://github.com/nodejs/node/pull/47286 PR-URL: https://github.com/nodejs/node/pull/48694
2023-07-10 08:12:52 -04:00
added:
- v20.1.0
- v18.17.0
-->
* `fn` {Function|AsyncFunction} The hook function. The first argument
to this function is a [`TestContext`][] object. If the hook uses callbacks,
the callback function is passed as the second argument. **Default:** A no-op
function.
* `options` {Object} Configuration options for the hook. The following
properties are supported:
* `signal` {AbortSignal} Allows aborting an in-progress hook.
* `timeout` {number} A number of milliseconds the hook will fail after.
If unspecified, subtests inherit this value from their parent.
**Default:** `Infinity`.
This function is used to create a hook running before
subtest of the current test.
### `context.beforeEach([fn][, options])`
<!-- YAML
2022-10-12, Version 16.18.0 'Gallium' (LTS) Notable changes: assert: add `getCalls` and `reset` to callTracker (Moshe Atlow) https://github.com/nodejs/node/pull/44191 crypto: allow zero-length secret KeyObject (Filip Skokan) https://github.com/nodejs/node/pull/44201 crypto: allow zero-length IKM in HKDF and in webcrypto PBKDF2 (Filip Skokan) https://github.com/nodejs/node/pull/44201 doc: deprecate modp1, modp2, and modp5 groups (Tobias Nießen) https://github.com/nodejs/node/pull/44588 http: make idle http parser count configurable (theanarkh) https://github.com/nodejs/node/pull/43974 http: throw error on content-length mismatch (sidwebworks) https://github.com/nodejs/node/pull/44378 lib: add diagnostics channel for process and worker (theanarkh) https://github.com/nodejs/node/pull/44045 net,tls: pass a valid socket on `tlsClientError` (Daeyeon Jeong) https://github.com/nodejs/node/pull/44021 net: add local family (theanarkh) https://github.com/nodejs/node/pull/43975 report: expose report public native apis (Chengzhong Wu) https://github.com/nodejs/node/pull/44255 src: expose environment RequestInterrupt api (Chengzhong Wu) https://github.com/nodejs/node/pull/44362 stream: add `ReadableByteStream.tee()` (Daeyeon Jeong) https://github.com/nodejs/node/pull/44505 test_runner: add before/after/each hooks (Moshe Atlow) https://github.com/nodejs/node/pull/43730 util: add `maxArrayLength` option to Set and Map (Kohei Ueno) https://github.com/nodejs/node/pull/43576 PR-URL: https://github.com/nodejs/node/pull/44886
2022-10-11 14:54:19 -05:00
added:
- v18.8.0
- v16.18.0
-->
* `fn` {Function|AsyncFunction} The hook function. The first argument
to this function is a [`TestContext`][] object. If the hook uses callbacks,
the callback function is passed as the second argument. **Default:** A no-op
function.
* `options` {Object} Configuration options for the hook. The following
properties are supported:
* `signal` {AbortSignal} Allows aborting an in-progress hook.
* `timeout` {number} A number of milliseconds the hook will fail after.
If unspecified, subtests inherit this value from their parent.
**Default:** `Infinity`.
This function is used to create a hook running
before each subtest of the current test.
```js
test('top level test', async (t) => {
t.beforeEach((t) => t.diagnostic(`about to run ${t.name}`));
t.test('This is a subtest', (t) => {
assert.ok('some relevant assertion here');
});
});
```
### `context.after([fn][, options])`
<!-- YAML
2023-01-05, Version 18.13.0 'Hydrogen' (LTS) Notable changes: Add support for externally shared js builtins: By default Node.js is built so that all dependencies are bundled into the Node.js binary itself. Some Node.js distributions prefer to manage dependencies externally. There are existing build options that allow dependencies with native code to be externalized. This commit adds additional options so that dependencies with JavaScript code (including WASM) can also be externalized. This addition does not affect binaries shipped by the Node.js project but will allow other distributions to externalize additional dependencies when needed. Contributed by Michael Dawson in https://github.com/nodejs/node/pull/44376 Introduce `File`: The File class is part of the [FileAPI](https://w3c.github.io/FileAPI/). It can be used anywhere a Blob can, for example in `URL.createObjectURL` and `FormData`. It contains two properties that Blobs do not have: `lastModified`, the last time the file was modified in ms, and `name`, the name of the file. Contributed by Khafra in https://github.com/nodejs/node/pull/45139 Support function mocking on Node.js test runner: The `node:test` module supports mocking during testing via a top-level `mock` object. ```js test('spies on an object method', (t) => { const number = { value: 5, add(a) { return this.value + a; }, }; t.mock.method(number, 'add'); assert.strictEqual(number.add(3), 8); assert.strictEqual(number.add.mock.calls.length, 1); }); ``` Contributed by Colin Ihrig in https://github.com/nodejs/node/pull/45326 Other notable changes: build: * disable v8 snapshot compression by default (Joyee Cheung) https://github.com/nodejs/node/pull/45716 crypto: * update root certificates (Luigi Pinca) https://github.com/nodejs/node/pull/45490 deps: * update ICU to 72.1 (Michaël Zasso) https://github.com/nodejs/node/pull/45068 doc: * add doc-only deprecation for headers/trailers setters (Rich Trott) https://github.com/nodejs/node/pull/45697 * add Rafael to the tsc (Michael Dawson) https://github.com/nodejs/node/pull/45691 * deprecate use of invalid ports in `url.parse` (Antoine du Hamel) https://github.com/nodejs/node/pull/45576 * add lukekarrys to collaborators (Luke Karrys) https://github.com/nodejs/node/pull/45180 * add anonrig to collaborators (Yagiz Nizipli) https://github.com/nodejs/node/pull/45002 * deprecate url.parse() (Rich Trott) https://github.com/nodejs/node/pull/44919 lib: * drop fetch experimental warning (Matteo Collina) https://github.com/nodejs/node/pull/45287 net: * (SEMVER-MINOR) add autoSelectFamily and autoSelectFamilyAttemptTimeout options (Paolo Insogna) https://github.com/nodejs/node/pull/44731 * src: * (SEMVER-MINOR) add uvwasi version (Jithil P Ponnan) https://github.com/nodejs/node/pull/45639 * (SEMVER-MINOR) add initial shadow realm support (Chengzhong Wu) https://github.com/nodejs/node/pull/42869 test_runner: * (SEMVER-MINOR) add t.after() hook (Colin Ihrig) https://github.com/nodejs/node/pull/45792 * (SEMVER-MINOR) don't use a symbol for runHook() (Colin Ihrig) https://github.com/nodejs/node/pull/45792 tls: * (SEMVER-MINOR) add "ca" property to certificate object (Ben Noordhuis) https://github.com/nodejs/node/pull/44935 * remove trustcor root ca certificates (Ben Noordhuis) https://github.com/nodejs/node/pull/45776 tools: * update certdata.txt (Luigi Pinca) https://github.com/nodejs/node/pull/45490 util: * add fast path for utf8 encoding (Yagiz Nizipli) https://github.com/nodejs/node/pull/45412 * improve textdecoder decode performance (Yagiz Nizipli) https://github.com/nodejs/node/pull/45294 * (SEMVER-MINOR) add MIME utilities (#21128) (Bradley Farias) https://github.com/nodejs/node/pull/21128 PR-URL: https://github.com/nodejs/node/pull/46025
2022-12-30 15:18:44 -05:00
added:
- v19.3.0
- v18.13.0
-->
* `fn` {Function|AsyncFunction} The hook function. The first argument
to this function is a [`TestContext`][] object. If the hook uses callbacks,
the callback function is passed as the second argument. **Default:** A no-op
function.
* `options` {Object} Configuration options for the hook. The following
properties are supported:
* `signal` {AbortSignal} Allows aborting an in-progress hook.
* `timeout` {number} A number of milliseconds the hook will fail after.
If unspecified, subtests inherit this value from their parent.
**Default:** `Infinity`.
This function is used to create a hook that runs after the current test
finishes.
```js
test('top level test', async (t) => {
t.after((t) => t.diagnostic(`finished running ${t.name}`));
assert.ok('some relevant assertion here');
});
```
### `context.afterEach([fn][, options])`
<!-- YAML
2022-10-12, Version 16.18.0 'Gallium' (LTS) Notable changes: assert: add `getCalls` and `reset` to callTracker (Moshe Atlow) https://github.com/nodejs/node/pull/44191 crypto: allow zero-length secret KeyObject (Filip Skokan) https://github.com/nodejs/node/pull/44201 crypto: allow zero-length IKM in HKDF and in webcrypto PBKDF2 (Filip Skokan) https://github.com/nodejs/node/pull/44201 doc: deprecate modp1, modp2, and modp5 groups (Tobias Nießen) https://github.com/nodejs/node/pull/44588 http: make idle http parser count configurable (theanarkh) https://github.com/nodejs/node/pull/43974 http: throw error on content-length mismatch (sidwebworks) https://github.com/nodejs/node/pull/44378 lib: add diagnostics channel for process and worker (theanarkh) https://github.com/nodejs/node/pull/44045 net,tls: pass a valid socket on `tlsClientError` (Daeyeon Jeong) https://github.com/nodejs/node/pull/44021 net: add local family (theanarkh) https://github.com/nodejs/node/pull/43975 report: expose report public native apis (Chengzhong Wu) https://github.com/nodejs/node/pull/44255 src: expose environment RequestInterrupt api (Chengzhong Wu) https://github.com/nodejs/node/pull/44362 stream: add `ReadableByteStream.tee()` (Daeyeon Jeong) https://github.com/nodejs/node/pull/44505 test_runner: add before/after/each hooks (Moshe Atlow) https://github.com/nodejs/node/pull/43730 util: add `maxArrayLength` option to Set and Map (Kohei Ueno) https://github.com/nodejs/node/pull/43576 PR-URL: https://github.com/nodejs/node/pull/44886
2022-10-11 14:54:19 -05:00
added:
- v18.8.0
- v16.18.0
-->
* `fn` {Function|AsyncFunction} The hook function. The first argument
to this function is a [`TestContext`][] object. If the hook uses callbacks,
the callback function is passed as the second argument. **Default:** A no-op
function.
* `options` {Object} Configuration options for the hook. The following
properties are supported:
* `signal` {AbortSignal} Allows aborting an in-progress hook.
* `timeout` {number} A number of milliseconds the hook will fail after.
If unspecified, subtests inherit this value from their parent.
**Default:** `Infinity`.
This function is used to create a hook running
after each subtest of the current test.
```js
test('top level test', async (t) => {
t.afterEach((t) => t.diagnostic(`finished running ${t.name}`));
t.test('This is a subtest', (t) => {
assert.ok('some relevant assertion here');
});
});
```
### `context.assert`
<!-- YAML
added:
- v22.2.0
- v20.15.0
-->
An object containing assertion methods bound to `context`. The top-level
functions from the `node:assert` module are exposed here for the purpose of
creating test plans.
```js
test('test', (t) => {
t.plan(1);
t.assert.strictEqual(true, true);
});
```
#### `context.assert.fileSnapshot(value, path[, options])`
<!-- YAML
2025-02-11, Version 22.14.0 'Jod' (LTS) Notable changes: crypto: * update root certificates to NSS 3.107 (Node.js GitHub Bot) https://github.com/nodejs/node/pull/56566 fs: * (SEMVER-MINOR) allow `exclude` option in globs to accept glob patterns (Daeyeon Jeong) https://github.com/nodejs/node/pull/56489 lib: * (SEMVER-MINOR) add typescript support to STDIN eval (Marco Ippolito) https://github.com/nodejs/node/pull/56359 module: * (SEMVER-MINOR) add ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX (Marco Ippolito) https://github.com/nodejs/node/pull/56610 * (SEMVER-MINOR) add `findPackageJSON` util (Jacob Smith) https://github.com/nodejs/node/pull/55412 process: * (SEMVER-MINOR) add process.ref() and process.unref() methods (James M Snell) https://github.com/nodejs/node/pull/56400 sqlite: * (SEMVER-MINOR) support TypedArray and DataView in `StatementSync` (Alex Yang) https://github.com/nodejs/node/pull/56385 src: * (SEMVER-MINOR) add --disable-sigusr1 to prevent signal i/o thread (Rafael Gonzaga) https://github.com/nodejs/node/pull/56441 src,worker: * (SEMVER-MINOR) add isInternalWorker (Carlos Espa) https://github.com/nodejs/node/pull/56469 test_runner: * (SEMVER-MINOR) add TestContext.prototype.waitFor() (Colin Ihrig) https://github.com/nodejs/node/pull/56595 * (SEMVER-MINOR) add t.assert.fileSnapshot() (Colin Ihrig) https://github.com/nodejs/node/pull/56459 * (SEMVER-MINOR) add assert.register() API (Colin Ihrig) https://github.com/nodejs/node/pull/56434 worker: * (SEMVER-MINOR) add eval ts input (Marco Ippolito) https://github.com/nodejs/node/pull/56394 PR-URL: https://github.com/nodejs/node/pull/56910
2025-02-06 11:04:25 +01:00
added:
- v23.7.0
- v22.14.0
-->
* `value` {any} A value to serialize to a string. If Node.js was started with
the [`--test-update-snapshots`][] flag, the serialized value is written to
`path`. Otherwise, the serialized value is compared to the contents of the
existing snapshot file.
* `path` {string} The file where the serialized `value` is written.
* `options` {Object} Optional configuration options. The following properties
are supported:
* `serializers` {Array} An array of synchronous functions used to serialize
`value` into a string. `value` is passed as the only argument to the first
serializer function. The return value of each serializer is passed as input
to the next serializer. Once all serializers have run, the resulting value
is coerced to a string. **Default:** If no serializers are provided, the
test runner's default serializers are used.
This function serializes `value` and writes it to the file specified by `path`.
```js
test('snapshot test with default serialization', (t) => {
t.assert.fileSnapshot({ value1: 1, value2: 2 }, './snapshots/snapshot.json');
});
```
This function differs from `context.assert.snapshot()` in the following ways:
* The snapshot file path is explicitly provided by the user.
* Each snapshot file is limited to a single snapshot value.
* No additional escaping is performed by the test runner.
These differences allow snapshot files to better support features such as syntax
highlighting.
#### `context.assert.snapshot(value[, options])`
<!-- YAML
2024-06-11, Version 22.3.0 (Current) Notable changes: buffer: * (SEMVER-MINOR) add .bytes() method to Blob (Matthew Aitken) https://github.com/nodejs/node/pull/53221 cli: * (SEMVER-MINOR) add `NODE_RUN_PACKAGE_JSON_PATH` env (Yagiz Nizipli) https://github.com/nodejs/node/pull/53058 * (SEMVER-MINOR) add `NODE_RUN_SCRIPT_NAME` env to `node --run` (Yagiz Nizipli) https://github.com/nodejs/node/pull/53032 doc: * (SEMVER-MINOR) add context.assert docs (Colin Ihrig) https://github.com/nodejs/node/pull/53169 * (SEMVER-MINOR) improve explanation about built-in modules (Joyee Cheung) https://github.com/nodejs/node/pull/52762 * add StefanStojanovic to collaborators (StefanStojanovic) https://github.com/nodejs/node/pull/53118 * add Marco Ippolito to TSC (Rafael Gonzaga) https://github.com/nodejs/node/pull/53008 fs: * mark recursive cp methods as stable (Théo LUDWIG) https://github.com/nodejs/node/pull/53127 lib: * (SEMVER-MINOR) add EventSource Client (Aras Abbasi) https://github.com/nodejs/node/pull/51575 * (SEMVER-MINOR) replace MessageEvent with undici's (Matthew Aitken) https://github.com/nodejs/node/pull/52370 module: * (SEMVER-MINOR) print amount of load time of a cjs module (Vinicius Lourenço) https://github.com/nodejs/node/pull/52213 net: * (SEMVER-MINOR) add new net.server.listen tracing channel (Paolo Insogna) https://github.com/nodejs/node/pull/53136 process: * (SEMVER-MINOR) add process.getBuiltinModule(id) (Joyee Cheung) https://github.com/nodejs/node/pull/52762 src: * (SEMVER-MINOR) traverse parent folders while running `--run` (Yagiz Nizipli) https://github.com/nodejs/node/pull/53154 src,permission: * (SEMVER-MINOR) --allow-wasi & prevent WASI exec (Rafael Gonzaga) https://github.com/nodejs/node/pull/53124 test_runner: * (SEMVER-MINOR) add snapshot testing (Colin Ihrig) https://github.com/nodejs/node/pull/53169 * (SEMVER-MINOR) add context.fullName (Colin Ihrig) https://github.com/nodejs/node/pull/53169 * (SEMVER-MINOR) support module mocking (Colin Ihrig) https://github.com/nodejs/node/pull/52848 PR-URL: https://github.com/nodejs/node/pull/53379
2024-06-07 10:47:50 -03:00
added: v22.3.0
-->
* `value` {any} A value to serialize to a string. If Node.js was started with
the [`--test-update-snapshots`][] flag, the serialized value is written to
the snapshot file. Otherwise, the serialized value is compared to the
corresponding value in the existing snapshot file.
* `options` {Object} Optional configuration options. The following properties
are supported:
* `serializers` {Array} An array of synchronous functions used to serialize
`value` into a string. `value` is passed as the only argument to the first
serializer function. The return value of each serializer is passed as input
to the next serializer. Once all serializers have run, the resulting value
is coerced to a string. **Default:** If no serializers are provided, the
test runner's default serializers are used.
This function implements assertions for snapshot testing.
```js
test('snapshot test with default serialization', (t) => {
t.assert.snapshot({ value1: 1, value2: 2 });
});
test('snapshot test with custom serialization', (t) => {
t.assert.snapshot({ value3: 3, value4: 4 }, {
serializers: [(value) => JSON.stringify(value)],
});
});
```
### `context.diagnostic(message)`
<!-- YAML
2022-08-16, Version 16.17.0 'Gallium' (LTS) Notable changes: Adds `util.parseArgs` helper for higher level command-line argument parsing. Contributed by Benjamin Coe, John Gee, Darcy Clarke, Joe Sepi, Kevin Gibbons, Aaron Casanova, Jessica Nahulan, and Jordan Harband. https://github.com/nodejs/node/pull/42675 Node.js ESM Loader hooks now support multiple custom loaders, and composition is achieved via "chaining": `foo-loader` calls `bar-loader` calls `qux-loader` (a custom loader _must_ now signal a short circuit when intentionally not calling the next). See the ESM docs (https://nodejs.org/dist/latest-v16.x/docs/api/esm.html) for details. Contributed by Jacob Smith, Geoffrey Booth, and Bradley Farias. https://github.com/nodejs/node/pull/42623 The `node:test` module, which was initially introduced in Node.js v18.0.0, is now available with all the changes done to it up to Node.js v18.7.0. To better align Node.js' experimental implementation of the Web Crypto API with other runtimes, several changes were made: * Support for CFRG curves was added, with the `'Ed25519'`, `'Ed448'`, `'X25519'`, and `'X448'` algorithms. * The proprietary `'NODE-DSA'`, `'NODE-DH'`, `'NODE-SCRYPT'`, `'NODE-ED25519'`, `'NODE-ED448'`, `'NODE-X25519'`, and `'NODE-X448'` algorithms were removed. * The proprietary `'node.keyObject'` import/export format was removed. Contributed by Filip Skokan. https://github.com/nodejs/node/pull/42507 https://github.com/nodejs/node/pull/43310 Updated Corepack to 0.12.1 - https://github.com/nodejs/node/pull/43965 Updated ICU to 71.1 - https://github.com/nodejs/node/pull/42655 Updated npm to 8.15.0 - https://github.com/nodejs/node/pull/43917 Updated Undici to 5.8.0 - https://github.com/nodejs/node/pull/43886 (SEMVER-MINOR) crypto: make authTagLength optional for CC20P1305 (Tobias Nießen) https://github.com/nodejs/node/pull/42427 (SEMVER-MINOR) crypto: align webcrypto RSA key import/export with other implementations (Filip Skokan) https://github.com/nodejs/node/pull/42816 (SEMVER-MINOR) dns: export error code constants from `dns/promises` (Feng Yu) https://github.com/nodejs/node/pull/43176 doc: deprecate coercion to integer in process.exit (Daeyeon Jeong) https://github.com/nodejs/node/pull/43738 (SEMVER-MINOR) doc: deprecate diagnostics_channel object subscribe method (Stephen Belanger) https://github.com/nodejs/node/pull/42714 (SEMVER-MINOR) errors: add support for cause in aborterror (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) events: expose CustomEvent on global with CLI flag (Daeyeon Jeong) https://github.com/nodejs/node/pull/43885 (SEMVER-MINOR) events: add `CustomEvent` (Daeyeon Jeong) https://github.com/nodejs/node/pull/43514 (SEMVER-MINOR) events: propagate abortsignal reason in new AbortError ctor in events (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) fs: propagate abortsignal reason in new AbortSignal constructors (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) fs: make params in writing methods optional (LiviaMedeiros) https://github.com/nodejs/node/pull/42601 (SEMVER-MINOR) fs: add `read(buffer[, options])` versions (LiviaMedeiros) https://github.com/nodejs/node/pull/42768 (SEMVER-MINOR) http: add drop request event for http server (theanarkh) https://github.com/nodejs/node/pull/43806 (SEMVER-MINOR) http: add diagnostics channel for http client (theanarkh) https://github.com/nodejs/node/pull/43580 (SEMVER-MINOR) http: add perf_hooks detail for http request and client (theanarkh) https://github.com/nodejs/node/pull/43361 (SEMVER-MINOR) http: add uniqueHeaders option to request and createServer (Paolo Insogna) https://github.com/nodejs/node/pull/41397 (SEMVER-MINOR) http2: propagate abortsignal reason in new AbortError constructor (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) http2: compat support for array headers (OneNail) https://github.com/nodejs/node/pull/42901 (SEMVER-MINOR) lib: propagate abortsignal reason in new AbortError constructor in blob (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) lib: add abortSignal.throwIfAborted() (James M Snell) https://github.com/nodejs/node/pull/40951 (SEMVER-MINOR) lib: improved diagnostics_channel subscribe/unsubscribe (Stephen Belanger) https://github.com/nodejs/node/pull/42714 (SEMVER-MINOR) module: add isBuiltIn method (hemanth.hm) https://github.com/nodejs/node/pull/43396 (SEMVER-MINOR) module,repl: support 'node:'-only core modules (Colin Ihrig) https://github.com/nodejs/node/pull/42325 (SEMVER-MINOR) net: add drop event for net server (theanarkh) https://github.com/nodejs/node/pull/43582 (SEMVER-MINOR) net: add ability to reset a tcp socket (pupilTong) https://github.com/nodejs/node/pull/43112 (SEMVER-MINOR) node-api: emit uncaught-exception on unhandled tsfn callbacks (Chengzhong Wu) https://github.com/nodejs/node/pull/36510 (SEMVER-MINOR) perf_hooks: add PerformanceResourceTiming (RafaelGSS) https://github.com/nodejs/node/pull/42725 (SEMVER-MINOR) report: add more heap infos in process report (theanarkh) https://github.com/nodejs/node/pull/43116 (SEMVER-MINOR) src: add --openssl-legacy-provider option (Daniel Bevenius) https://github.com/nodejs/node/pull/40478 (SEMVER-MINOR) src: define fs.constants.S_IWUSR & S_IRUSR for Win (Liviu Ionescu) https://github.com/nodejs/node/pull/42757 (SEMVER-MINOR) src,doc,test: add --openssl-shared-config option (Daniel Bevenius) https://github.com/nodejs/node/pull/43124 (SEMVER-MINOR) stream: use cause options in AbortError constructors (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) stream: add iterator helper find (Nitzan Uziely) https://github.com/nodejs/node/pull/41849 (SEMVER-MINOR) stream: add writableAborted (Robert Nagy) https://github.com/nodejs/node/pull/40802 (SEMVER-MINOR) timers: propagate signal.reason in awaitable timers (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) v8: add v8.startupSnapshot utils (Joyee Cheung) https://github.com/nodejs/node/pull/43329 (SEMVER-MINOR) v8: export more fields in getHeapStatistics (theanarkh) https://github.com/nodejs/node/pull/42784 (SEMVER-MINOR) worker: add hasRef() to MessagePort (Darshan Sen) https://github.com/nodejs/node/pull/42849 PR-URL: https://github.com/nodejs/node/pull/44098
2022-08-02 14:34:18 +02:00
added:
- v18.0.0
- v16.17.0
-->
* `message` {string} Message to be reported.
This function is used to write diagnostics to the output. Any diagnostic
information is included at the end of the test's results. This function does
not return a value.
```js
test('top level test', (t) => {
t.diagnostic('A diagnostic message');
});
```
### `context.filePath`
<!-- YAML
added:
- v22.6.0
- v20.16.0
-->
The absolute path of the test file that created the current test. If a test file
imports additional modules that generate tests, the imported tests will return
the path of the root test file.
### `context.fullName`
<!-- YAML
2024-06-11, Version 22.3.0 (Current) Notable changes: buffer: * (SEMVER-MINOR) add .bytes() method to Blob (Matthew Aitken) https://github.com/nodejs/node/pull/53221 cli: * (SEMVER-MINOR) add `NODE_RUN_PACKAGE_JSON_PATH` env (Yagiz Nizipli) https://github.com/nodejs/node/pull/53058 * (SEMVER-MINOR) add `NODE_RUN_SCRIPT_NAME` env to `node --run` (Yagiz Nizipli) https://github.com/nodejs/node/pull/53032 doc: * (SEMVER-MINOR) add context.assert docs (Colin Ihrig) https://github.com/nodejs/node/pull/53169 * (SEMVER-MINOR) improve explanation about built-in modules (Joyee Cheung) https://github.com/nodejs/node/pull/52762 * add StefanStojanovic to collaborators (StefanStojanovic) https://github.com/nodejs/node/pull/53118 * add Marco Ippolito to TSC (Rafael Gonzaga) https://github.com/nodejs/node/pull/53008 fs: * mark recursive cp methods as stable (Théo LUDWIG) https://github.com/nodejs/node/pull/53127 lib: * (SEMVER-MINOR) add EventSource Client (Aras Abbasi) https://github.com/nodejs/node/pull/51575 * (SEMVER-MINOR) replace MessageEvent with undici's (Matthew Aitken) https://github.com/nodejs/node/pull/52370 module: * (SEMVER-MINOR) print amount of load time of a cjs module (Vinicius Lourenço) https://github.com/nodejs/node/pull/52213 net: * (SEMVER-MINOR) add new net.server.listen tracing channel (Paolo Insogna) https://github.com/nodejs/node/pull/53136 process: * (SEMVER-MINOR) add process.getBuiltinModule(id) (Joyee Cheung) https://github.com/nodejs/node/pull/52762 src: * (SEMVER-MINOR) traverse parent folders while running `--run` (Yagiz Nizipli) https://github.com/nodejs/node/pull/53154 src,permission: * (SEMVER-MINOR) --allow-wasi & prevent WASI exec (Rafael Gonzaga) https://github.com/nodejs/node/pull/53124 test_runner: * (SEMVER-MINOR) add snapshot testing (Colin Ihrig) https://github.com/nodejs/node/pull/53169 * (SEMVER-MINOR) add context.fullName (Colin Ihrig) https://github.com/nodejs/node/pull/53169 * (SEMVER-MINOR) support module mocking (Colin Ihrig) https://github.com/nodejs/node/pull/52848 PR-URL: https://github.com/nodejs/node/pull/53379
2024-06-07 10:47:50 -03:00
added: v22.3.0
-->
The name of the test and each of its ancestors, separated by `>`.
### `context.name`
<!-- YAML
2022-10-12, Version 16.18.0 'Gallium' (LTS) Notable changes: assert: add `getCalls` and `reset` to callTracker (Moshe Atlow) https://github.com/nodejs/node/pull/44191 crypto: allow zero-length secret KeyObject (Filip Skokan) https://github.com/nodejs/node/pull/44201 crypto: allow zero-length IKM in HKDF and in webcrypto PBKDF2 (Filip Skokan) https://github.com/nodejs/node/pull/44201 doc: deprecate modp1, modp2, and modp5 groups (Tobias Nießen) https://github.com/nodejs/node/pull/44588 http: make idle http parser count configurable (theanarkh) https://github.com/nodejs/node/pull/43974 http: throw error on content-length mismatch (sidwebworks) https://github.com/nodejs/node/pull/44378 lib: add diagnostics channel for process and worker (theanarkh) https://github.com/nodejs/node/pull/44045 net,tls: pass a valid socket on `tlsClientError` (Daeyeon Jeong) https://github.com/nodejs/node/pull/44021 net: add local family (theanarkh) https://github.com/nodejs/node/pull/43975 report: expose report public native apis (Chengzhong Wu) https://github.com/nodejs/node/pull/44255 src: expose environment RequestInterrupt api (Chengzhong Wu) https://github.com/nodejs/node/pull/44362 stream: add `ReadableByteStream.tee()` (Daeyeon Jeong) https://github.com/nodejs/node/pull/44505 test_runner: add before/after/each hooks (Moshe Atlow) https://github.com/nodejs/node/pull/43730 util: add `maxArrayLength` option to Set and Map (Kohei Ueno) https://github.com/nodejs/node/pull/43576 PR-URL: https://github.com/nodejs/node/pull/44886
2022-10-11 14:54:19 -05:00
added:
- v18.8.0
- v16.18.0
-->
The name of the test.
### `context.plan(count[,options])`
<!-- YAML
added:
- v22.2.0
- v20.15.0
changes:
- version:
- v23.9.0
2025-04-23, Version 22.15.0 'Jod' (LTS) Notable changes: assert: * (SEMVER-MINOR) implement partial error comparison (Ruben Bridgewater) https://github.com/nodejs/node/pull/57370 * (SEMVER-MINOR) improve partialDeepStrictEqual (Ruben Bridgewater) https://github.com/nodejs/node/pull/57370 cli: * (SEMVER-MINOR) allow --cpu-prof* in NODE_OPTIONS (Carlos Espa) https://github.com/nodejs/node/pull/57018 crypto: * update root certificates to NSS 3.108 (Node.js GitHub Bot) https://github.com/nodejs/node/pull/57381 * (SEMVER-MINOR) support --use-system-ca on Windows (Joyee Cheung) https://github.com/nodejs/node/pull/56833 * (SEMVER-MINOR) added support for reading certificates from macOS system store (Tim Jacomb) https://github.com/nodejs/node/pull/56599 deps: * update timezone to 2025a (Node.js GitHub Bot) https://github.com/nodejs/node/pull/56876 deps,tools: * (SEMVER-MINOR) add zstd 1.5.6 (Jan Martin) https://github.com/nodejs/node/pull/52100 dns: * (SEMVER-MINOR) add TLSA record query and parsing (Rithvik Vibhu) https://github.com/nodejs/node/pull/52983 doc: * add @geeksilva97 to collaborators (Edy Silva) https://github.com/nodejs/node/pull/57241 module: * (SEMVER-MINOR) use synchronous hooks for preparsing in import(cjs) (Joyee Cheung) https://github.com/nodejs/node/pull/55698 * (SEMVER-MINOR) implement module.registerHooks() (Joyee Cheung) https://github.com/nodejs/node/pull/55698 process: * (SEMVER-MINOR) add execve (Paolo Insogna) https://github.com/nodejs/node/pull/56496 * (SEMVER-MINOR) add threadCpuUsage (Paolo Insogna) https://github.com/nodejs/node/pull/56467 sqlite: * (SEMVER-MINOR) add StatementSync.prototype.columns() (Colin Ihrig) https://github.com/nodejs/node/pull/57490 * (SEMVER-MINOR) allow returning `ArrayBufferView`s from user-defined functions (René) https://github.com/nodejs/node/pull/56790 src: * set signal inspector io thread name (RafaelGSS) https://github.com/nodejs/node/pull/56416 * set thread name for main thread and v8 worker (RafaelGSS) https://github.com/nodejs/node/pull/56416 * set worker thread name using worker.name (RafaelGSS) https://github.com/nodejs/node/pull/56416 * use a default thread name for inspector (RafaelGSS) https://github.com/nodejs/node/pull/56416 tls: * (SEMVER-MINOR) implement tls.getCACertificates() (Joyee Cheung) https://github.com/nodejs/node/pull/57107 util: * (SEMVER-MINOR) expose diff function used by the assertion errors (Giovanni Bucci) https://github.com/nodejs/node/pull/57462 v8: * (SEMVER-MINOR) add v8.getCppHeapStatistics() method (Aditi) https://github.com/nodejs/node/pull/57146 zlib: * (SEMVER-MINOR) add zstd support (Jan Martin) https://github.com/nodejs/node/pull/52100 PR-URL: https://github.com/nodejs/node/pull/57840
2025-04-11 17:38:28 -03:00
- v22.15.0
pr-url: https://github.com/nodejs/node/pull/56765
description: Add the `options` parameter.
2025-01-07, Version 22.13.0 'Jod' (LTS) Notable changes: assert: * (SEMVER-MINOR) add partialDeepStrictEqual (Giovanni Bucci) https://github.com/nodejs/node/pull/54630 cli: * (SEMVER-MINOR) implement --trace-env and --trace-env-[js|native]-stack (Joyee Cheung) https://github.com/nodejs/node/pull/55604 crypto: * graduate WebCryptoAPI Ed25519 and X25519 algorithms as stable (Filip Skokan) https://github.com/nodejs/node/pull/56142 dgram: * (SEMVER-MINOR) support blocklist in udp (theanarkh) https://github.com/nodejs/node/pull/56087 doc: * stabilize util.styleText (Rafael Gonzaga) https://github.com/nodejs/node/pull/56265 * move typescript support to active development (Marco Ippolito) https://github.com/nodejs/node/pull/55536 * add LJHarb to collaborators (Jordan Harband) https://github.com/nodejs/node/pull/56132 * (SEMVER-MINOR) add report version and history section (Chengzhong Wu) https://github.com/nodejs/node/pull/56130 * (SEMVER-MINOR) sort --report-exclude alphabetically (Rafael Gonzaga) https://github.com/nodejs/node/pull/55788 doc,lib,src,test: * (SEMVER-MINOR) unflag sqlite module (Colin Ihrig) https://github.com/nodejs/node/pull/55890 module: * (SEMVER-MINOR) only emit require(esm) warning under --trace-require-module (Joyee Cheung) https://github.com/nodejs/node/pull/56194 * (SEMVER-MINOR) add module.stripTypeScriptTypes (Marco Ippolito) https://github.com/nodejs/node/pull/55282 net: * (SEMVER-MINOR) support blocklist in net.connect (theanarkh) https://github.com/nodejs/node/pull/56075 * (SEMVER-MINOR) add SocketAddress.parse (James M Snell) https://github.com/nodejs/node/pull/56076 * (SEMVER-MINOR) add net.BlockList.isBlockList(value) (James M Snell) https://github.com/nodejs/node/pull/56078 * (SEMVER-MINOR) support blocklist for net.Server (theanarkh) https://github.com/nodejs/node/pull/56079 process: * (SEMVER-MINOR) deprecate `features.{ipv6,uv}` and `features.tls_*` (René) https://github.com/nodejs/node/pull/55545 report: * (SEMVER-MINOR) fix typos in report keys and bump the version (Yuan-Ming Hsu) https://github.com/nodejs/node/pull/56068 sqlite: * (SEMVER-MINOR) aggregate constants in a single property (Edigleysson Silva (Edy)) https://github.com/nodejs/node/pull/56213 * (SEMVER-MINOR) add `StatementSync.prototype.iterate` method (tpoisseau) https://github.com/nodejs/node/pull/54213 src: * (SEMVER-MINOR) add cli option to preserve env vars on dr (Rafael Gonzaga) https://github.com/nodejs/node/pull/55697 src,lib: * (SEMVER-MINOR) stabilize permission model (Rafael Gonzaga) https://github.com/nodejs/node/pull/56201 util: * (SEMVER-MINOR) add sourcemap support to getCallSites (Marco Ippolito) https://github.com/nodejs/node/pull/55589 PR-URL: https://github.com/nodejs/node/pull/56329
2025-01-05 13:33:23 -05:00
- version:
- v23.4.0
- v22.13.0
pr-url: https://github.com/nodejs/node/pull/55895
description: This function is no longer experimental.
-->
* `count` {number} The number of assertions and subtests that are expected to run.
* `options` {Object} Additional options for the plan.
* `wait` {boolean|number} The wait time for the plan:
* If `true`, the plan waits indefinitely for all assertions and subtests to run.
* If `false`, the plan performs an immediate check after the test function completes,
without waiting for any pending assertions or subtests.
Any assertions or subtests that complete after this check will not be counted towards the plan.
* If a number, it specifies the maximum wait time in milliseconds
before timing out while waiting for expected assertions and subtests to be matched.
If the timeout is reached, the test will fail.
**Default:** `false`.
This function is used to set the number of assertions and subtests that are expected to run
within the test. If the number of assertions and subtests that run does not match the
expected count, the test will fail.
> Note: To make sure assertions are tracked, `t.assert` must be used instead of `assert` directly.
```js
test('top level test', (t) => {
t.plan(2);
t.assert.ok('some relevant assertion here');
t.test('subtest', () => {});
});
```
When working with asynchronous code, the `plan` function can be used to ensure that the
correct number of assertions are run:
```js
test('planning with streams', (t, done) => {
function* generate() {
yield 'a';
yield 'b';
yield 'c';
}
const expected = ['a', 'b', 'c'];
t.plan(expected.length);
const stream = Readable.from(generate());
stream.on('data', (chunk) => {
t.assert.strictEqual(chunk, expected.shift());
});
stream.on('end', () => {
done();
});
});
```
When using the `wait` option, you can control how long the test will wait for the expected assertions.
For example, setting a maximum wait time ensures that the test will wait for asynchronous assertions
to complete within the specified timeframe:
```js
test('plan with wait: 2000 waits for async assertions', (t) => {
t.plan(1, { wait: 2000 }); // Waits for up to 2 seconds for the assertion to complete.
const asyncActivity = () => {
setTimeout(() => {
t.assert.ok(true, 'Async assertion completed within the wait time');
}, 1000); // Completes after 1 second, within the 2-second wait time.
};
asyncActivity(); // The test will pass because the assertion is completed in time.
});
```
Note: If a `wait` timeout is specified, it begins counting down only after the test function finishes executing.
### `context.runOnly(shouldRunOnlyTests)`
<!-- YAML
2022-08-16, Version 16.17.0 'Gallium' (LTS) Notable changes: Adds `util.parseArgs` helper for higher level command-line argument parsing. Contributed by Benjamin Coe, John Gee, Darcy Clarke, Joe Sepi, Kevin Gibbons, Aaron Casanova, Jessica Nahulan, and Jordan Harband. https://github.com/nodejs/node/pull/42675 Node.js ESM Loader hooks now support multiple custom loaders, and composition is achieved via "chaining": `foo-loader` calls `bar-loader` calls `qux-loader` (a custom loader _must_ now signal a short circuit when intentionally not calling the next). See the ESM docs (https://nodejs.org/dist/latest-v16.x/docs/api/esm.html) for details. Contributed by Jacob Smith, Geoffrey Booth, and Bradley Farias. https://github.com/nodejs/node/pull/42623 The `node:test` module, which was initially introduced in Node.js v18.0.0, is now available with all the changes done to it up to Node.js v18.7.0. To better align Node.js' experimental implementation of the Web Crypto API with other runtimes, several changes were made: * Support for CFRG curves was added, with the `'Ed25519'`, `'Ed448'`, `'X25519'`, and `'X448'` algorithms. * The proprietary `'NODE-DSA'`, `'NODE-DH'`, `'NODE-SCRYPT'`, `'NODE-ED25519'`, `'NODE-ED448'`, `'NODE-X25519'`, and `'NODE-X448'` algorithms were removed. * The proprietary `'node.keyObject'` import/export format was removed. Contributed by Filip Skokan. https://github.com/nodejs/node/pull/42507 https://github.com/nodejs/node/pull/43310 Updated Corepack to 0.12.1 - https://github.com/nodejs/node/pull/43965 Updated ICU to 71.1 - https://github.com/nodejs/node/pull/42655 Updated npm to 8.15.0 - https://github.com/nodejs/node/pull/43917 Updated Undici to 5.8.0 - https://github.com/nodejs/node/pull/43886 (SEMVER-MINOR) crypto: make authTagLength optional for CC20P1305 (Tobias Nießen) https://github.com/nodejs/node/pull/42427 (SEMVER-MINOR) crypto: align webcrypto RSA key import/export with other implementations (Filip Skokan) https://github.com/nodejs/node/pull/42816 (SEMVER-MINOR) dns: export error code constants from `dns/promises` (Feng Yu) https://github.com/nodejs/node/pull/43176 doc: deprecate coercion to integer in process.exit (Daeyeon Jeong) https://github.com/nodejs/node/pull/43738 (SEMVER-MINOR) doc: deprecate diagnostics_channel object subscribe method (Stephen Belanger) https://github.com/nodejs/node/pull/42714 (SEMVER-MINOR) errors: add support for cause in aborterror (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) events: expose CustomEvent on global with CLI flag (Daeyeon Jeong) https://github.com/nodejs/node/pull/43885 (SEMVER-MINOR) events: add `CustomEvent` (Daeyeon Jeong) https://github.com/nodejs/node/pull/43514 (SEMVER-MINOR) events: propagate abortsignal reason in new AbortError ctor in events (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) fs: propagate abortsignal reason in new AbortSignal constructors (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) fs: make params in writing methods optional (LiviaMedeiros) https://github.com/nodejs/node/pull/42601 (SEMVER-MINOR) fs: add `read(buffer[, options])` versions (LiviaMedeiros) https://github.com/nodejs/node/pull/42768 (SEMVER-MINOR) http: add drop request event for http server (theanarkh) https://github.com/nodejs/node/pull/43806 (SEMVER-MINOR) http: add diagnostics channel for http client (theanarkh) https://github.com/nodejs/node/pull/43580 (SEMVER-MINOR) http: add perf_hooks detail for http request and client (theanarkh) https://github.com/nodejs/node/pull/43361 (SEMVER-MINOR) http: add uniqueHeaders option to request and createServer (Paolo Insogna) https://github.com/nodejs/node/pull/41397 (SEMVER-MINOR) http2: propagate abortsignal reason in new AbortError constructor (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) http2: compat support for array headers (OneNail) https://github.com/nodejs/node/pull/42901 (SEMVER-MINOR) lib: propagate abortsignal reason in new AbortError constructor in blob (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) lib: add abortSignal.throwIfAborted() (James M Snell) https://github.com/nodejs/node/pull/40951 (SEMVER-MINOR) lib: improved diagnostics_channel subscribe/unsubscribe (Stephen Belanger) https://github.com/nodejs/node/pull/42714 (SEMVER-MINOR) module: add isBuiltIn method (hemanth.hm) https://github.com/nodejs/node/pull/43396 (SEMVER-MINOR) module,repl: support 'node:'-only core modules (Colin Ihrig) https://github.com/nodejs/node/pull/42325 (SEMVER-MINOR) net: add drop event for net server (theanarkh) https://github.com/nodejs/node/pull/43582 (SEMVER-MINOR) net: add ability to reset a tcp socket (pupilTong) https://github.com/nodejs/node/pull/43112 (SEMVER-MINOR) node-api: emit uncaught-exception on unhandled tsfn callbacks (Chengzhong Wu) https://github.com/nodejs/node/pull/36510 (SEMVER-MINOR) perf_hooks: add PerformanceResourceTiming (RafaelGSS) https://github.com/nodejs/node/pull/42725 (SEMVER-MINOR) report: add more heap infos in process report (theanarkh) https://github.com/nodejs/node/pull/43116 (SEMVER-MINOR) src: add --openssl-legacy-provider option (Daniel Bevenius) https://github.com/nodejs/node/pull/40478 (SEMVER-MINOR) src: define fs.constants.S_IWUSR & S_IRUSR for Win (Liviu Ionescu) https://github.com/nodejs/node/pull/42757 (SEMVER-MINOR) src,doc,test: add --openssl-shared-config option (Daniel Bevenius) https://github.com/nodejs/node/pull/43124 (SEMVER-MINOR) stream: use cause options in AbortError constructors (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) stream: add iterator helper find (Nitzan Uziely) https://github.com/nodejs/node/pull/41849 (SEMVER-MINOR) stream: add writableAborted (Robert Nagy) https://github.com/nodejs/node/pull/40802 (SEMVER-MINOR) timers: propagate signal.reason in awaitable timers (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) v8: add v8.startupSnapshot utils (Joyee Cheung) https://github.com/nodejs/node/pull/43329 (SEMVER-MINOR) v8: export more fields in getHeapStatistics (theanarkh) https://github.com/nodejs/node/pull/42784 (SEMVER-MINOR) worker: add hasRef() to MessagePort (Darshan Sen) https://github.com/nodejs/node/pull/42849 PR-URL: https://github.com/nodejs/node/pull/44098
2022-08-02 14:34:18 +02:00
added:
- v18.0.0
- v16.17.0
-->
* `shouldRunOnlyTests` {boolean} Whether or not to run `only` tests.
If `shouldRunOnlyTests` is truthy, the test context will only run tests that
have the `only` option set. Otherwise, all tests are run. If Node.js was not
started with the [`--test-only`][] command-line option, this function is a
no-op.
```js
test('top level test', (t) => {
// The test context can be set to run subtests with the 'only' option.
t.runOnly(true);
t.test('this subtest is now skipped');
t.test('this subtest is run', { only: true });
});
```
### `context.signal`
<!-- YAML
2022-08-16, Version 16.17.0 'Gallium' (LTS) Notable changes: Adds `util.parseArgs` helper for higher level command-line argument parsing. Contributed by Benjamin Coe, John Gee, Darcy Clarke, Joe Sepi, Kevin Gibbons, Aaron Casanova, Jessica Nahulan, and Jordan Harband. https://github.com/nodejs/node/pull/42675 Node.js ESM Loader hooks now support multiple custom loaders, and composition is achieved via "chaining": `foo-loader` calls `bar-loader` calls `qux-loader` (a custom loader _must_ now signal a short circuit when intentionally not calling the next). See the ESM docs (https://nodejs.org/dist/latest-v16.x/docs/api/esm.html) for details. Contributed by Jacob Smith, Geoffrey Booth, and Bradley Farias. https://github.com/nodejs/node/pull/42623 The `node:test` module, which was initially introduced in Node.js v18.0.0, is now available with all the changes done to it up to Node.js v18.7.0. To better align Node.js' experimental implementation of the Web Crypto API with other runtimes, several changes were made: * Support for CFRG curves was added, with the `'Ed25519'`, `'Ed448'`, `'X25519'`, and `'X448'` algorithms. * The proprietary `'NODE-DSA'`, `'NODE-DH'`, `'NODE-SCRYPT'`, `'NODE-ED25519'`, `'NODE-ED448'`, `'NODE-X25519'`, and `'NODE-X448'` algorithms were removed. * The proprietary `'node.keyObject'` import/export format was removed. Contributed by Filip Skokan. https://github.com/nodejs/node/pull/42507 https://github.com/nodejs/node/pull/43310 Updated Corepack to 0.12.1 - https://github.com/nodejs/node/pull/43965 Updated ICU to 71.1 - https://github.com/nodejs/node/pull/42655 Updated npm to 8.15.0 - https://github.com/nodejs/node/pull/43917 Updated Undici to 5.8.0 - https://github.com/nodejs/node/pull/43886 (SEMVER-MINOR) crypto: make authTagLength optional for CC20P1305 (Tobias Nießen) https://github.com/nodejs/node/pull/42427 (SEMVER-MINOR) crypto: align webcrypto RSA key import/export with other implementations (Filip Skokan) https://github.com/nodejs/node/pull/42816 (SEMVER-MINOR) dns: export error code constants from `dns/promises` (Feng Yu) https://github.com/nodejs/node/pull/43176 doc: deprecate coercion to integer in process.exit (Daeyeon Jeong) https://github.com/nodejs/node/pull/43738 (SEMVER-MINOR) doc: deprecate diagnostics_channel object subscribe method (Stephen Belanger) https://github.com/nodejs/node/pull/42714 (SEMVER-MINOR) errors: add support for cause in aborterror (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) events: expose CustomEvent on global with CLI flag (Daeyeon Jeong) https://github.com/nodejs/node/pull/43885 (SEMVER-MINOR) events: add `CustomEvent` (Daeyeon Jeong) https://github.com/nodejs/node/pull/43514 (SEMVER-MINOR) events: propagate abortsignal reason in new AbortError ctor in events (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) fs: propagate abortsignal reason in new AbortSignal constructors (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) fs: make params in writing methods optional (LiviaMedeiros) https://github.com/nodejs/node/pull/42601 (SEMVER-MINOR) fs: add `read(buffer[, options])` versions (LiviaMedeiros) https://github.com/nodejs/node/pull/42768 (SEMVER-MINOR) http: add drop request event for http server (theanarkh) https://github.com/nodejs/node/pull/43806 (SEMVER-MINOR) http: add diagnostics channel for http client (theanarkh) https://github.com/nodejs/node/pull/43580 (SEMVER-MINOR) http: add perf_hooks detail for http request and client (theanarkh) https://github.com/nodejs/node/pull/43361 (SEMVER-MINOR) http: add uniqueHeaders option to request and createServer (Paolo Insogna) https://github.com/nodejs/node/pull/41397 (SEMVER-MINOR) http2: propagate abortsignal reason in new AbortError constructor (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) http2: compat support for array headers (OneNail) https://github.com/nodejs/node/pull/42901 (SEMVER-MINOR) lib: propagate abortsignal reason in new AbortError constructor in blob (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) lib: add abortSignal.throwIfAborted() (James M Snell) https://github.com/nodejs/node/pull/40951 (SEMVER-MINOR) lib: improved diagnostics_channel subscribe/unsubscribe (Stephen Belanger) https://github.com/nodejs/node/pull/42714 (SEMVER-MINOR) module: add isBuiltIn method (hemanth.hm) https://github.com/nodejs/node/pull/43396 (SEMVER-MINOR) module,repl: support 'node:'-only core modules (Colin Ihrig) https://github.com/nodejs/node/pull/42325 (SEMVER-MINOR) net: add drop event for net server (theanarkh) https://github.com/nodejs/node/pull/43582 (SEMVER-MINOR) net: add ability to reset a tcp socket (pupilTong) https://github.com/nodejs/node/pull/43112 (SEMVER-MINOR) node-api: emit uncaught-exception on unhandled tsfn callbacks (Chengzhong Wu) https://github.com/nodejs/node/pull/36510 (SEMVER-MINOR) perf_hooks: add PerformanceResourceTiming (RafaelGSS) https://github.com/nodejs/node/pull/42725 (SEMVER-MINOR) report: add more heap infos in process report (theanarkh) https://github.com/nodejs/node/pull/43116 (SEMVER-MINOR) src: add --openssl-legacy-provider option (Daniel Bevenius) https://github.com/nodejs/node/pull/40478 (SEMVER-MINOR) src: define fs.constants.S_IWUSR & S_IRUSR for Win (Liviu Ionescu) https://github.com/nodejs/node/pull/42757 (SEMVER-MINOR) src,doc,test: add --openssl-shared-config option (Daniel Bevenius) https://github.com/nodejs/node/pull/43124 (SEMVER-MINOR) stream: use cause options in AbortError constructors (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) stream: add iterator helper find (Nitzan Uziely) https://github.com/nodejs/node/pull/41849 (SEMVER-MINOR) stream: add writableAborted (Robert Nagy) https://github.com/nodejs/node/pull/40802 (SEMVER-MINOR) timers: propagate signal.reason in awaitable timers (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) v8: add v8.startupSnapshot utils (Joyee Cheung) https://github.com/nodejs/node/pull/43329 (SEMVER-MINOR) v8: export more fields in getHeapStatistics (theanarkh) https://github.com/nodejs/node/pull/42784 (SEMVER-MINOR) worker: add hasRef() to MessagePort (Darshan Sen) https://github.com/nodejs/node/pull/42849 PR-URL: https://github.com/nodejs/node/pull/44098
2022-08-02 14:34:18 +02:00
added:
- v18.7.0
- v16.17.0
-->
* Type: {AbortSignal}
Can be used to abort test subtasks when the test has been aborted.
```js
test('top level test', async (t) => {
await fetch('some/uri', { signal: t.signal });
});
```
### `context.skip([message])`
<!-- YAML
2022-08-16, Version 16.17.0 'Gallium' (LTS) Notable changes: Adds `util.parseArgs` helper for higher level command-line argument parsing. Contributed by Benjamin Coe, John Gee, Darcy Clarke, Joe Sepi, Kevin Gibbons, Aaron Casanova, Jessica Nahulan, and Jordan Harband. https://github.com/nodejs/node/pull/42675 Node.js ESM Loader hooks now support multiple custom loaders, and composition is achieved via "chaining": `foo-loader` calls `bar-loader` calls `qux-loader` (a custom loader _must_ now signal a short circuit when intentionally not calling the next). See the ESM docs (https://nodejs.org/dist/latest-v16.x/docs/api/esm.html) for details. Contributed by Jacob Smith, Geoffrey Booth, and Bradley Farias. https://github.com/nodejs/node/pull/42623 The `node:test` module, which was initially introduced in Node.js v18.0.0, is now available with all the changes done to it up to Node.js v18.7.0. To better align Node.js' experimental implementation of the Web Crypto API with other runtimes, several changes were made: * Support for CFRG curves was added, with the `'Ed25519'`, `'Ed448'`, `'X25519'`, and `'X448'` algorithms. * The proprietary `'NODE-DSA'`, `'NODE-DH'`, `'NODE-SCRYPT'`, `'NODE-ED25519'`, `'NODE-ED448'`, `'NODE-X25519'`, and `'NODE-X448'` algorithms were removed. * The proprietary `'node.keyObject'` import/export format was removed. Contributed by Filip Skokan. https://github.com/nodejs/node/pull/42507 https://github.com/nodejs/node/pull/43310 Updated Corepack to 0.12.1 - https://github.com/nodejs/node/pull/43965 Updated ICU to 71.1 - https://github.com/nodejs/node/pull/42655 Updated npm to 8.15.0 - https://github.com/nodejs/node/pull/43917 Updated Undici to 5.8.0 - https://github.com/nodejs/node/pull/43886 (SEMVER-MINOR) crypto: make authTagLength optional for CC20P1305 (Tobias Nießen) https://github.com/nodejs/node/pull/42427 (SEMVER-MINOR) crypto: align webcrypto RSA key import/export with other implementations (Filip Skokan) https://github.com/nodejs/node/pull/42816 (SEMVER-MINOR) dns: export error code constants from `dns/promises` (Feng Yu) https://github.com/nodejs/node/pull/43176 doc: deprecate coercion to integer in process.exit (Daeyeon Jeong) https://github.com/nodejs/node/pull/43738 (SEMVER-MINOR) doc: deprecate diagnostics_channel object subscribe method (Stephen Belanger) https://github.com/nodejs/node/pull/42714 (SEMVER-MINOR) errors: add support for cause in aborterror (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) events: expose CustomEvent on global with CLI flag (Daeyeon Jeong) https://github.com/nodejs/node/pull/43885 (SEMVER-MINOR) events: add `CustomEvent` (Daeyeon Jeong) https://github.com/nodejs/node/pull/43514 (SEMVER-MINOR) events: propagate abortsignal reason in new AbortError ctor in events (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) fs: propagate abortsignal reason in new AbortSignal constructors (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) fs: make params in writing methods optional (LiviaMedeiros) https://github.com/nodejs/node/pull/42601 (SEMVER-MINOR) fs: add `read(buffer[, options])` versions (LiviaMedeiros) https://github.com/nodejs/node/pull/42768 (SEMVER-MINOR) http: add drop request event for http server (theanarkh) https://github.com/nodejs/node/pull/43806 (SEMVER-MINOR) http: add diagnostics channel for http client (theanarkh) https://github.com/nodejs/node/pull/43580 (SEMVER-MINOR) http: add perf_hooks detail for http request and client (theanarkh) https://github.com/nodejs/node/pull/43361 (SEMVER-MINOR) http: add uniqueHeaders option to request and createServer (Paolo Insogna) https://github.com/nodejs/node/pull/41397 (SEMVER-MINOR) http2: propagate abortsignal reason in new AbortError constructor (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) http2: compat support for array headers (OneNail) https://github.com/nodejs/node/pull/42901 (SEMVER-MINOR) lib: propagate abortsignal reason in new AbortError constructor in blob (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) lib: add abortSignal.throwIfAborted() (James M Snell) https://github.com/nodejs/node/pull/40951 (SEMVER-MINOR) lib: improved diagnostics_channel subscribe/unsubscribe (Stephen Belanger) https://github.com/nodejs/node/pull/42714 (SEMVER-MINOR) module: add isBuiltIn method (hemanth.hm) https://github.com/nodejs/node/pull/43396 (SEMVER-MINOR) module,repl: support 'node:'-only core modules (Colin Ihrig) https://github.com/nodejs/node/pull/42325 (SEMVER-MINOR) net: add drop event for net server (theanarkh) https://github.com/nodejs/node/pull/43582 (SEMVER-MINOR) net: add ability to reset a tcp socket (pupilTong) https://github.com/nodejs/node/pull/43112 (SEMVER-MINOR) node-api: emit uncaught-exception on unhandled tsfn callbacks (Chengzhong Wu) https://github.com/nodejs/node/pull/36510 (SEMVER-MINOR) perf_hooks: add PerformanceResourceTiming (RafaelGSS) https://github.com/nodejs/node/pull/42725 (SEMVER-MINOR) report: add more heap infos in process report (theanarkh) https://github.com/nodejs/node/pull/43116 (SEMVER-MINOR) src: add --openssl-legacy-provider option (Daniel Bevenius) https://github.com/nodejs/node/pull/40478 (SEMVER-MINOR) src: define fs.constants.S_IWUSR & S_IRUSR for Win (Liviu Ionescu) https://github.com/nodejs/node/pull/42757 (SEMVER-MINOR) src,doc,test: add --openssl-shared-config option (Daniel Bevenius) https://github.com/nodejs/node/pull/43124 (SEMVER-MINOR) stream: use cause options in AbortError constructors (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) stream: add iterator helper find (Nitzan Uziely) https://github.com/nodejs/node/pull/41849 (SEMVER-MINOR) stream: add writableAborted (Robert Nagy) https://github.com/nodejs/node/pull/40802 (SEMVER-MINOR) timers: propagate signal.reason in awaitable timers (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) v8: add v8.startupSnapshot utils (Joyee Cheung) https://github.com/nodejs/node/pull/43329 (SEMVER-MINOR) v8: export more fields in getHeapStatistics (theanarkh) https://github.com/nodejs/node/pull/42784 (SEMVER-MINOR) worker: add hasRef() to MessagePort (Darshan Sen) https://github.com/nodejs/node/pull/42849 PR-URL: https://github.com/nodejs/node/pull/44098
2022-08-02 14:34:18 +02:00
added:
- v18.0.0
- v16.17.0
-->
* `message` {string} Optional skip message.
This function causes the test's output to indicate the test as skipped. If
`message` is provided, it is included in the output. Calling `skip()` does
not terminate execution of the test function. This function does not return a
value.
```js
test('top level test', (t) => {
// Make sure to return here as well if the test contains additional logic.
t.skip('this is skipped');
});
```
### `context.todo([message])`
<!-- YAML
2022-08-16, Version 16.17.0 'Gallium' (LTS) Notable changes: Adds `util.parseArgs` helper for higher level command-line argument parsing. Contributed by Benjamin Coe, John Gee, Darcy Clarke, Joe Sepi, Kevin Gibbons, Aaron Casanova, Jessica Nahulan, and Jordan Harband. https://github.com/nodejs/node/pull/42675 Node.js ESM Loader hooks now support multiple custom loaders, and composition is achieved via "chaining": `foo-loader` calls `bar-loader` calls `qux-loader` (a custom loader _must_ now signal a short circuit when intentionally not calling the next). See the ESM docs (https://nodejs.org/dist/latest-v16.x/docs/api/esm.html) for details. Contributed by Jacob Smith, Geoffrey Booth, and Bradley Farias. https://github.com/nodejs/node/pull/42623 The `node:test` module, which was initially introduced in Node.js v18.0.0, is now available with all the changes done to it up to Node.js v18.7.0. To better align Node.js' experimental implementation of the Web Crypto API with other runtimes, several changes were made: * Support for CFRG curves was added, with the `'Ed25519'`, `'Ed448'`, `'X25519'`, and `'X448'` algorithms. * The proprietary `'NODE-DSA'`, `'NODE-DH'`, `'NODE-SCRYPT'`, `'NODE-ED25519'`, `'NODE-ED448'`, `'NODE-X25519'`, and `'NODE-X448'` algorithms were removed. * The proprietary `'node.keyObject'` import/export format was removed. Contributed by Filip Skokan. https://github.com/nodejs/node/pull/42507 https://github.com/nodejs/node/pull/43310 Updated Corepack to 0.12.1 - https://github.com/nodejs/node/pull/43965 Updated ICU to 71.1 - https://github.com/nodejs/node/pull/42655 Updated npm to 8.15.0 - https://github.com/nodejs/node/pull/43917 Updated Undici to 5.8.0 - https://github.com/nodejs/node/pull/43886 (SEMVER-MINOR) crypto: make authTagLength optional for CC20P1305 (Tobias Nießen) https://github.com/nodejs/node/pull/42427 (SEMVER-MINOR) crypto: align webcrypto RSA key import/export with other implementations (Filip Skokan) https://github.com/nodejs/node/pull/42816 (SEMVER-MINOR) dns: export error code constants from `dns/promises` (Feng Yu) https://github.com/nodejs/node/pull/43176 doc: deprecate coercion to integer in process.exit (Daeyeon Jeong) https://github.com/nodejs/node/pull/43738 (SEMVER-MINOR) doc: deprecate diagnostics_channel object subscribe method (Stephen Belanger) https://github.com/nodejs/node/pull/42714 (SEMVER-MINOR) errors: add support for cause in aborterror (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) events: expose CustomEvent on global with CLI flag (Daeyeon Jeong) https://github.com/nodejs/node/pull/43885 (SEMVER-MINOR) events: add `CustomEvent` (Daeyeon Jeong) https://github.com/nodejs/node/pull/43514 (SEMVER-MINOR) events: propagate abortsignal reason in new AbortError ctor in events (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) fs: propagate abortsignal reason in new AbortSignal constructors (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) fs: make params in writing methods optional (LiviaMedeiros) https://github.com/nodejs/node/pull/42601 (SEMVER-MINOR) fs: add `read(buffer[, options])` versions (LiviaMedeiros) https://github.com/nodejs/node/pull/42768 (SEMVER-MINOR) http: add drop request event for http server (theanarkh) https://github.com/nodejs/node/pull/43806 (SEMVER-MINOR) http: add diagnostics channel for http client (theanarkh) https://github.com/nodejs/node/pull/43580 (SEMVER-MINOR) http: add perf_hooks detail for http request and client (theanarkh) https://github.com/nodejs/node/pull/43361 (SEMVER-MINOR) http: add uniqueHeaders option to request and createServer (Paolo Insogna) https://github.com/nodejs/node/pull/41397 (SEMVER-MINOR) http2: propagate abortsignal reason in new AbortError constructor (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) http2: compat support for array headers (OneNail) https://github.com/nodejs/node/pull/42901 (SEMVER-MINOR) lib: propagate abortsignal reason in new AbortError constructor in blob (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) lib: add abortSignal.throwIfAborted() (James M Snell) https://github.com/nodejs/node/pull/40951 (SEMVER-MINOR) lib: improved diagnostics_channel subscribe/unsubscribe (Stephen Belanger) https://github.com/nodejs/node/pull/42714 (SEMVER-MINOR) module: add isBuiltIn method (hemanth.hm) https://github.com/nodejs/node/pull/43396 (SEMVER-MINOR) module,repl: support 'node:'-only core modules (Colin Ihrig) https://github.com/nodejs/node/pull/42325 (SEMVER-MINOR) net: add drop event for net server (theanarkh) https://github.com/nodejs/node/pull/43582 (SEMVER-MINOR) net: add ability to reset a tcp socket (pupilTong) https://github.com/nodejs/node/pull/43112 (SEMVER-MINOR) node-api: emit uncaught-exception on unhandled tsfn callbacks (Chengzhong Wu) https://github.com/nodejs/node/pull/36510 (SEMVER-MINOR) perf_hooks: add PerformanceResourceTiming (RafaelGSS) https://github.com/nodejs/node/pull/42725 (SEMVER-MINOR) report: add more heap infos in process report (theanarkh) https://github.com/nodejs/node/pull/43116 (SEMVER-MINOR) src: add --openssl-legacy-provider option (Daniel Bevenius) https://github.com/nodejs/node/pull/40478 (SEMVER-MINOR) src: define fs.constants.S_IWUSR & S_IRUSR for Win (Liviu Ionescu) https://github.com/nodejs/node/pull/42757 (SEMVER-MINOR) src,doc,test: add --openssl-shared-config option (Daniel Bevenius) https://github.com/nodejs/node/pull/43124 (SEMVER-MINOR) stream: use cause options in AbortError constructors (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) stream: add iterator helper find (Nitzan Uziely) https://github.com/nodejs/node/pull/41849 (SEMVER-MINOR) stream: add writableAborted (Robert Nagy) https://github.com/nodejs/node/pull/40802 (SEMVER-MINOR) timers: propagate signal.reason in awaitable timers (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) v8: add v8.startupSnapshot utils (Joyee Cheung) https://github.com/nodejs/node/pull/43329 (SEMVER-MINOR) v8: export more fields in getHeapStatistics (theanarkh) https://github.com/nodejs/node/pull/42784 (SEMVER-MINOR) worker: add hasRef() to MessagePort (Darshan Sen) https://github.com/nodejs/node/pull/42849 PR-URL: https://github.com/nodejs/node/pull/44098
2022-08-02 14:34:18 +02:00
added:
- v18.0.0
- v16.17.0
-->
* `message` {string} Optional `TODO` message.
This function adds a `TODO` directive to the test's output. If `message` is
provided, it is included in the output. Calling `todo()` does not terminate
execution of the test function. This function does not return a value.
```js
test('top level test', (t) => {
// This test is marked as `TODO`
t.todo('this is a todo');
});
```
### `context.test([name][, options][, fn])`
<!-- YAML
2022-08-16, Version 16.17.0 'Gallium' (LTS) Notable changes: Adds `util.parseArgs` helper for higher level command-line argument parsing. Contributed by Benjamin Coe, John Gee, Darcy Clarke, Joe Sepi, Kevin Gibbons, Aaron Casanova, Jessica Nahulan, and Jordan Harband. https://github.com/nodejs/node/pull/42675 Node.js ESM Loader hooks now support multiple custom loaders, and composition is achieved via "chaining": `foo-loader` calls `bar-loader` calls `qux-loader` (a custom loader _must_ now signal a short circuit when intentionally not calling the next). See the ESM docs (https://nodejs.org/dist/latest-v16.x/docs/api/esm.html) for details. Contributed by Jacob Smith, Geoffrey Booth, and Bradley Farias. https://github.com/nodejs/node/pull/42623 The `node:test` module, which was initially introduced in Node.js v18.0.0, is now available with all the changes done to it up to Node.js v18.7.0. To better align Node.js' experimental implementation of the Web Crypto API with other runtimes, several changes were made: * Support for CFRG curves was added, with the `'Ed25519'`, `'Ed448'`, `'X25519'`, and `'X448'` algorithms. * The proprietary `'NODE-DSA'`, `'NODE-DH'`, `'NODE-SCRYPT'`, `'NODE-ED25519'`, `'NODE-ED448'`, `'NODE-X25519'`, and `'NODE-X448'` algorithms were removed. * The proprietary `'node.keyObject'` import/export format was removed. Contributed by Filip Skokan. https://github.com/nodejs/node/pull/42507 https://github.com/nodejs/node/pull/43310 Updated Corepack to 0.12.1 - https://github.com/nodejs/node/pull/43965 Updated ICU to 71.1 - https://github.com/nodejs/node/pull/42655 Updated npm to 8.15.0 - https://github.com/nodejs/node/pull/43917 Updated Undici to 5.8.0 - https://github.com/nodejs/node/pull/43886 (SEMVER-MINOR) crypto: make authTagLength optional for CC20P1305 (Tobias Nießen) https://github.com/nodejs/node/pull/42427 (SEMVER-MINOR) crypto: align webcrypto RSA key import/export with other implementations (Filip Skokan) https://github.com/nodejs/node/pull/42816 (SEMVER-MINOR) dns: export error code constants from `dns/promises` (Feng Yu) https://github.com/nodejs/node/pull/43176 doc: deprecate coercion to integer in process.exit (Daeyeon Jeong) https://github.com/nodejs/node/pull/43738 (SEMVER-MINOR) doc: deprecate diagnostics_channel object subscribe method (Stephen Belanger) https://github.com/nodejs/node/pull/42714 (SEMVER-MINOR) errors: add support for cause in aborterror (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) events: expose CustomEvent on global with CLI flag (Daeyeon Jeong) https://github.com/nodejs/node/pull/43885 (SEMVER-MINOR) events: add `CustomEvent` (Daeyeon Jeong) https://github.com/nodejs/node/pull/43514 (SEMVER-MINOR) events: propagate abortsignal reason in new AbortError ctor in events (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) fs: propagate abortsignal reason in new AbortSignal constructors (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) fs: make params in writing methods optional (LiviaMedeiros) https://github.com/nodejs/node/pull/42601 (SEMVER-MINOR) fs: add `read(buffer[, options])` versions (LiviaMedeiros) https://github.com/nodejs/node/pull/42768 (SEMVER-MINOR) http: add drop request event for http server (theanarkh) https://github.com/nodejs/node/pull/43806 (SEMVER-MINOR) http: add diagnostics channel for http client (theanarkh) https://github.com/nodejs/node/pull/43580 (SEMVER-MINOR) http: add perf_hooks detail for http request and client (theanarkh) https://github.com/nodejs/node/pull/43361 (SEMVER-MINOR) http: add uniqueHeaders option to request and createServer (Paolo Insogna) https://github.com/nodejs/node/pull/41397 (SEMVER-MINOR) http2: propagate abortsignal reason in new AbortError constructor (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) http2: compat support for array headers (OneNail) https://github.com/nodejs/node/pull/42901 (SEMVER-MINOR) lib: propagate abortsignal reason in new AbortError constructor in blob (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) lib: add abortSignal.throwIfAborted() (James M Snell) https://github.com/nodejs/node/pull/40951 (SEMVER-MINOR) lib: improved diagnostics_channel subscribe/unsubscribe (Stephen Belanger) https://github.com/nodejs/node/pull/42714 (SEMVER-MINOR) module: add isBuiltIn method (hemanth.hm) https://github.com/nodejs/node/pull/43396 (SEMVER-MINOR) module,repl: support 'node:'-only core modules (Colin Ihrig) https://github.com/nodejs/node/pull/42325 (SEMVER-MINOR) net: add drop event for net server (theanarkh) https://github.com/nodejs/node/pull/43582 (SEMVER-MINOR) net: add ability to reset a tcp socket (pupilTong) https://github.com/nodejs/node/pull/43112 (SEMVER-MINOR) node-api: emit uncaught-exception on unhandled tsfn callbacks (Chengzhong Wu) https://github.com/nodejs/node/pull/36510 (SEMVER-MINOR) perf_hooks: add PerformanceResourceTiming (RafaelGSS) https://github.com/nodejs/node/pull/42725 (SEMVER-MINOR) report: add more heap infos in process report (theanarkh) https://github.com/nodejs/node/pull/43116 (SEMVER-MINOR) src: add --openssl-legacy-provider option (Daniel Bevenius) https://github.com/nodejs/node/pull/40478 (SEMVER-MINOR) src: define fs.constants.S_IWUSR & S_IRUSR for Win (Liviu Ionescu) https://github.com/nodejs/node/pull/42757 (SEMVER-MINOR) src,doc,test: add --openssl-shared-config option (Daniel Bevenius) https://github.com/nodejs/node/pull/43124 (SEMVER-MINOR) stream: use cause options in AbortError constructors (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) stream: add iterator helper find (Nitzan Uziely) https://github.com/nodejs/node/pull/41849 (SEMVER-MINOR) stream: add writableAborted (Robert Nagy) https://github.com/nodejs/node/pull/40802 (SEMVER-MINOR) timers: propagate signal.reason in awaitable timers (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) v8: add v8.startupSnapshot utils (Joyee Cheung) https://github.com/nodejs/node/pull/43329 (SEMVER-MINOR) v8: export more fields in getHeapStatistics (theanarkh) https://github.com/nodejs/node/pull/42784 (SEMVER-MINOR) worker: add hasRef() to MessagePort (Darshan Sen) https://github.com/nodejs/node/pull/42849 PR-URL: https://github.com/nodejs/node/pull/44098
2022-08-02 14:34:18 +02:00
added:
- v18.0.0
- v16.17.0
changes:
- version:
- REPLACEME
pr-url: https://github.com/nodejs/node/pull/56664
description: This function no longer returns a `Promise`.
2022-10-12, Version 16.18.0 'Gallium' (LTS) Notable changes: assert: add `getCalls` and `reset` to callTracker (Moshe Atlow) https://github.com/nodejs/node/pull/44191 crypto: allow zero-length secret KeyObject (Filip Skokan) https://github.com/nodejs/node/pull/44201 crypto: allow zero-length IKM in HKDF and in webcrypto PBKDF2 (Filip Skokan) https://github.com/nodejs/node/pull/44201 doc: deprecate modp1, modp2, and modp5 groups (Tobias Nießen) https://github.com/nodejs/node/pull/44588 http: make idle http parser count configurable (theanarkh) https://github.com/nodejs/node/pull/43974 http: throw error on content-length mismatch (sidwebworks) https://github.com/nodejs/node/pull/44378 lib: add diagnostics channel for process and worker (theanarkh) https://github.com/nodejs/node/pull/44045 net,tls: pass a valid socket on `tlsClientError` (Daeyeon Jeong) https://github.com/nodejs/node/pull/44021 net: add local family (theanarkh) https://github.com/nodejs/node/pull/43975 report: expose report public native apis (Chengzhong Wu) https://github.com/nodejs/node/pull/44255 src: expose environment RequestInterrupt api (Chengzhong Wu) https://github.com/nodejs/node/pull/44362 stream: add `ReadableByteStream.tee()` (Daeyeon Jeong) https://github.com/nodejs/node/pull/44505 test_runner: add before/after/each hooks (Moshe Atlow) https://github.com/nodejs/node/pull/43730 util: add `maxArrayLength` option to Set and Map (Kohei Ueno) https://github.com/nodejs/node/pull/43576 PR-URL: https://github.com/nodejs/node/pull/44886
2022-10-11 14:54:19 -05:00
- version:
- v18.8.0
- v16.18.0
pr-url: https://github.com/nodejs/node/pull/43554
description: Add a `signal` option.
2022-08-16, Version 16.17.0 'Gallium' (LTS) Notable changes: Adds `util.parseArgs` helper for higher level command-line argument parsing. Contributed by Benjamin Coe, John Gee, Darcy Clarke, Joe Sepi, Kevin Gibbons, Aaron Casanova, Jessica Nahulan, and Jordan Harband. https://github.com/nodejs/node/pull/42675 Node.js ESM Loader hooks now support multiple custom loaders, and composition is achieved via "chaining": `foo-loader` calls `bar-loader` calls `qux-loader` (a custom loader _must_ now signal a short circuit when intentionally not calling the next). See the ESM docs (https://nodejs.org/dist/latest-v16.x/docs/api/esm.html) for details. Contributed by Jacob Smith, Geoffrey Booth, and Bradley Farias. https://github.com/nodejs/node/pull/42623 The `node:test` module, which was initially introduced in Node.js v18.0.0, is now available with all the changes done to it up to Node.js v18.7.0. To better align Node.js' experimental implementation of the Web Crypto API with other runtimes, several changes were made: * Support for CFRG curves was added, with the `'Ed25519'`, `'Ed448'`, `'X25519'`, and `'X448'` algorithms. * The proprietary `'NODE-DSA'`, `'NODE-DH'`, `'NODE-SCRYPT'`, `'NODE-ED25519'`, `'NODE-ED448'`, `'NODE-X25519'`, and `'NODE-X448'` algorithms were removed. * The proprietary `'node.keyObject'` import/export format was removed. Contributed by Filip Skokan. https://github.com/nodejs/node/pull/42507 https://github.com/nodejs/node/pull/43310 Updated Corepack to 0.12.1 - https://github.com/nodejs/node/pull/43965 Updated ICU to 71.1 - https://github.com/nodejs/node/pull/42655 Updated npm to 8.15.0 - https://github.com/nodejs/node/pull/43917 Updated Undici to 5.8.0 - https://github.com/nodejs/node/pull/43886 (SEMVER-MINOR) crypto: make authTagLength optional for CC20P1305 (Tobias Nießen) https://github.com/nodejs/node/pull/42427 (SEMVER-MINOR) crypto: align webcrypto RSA key import/export with other implementations (Filip Skokan) https://github.com/nodejs/node/pull/42816 (SEMVER-MINOR) dns: export error code constants from `dns/promises` (Feng Yu) https://github.com/nodejs/node/pull/43176 doc: deprecate coercion to integer in process.exit (Daeyeon Jeong) https://github.com/nodejs/node/pull/43738 (SEMVER-MINOR) doc: deprecate diagnostics_channel object subscribe method (Stephen Belanger) https://github.com/nodejs/node/pull/42714 (SEMVER-MINOR) errors: add support for cause in aborterror (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) events: expose CustomEvent on global with CLI flag (Daeyeon Jeong) https://github.com/nodejs/node/pull/43885 (SEMVER-MINOR) events: add `CustomEvent` (Daeyeon Jeong) https://github.com/nodejs/node/pull/43514 (SEMVER-MINOR) events: propagate abortsignal reason in new AbortError ctor in events (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) fs: propagate abortsignal reason in new AbortSignal constructors (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) fs: make params in writing methods optional (LiviaMedeiros) https://github.com/nodejs/node/pull/42601 (SEMVER-MINOR) fs: add `read(buffer[, options])` versions (LiviaMedeiros) https://github.com/nodejs/node/pull/42768 (SEMVER-MINOR) http: add drop request event for http server (theanarkh) https://github.com/nodejs/node/pull/43806 (SEMVER-MINOR) http: add diagnostics channel for http client (theanarkh) https://github.com/nodejs/node/pull/43580 (SEMVER-MINOR) http: add perf_hooks detail for http request and client (theanarkh) https://github.com/nodejs/node/pull/43361 (SEMVER-MINOR) http: add uniqueHeaders option to request and createServer (Paolo Insogna) https://github.com/nodejs/node/pull/41397 (SEMVER-MINOR) http2: propagate abortsignal reason in new AbortError constructor (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) http2: compat support for array headers (OneNail) https://github.com/nodejs/node/pull/42901 (SEMVER-MINOR) lib: propagate abortsignal reason in new AbortError constructor in blob (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) lib: add abortSignal.throwIfAborted() (James M Snell) https://github.com/nodejs/node/pull/40951 (SEMVER-MINOR) lib: improved diagnostics_channel subscribe/unsubscribe (Stephen Belanger) https://github.com/nodejs/node/pull/42714 (SEMVER-MINOR) module: add isBuiltIn method (hemanth.hm) https://github.com/nodejs/node/pull/43396 (SEMVER-MINOR) module,repl: support 'node:'-only core modules (Colin Ihrig) https://github.com/nodejs/node/pull/42325 (SEMVER-MINOR) net: add drop event for net server (theanarkh) https://github.com/nodejs/node/pull/43582 (SEMVER-MINOR) net: add ability to reset a tcp socket (pupilTong) https://github.com/nodejs/node/pull/43112 (SEMVER-MINOR) node-api: emit uncaught-exception on unhandled tsfn callbacks (Chengzhong Wu) https://github.com/nodejs/node/pull/36510 (SEMVER-MINOR) perf_hooks: add PerformanceResourceTiming (RafaelGSS) https://github.com/nodejs/node/pull/42725 (SEMVER-MINOR) report: add more heap infos in process report (theanarkh) https://github.com/nodejs/node/pull/43116 (SEMVER-MINOR) src: add --openssl-legacy-provider option (Daniel Bevenius) https://github.com/nodejs/node/pull/40478 (SEMVER-MINOR) src: define fs.constants.S_IWUSR & S_IRUSR for Win (Liviu Ionescu) https://github.com/nodejs/node/pull/42757 (SEMVER-MINOR) src,doc,test: add --openssl-shared-config option (Daniel Bevenius) https://github.com/nodejs/node/pull/43124 (SEMVER-MINOR) stream: use cause options in AbortError constructors (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) stream: add iterator helper find (Nitzan Uziely) https://github.com/nodejs/node/pull/41849 (SEMVER-MINOR) stream: add writableAborted (Robert Nagy) https://github.com/nodejs/node/pull/40802 (SEMVER-MINOR) timers: propagate signal.reason in awaitable timers (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) v8: add v8.startupSnapshot utils (Joyee Cheung) https://github.com/nodejs/node/pull/43329 (SEMVER-MINOR) v8: export more fields in getHeapStatistics (theanarkh) https://github.com/nodejs/node/pull/42784 (SEMVER-MINOR) worker: add hasRef() to MessagePort (Darshan Sen) https://github.com/nodejs/node/pull/42849 PR-URL: https://github.com/nodejs/node/pull/44098
2022-08-02 14:34:18 +02:00
- version:
- v18.7.0
- v16.17.0
pr-url: https://github.com/nodejs/node/pull/43505
description: Add a `timeout` option.
-->
* `name` {string} The name of the subtest, which is displayed when reporting
test results. **Default:** The `name` property of `fn`, or `'<anonymous>'` if
`fn` does not have a name.
* `options` {Object} Configuration options for the subtest. The following
properties are supported:
* `concurrency` {number|boolean|null} If a number is provided,
then that many tests would run in parallel within the application thread.
If `true`, it would run all subtests in parallel.
If `false`, it would only run one test at a time.
If unspecified, subtests inherit this value from their parent.
**Default:** `null`.
* `only` {boolean} If truthy, and the test context is configured to run
`only` tests, then this test will be run. Otherwise, the test is skipped.
**Default:** `false`.
* `signal` {AbortSignal} Allows aborting an in-progress test.
* `skip` {boolean|string} If truthy, the test is skipped. If a string is
provided, that string is displayed in the test results as the reason for
skipping the test. **Default:** `false`.
* `todo` {boolean|string} If truthy, the test marked as `TODO`. If a string
is provided, that string is displayed in the test results as the reason why
the test is `TODO`. **Default:** `false`.
* `timeout` {number} A number of milliseconds the test will fail after.
If unspecified, subtests inherit this value from their parent.
**Default:** `Infinity`.
* `plan` {number} The number of assertions and subtests expected to be run in the test.
If the number of assertions run in the test does not match the number
specified in the plan, the test will fail.
**Default:** `undefined`.
* `fn` {Function|AsyncFunction} The function under test. The first argument
to this function is a [`TestContext`][] object. If the test uses callbacks,
the callback function is passed as the second argument. **Default:** A no-op
function.
This function is used to create subtests under the current test. This function
behaves in the same fashion as the top level [`test()`][] function.
```js
test('top level test', async (t) => {
t.test(
'This is a subtest',
{ only: false, skip: false, concurrency: 1, todo: false, plan: 1 },
(t) => {
t.assert.ok('some relevant assertion here');
},
);
});
```
### `context.waitFor(condition[, options])`
<!-- YAML
2025-02-11, Version 22.14.0 'Jod' (LTS) Notable changes: crypto: * update root certificates to NSS 3.107 (Node.js GitHub Bot) https://github.com/nodejs/node/pull/56566 fs: * (SEMVER-MINOR) allow `exclude` option in globs to accept glob patterns (Daeyeon Jeong) https://github.com/nodejs/node/pull/56489 lib: * (SEMVER-MINOR) add typescript support to STDIN eval (Marco Ippolito) https://github.com/nodejs/node/pull/56359 module: * (SEMVER-MINOR) add ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX (Marco Ippolito) https://github.com/nodejs/node/pull/56610 * (SEMVER-MINOR) add `findPackageJSON` util (Jacob Smith) https://github.com/nodejs/node/pull/55412 process: * (SEMVER-MINOR) add process.ref() and process.unref() methods (James M Snell) https://github.com/nodejs/node/pull/56400 sqlite: * (SEMVER-MINOR) support TypedArray and DataView in `StatementSync` (Alex Yang) https://github.com/nodejs/node/pull/56385 src: * (SEMVER-MINOR) add --disable-sigusr1 to prevent signal i/o thread (Rafael Gonzaga) https://github.com/nodejs/node/pull/56441 src,worker: * (SEMVER-MINOR) add isInternalWorker (Carlos Espa) https://github.com/nodejs/node/pull/56469 test_runner: * (SEMVER-MINOR) add TestContext.prototype.waitFor() (Colin Ihrig) https://github.com/nodejs/node/pull/56595 * (SEMVER-MINOR) add t.assert.fileSnapshot() (Colin Ihrig) https://github.com/nodejs/node/pull/56459 * (SEMVER-MINOR) add assert.register() API (Colin Ihrig) https://github.com/nodejs/node/pull/56434 worker: * (SEMVER-MINOR) add eval ts input (Marco Ippolito) https://github.com/nodejs/node/pull/56394 PR-URL: https://github.com/nodejs/node/pull/56910
2025-02-06 11:04:25 +01:00
added:
- v23.7.0
- v22.14.0
-->
* `condition` {Function|AsyncFunction} An assertion function that is invoked
periodically until it completes successfully or the defined polling timeout
elapses. Successful completion is defined as not throwing or rejecting. This
function does not accept any arguments, and is allowed to return any value.
* `options` {Object} An optional configuration object for the polling operation.
The following properties are supported:
* `interval` {number} The number of milliseconds to wait after an unsuccessful
invocation of `condition` before trying again. **Default:** `50`.
* `timeout` {number} The poll timeout in milliseconds. If `condition` has not
succeeded by the time this elapses, an error occurs. **Default:** `1000`.
* Returns: {Promise} Fulfilled with the value returned by `condition`.
This method polls a `condition` function until that function either returns
successfully or the operation times out.
## Class: `SuiteContext`
<!-- YAML
2022-08-16, Version 16.17.0 'Gallium' (LTS) Notable changes: Adds `util.parseArgs` helper for higher level command-line argument parsing. Contributed by Benjamin Coe, John Gee, Darcy Clarke, Joe Sepi, Kevin Gibbons, Aaron Casanova, Jessica Nahulan, and Jordan Harband. https://github.com/nodejs/node/pull/42675 Node.js ESM Loader hooks now support multiple custom loaders, and composition is achieved via "chaining": `foo-loader` calls `bar-loader` calls `qux-loader` (a custom loader _must_ now signal a short circuit when intentionally not calling the next). See the ESM docs (https://nodejs.org/dist/latest-v16.x/docs/api/esm.html) for details. Contributed by Jacob Smith, Geoffrey Booth, and Bradley Farias. https://github.com/nodejs/node/pull/42623 The `node:test` module, which was initially introduced in Node.js v18.0.0, is now available with all the changes done to it up to Node.js v18.7.0. To better align Node.js' experimental implementation of the Web Crypto API with other runtimes, several changes were made: * Support for CFRG curves was added, with the `'Ed25519'`, `'Ed448'`, `'X25519'`, and `'X448'` algorithms. * The proprietary `'NODE-DSA'`, `'NODE-DH'`, `'NODE-SCRYPT'`, `'NODE-ED25519'`, `'NODE-ED448'`, `'NODE-X25519'`, and `'NODE-X448'` algorithms were removed. * The proprietary `'node.keyObject'` import/export format was removed. Contributed by Filip Skokan. https://github.com/nodejs/node/pull/42507 https://github.com/nodejs/node/pull/43310 Updated Corepack to 0.12.1 - https://github.com/nodejs/node/pull/43965 Updated ICU to 71.1 - https://github.com/nodejs/node/pull/42655 Updated npm to 8.15.0 - https://github.com/nodejs/node/pull/43917 Updated Undici to 5.8.0 - https://github.com/nodejs/node/pull/43886 (SEMVER-MINOR) crypto: make authTagLength optional for CC20P1305 (Tobias Nießen) https://github.com/nodejs/node/pull/42427 (SEMVER-MINOR) crypto: align webcrypto RSA key import/export with other implementations (Filip Skokan) https://github.com/nodejs/node/pull/42816 (SEMVER-MINOR) dns: export error code constants from `dns/promises` (Feng Yu) https://github.com/nodejs/node/pull/43176 doc: deprecate coercion to integer in process.exit (Daeyeon Jeong) https://github.com/nodejs/node/pull/43738 (SEMVER-MINOR) doc: deprecate diagnostics_channel object subscribe method (Stephen Belanger) https://github.com/nodejs/node/pull/42714 (SEMVER-MINOR) errors: add support for cause in aborterror (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) events: expose CustomEvent on global with CLI flag (Daeyeon Jeong) https://github.com/nodejs/node/pull/43885 (SEMVER-MINOR) events: add `CustomEvent` (Daeyeon Jeong) https://github.com/nodejs/node/pull/43514 (SEMVER-MINOR) events: propagate abortsignal reason in new AbortError ctor in events (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) fs: propagate abortsignal reason in new AbortSignal constructors (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) fs: make params in writing methods optional (LiviaMedeiros) https://github.com/nodejs/node/pull/42601 (SEMVER-MINOR) fs: add `read(buffer[, options])` versions (LiviaMedeiros) https://github.com/nodejs/node/pull/42768 (SEMVER-MINOR) http: add drop request event for http server (theanarkh) https://github.com/nodejs/node/pull/43806 (SEMVER-MINOR) http: add diagnostics channel for http client (theanarkh) https://github.com/nodejs/node/pull/43580 (SEMVER-MINOR) http: add perf_hooks detail for http request and client (theanarkh) https://github.com/nodejs/node/pull/43361 (SEMVER-MINOR) http: add uniqueHeaders option to request and createServer (Paolo Insogna) https://github.com/nodejs/node/pull/41397 (SEMVER-MINOR) http2: propagate abortsignal reason in new AbortError constructor (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) http2: compat support for array headers (OneNail) https://github.com/nodejs/node/pull/42901 (SEMVER-MINOR) lib: propagate abortsignal reason in new AbortError constructor in blob (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) lib: add abortSignal.throwIfAborted() (James M Snell) https://github.com/nodejs/node/pull/40951 (SEMVER-MINOR) lib: improved diagnostics_channel subscribe/unsubscribe (Stephen Belanger) https://github.com/nodejs/node/pull/42714 (SEMVER-MINOR) module: add isBuiltIn method (hemanth.hm) https://github.com/nodejs/node/pull/43396 (SEMVER-MINOR) module,repl: support 'node:'-only core modules (Colin Ihrig) https://github.com/nodejs/node/pull/42325 (SEMVER-MINOR) net: add drop event for net server (theanarkh) https://github.com/nodejs/node/pull/43582 (SEMVER-MINOR) net: add ability to reset a tcp socket (pupilTong) https://github.com/nodejs/node/pull/43112 (SEMVER-MINOR) node-api: emit uncaught-exception on unhandled tsfn callbacks (Chengzhong Wu) https://github.com/nodejs/node/pull/36510 (SEMVER-MINOR) perf_hooks: add PerformanceResourceTiming (RafaelGSS) https://github.com/nodejs/node/pull/42725 (SEMVER-MINOR) report: add more heap infos in process report (theanarkh) https://github.com/nodejs/node/pull/43116 (SEMVER-MINOR) src: add --openssl-legacy-provider option (Daniel Bevenius) https://github.com/nodejs/node/pull/40478 (SEMVER-MINOR) src: define fs.constants.S_IWUSR & S_IRUSR for Win (Liviu Ionescu) https://github.com/nodejs/node/pull/42757 (SEMVER-MINOR) src,doc,test: add --openssl-shared-config option (Daniel Bevenius) https://github.com/nodejs/node/pull/43124 (SEMVER-MINOR) stream: use cause options in AbortError constructors (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) stream: add iterator helper find (Nitzan Uziely) https://github.com/nodejs/node/pull/41849 (SEMVER-MINOR) stream: add writableAborted (Robert Nagy) https://github.com/nodejs/node/pull/40802 (SEMVER-MINOR) timers: propagate signal.reason in awaitable timers (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) v8: add v8.startupSnapshot utils (Joyee Cheung) https://github.com/nodejs/node/pull/43329 (SEMVER-MINOR) v8: export more fields in getHeapStatistics (theanarkh) https://github.com/nodejs/node/pull/42784 (SEMVER-MINOR) worker: add hasRef() to MessagePort (Darshan Sen) https://github.com/nodejs/node/pull/42849 PR-URL: https://github.com/nodejs/node/pull/44098
2022-08-02 14:34:18 +02:00
added:
- v18.7.0
- v16.17.0
-->
An instance of `SuiteContext` is passed to each suite function in order to
interact with the test runner. However, the `SuiteContext` constructor is not
exposed as part of the API.
### `context.filePath`
<!-- YAML
added: v22.6.0
-->
The absolute path of the test file that created the current suite. If a test
file imports additional modules that generate suites, the imported suites will
return the path of the root test file.
### `context.name`
<!-- YAML
2022-10-12, Version 16.18.0 'Gallium' (LTS) Notable changes: assert: add `getCalls` and `reset` to callTracker (Moshe Atlow) https://github.com/nodejs/node/pull/44191 crypto: allow zero-length secret KeyObject (Filip Skokan) https://github.com/nodejs/node/pull/44201 crypto: allow zero-length IKM in HKDF and in webcrypto PBKDF2 (Filip Skokan) https://github.com/nodejs/node/pull/44201 doc: deprecate modp1, modp2, and modp5 groups (Tobias Nießen) https://github.com/nodejs/node/pull/44588 http: make idle http parser count configurable (theanarkh) https://github.com/nodejs/node/pull/43974 http: throw error on content-length mismatch (sidwebworks) https://github.com/nodejs/node/pull/44378 lib: add diagnostics channel for process and worker (theanarkh) https://github.com/nodejs/node/pull/44045 net,tls: pass a valid socket on `tlsClientError` (Daeyeon Jeong) https://github.com/nodejs/node/pull/44021 net: add local family (theanarkh) https://github.com/nodejs/node/pull/43975 report: expose report public native apis (Chengzhong Wu) https://github.com/nodejs/node/pull/44255 src: expose environment RequestInterrupt api (Chengzhong Wu) https://github.com/nodejs/node/pull/44362 stream: add `ReadableByteStream.tee()` (Daeyeon Jeong) https://github.com/nodejs/node/pull/44505 test_runner: add before/after/each hooks (Moshe Atlow) https://github.com/nodejs/node/pull/43730 util: add `maxArrayLength` option to Set and Map (Kohei Ueno) https://github.com/nodejs/node/pull/43576 PR-URL: https://github.com/nodejs/node/pull/44886
2022-10-11 14:54:19 -05:00
added:
- v18.8.0
- v16.18.0
-->
The name of the suite.
### `context.signal`
<!-- YAML
2022-08-16, Version 16.17.0 'Gallium' (LTS) Notable changes: Adds `util.parseArgs` helper for higher level command-line argument parsing. Contributed by Benjamin Coe, John Gee, Darcy Clarke, Joe Sepi, Kevin Gibbons, Aaron Casanova, Jessica Nahulan, and Jordan Harband. https://github.com/nodejs/node/pull/42675 Node.js ESM Loader hooks now support multiple custom loaders, and composition is achieved via "chaining": `foo-loader` calls `bar-loader` calls `qux-loader` (a custom loader _must_ now signal a short circuit when intentionally not calling the next). See the ESM docs (https://nodejs.org/dist/latest-v16.x/docs/api/esm.html) for details. Contributed by Jacob Smith, Geoffrey Booth, and Bradley Farias. https://github.com/nodejs/node/pull/42623 The `node:test` module, which was initially introduced in Node.js v18.0.0, is now available with all the changes done to it up to Node.js v18.7.0. To better align Node.js' experimental implementation of the Web Crypto API with other runtimes, several changes were made: * Support for CFRG curves was added, with the `'Ed25519'`, `'Ed448'`, `'X25519'`, and `'X448'` algorithms. * The proprietary `'NODE-DSA'`, `'NODE-DH'`, `'NODE-SCRYPT'`, `'NODE-ED25519'`, `'NODE-ED448'`, `'NODE-X25519'`, and `'NODE-X448'` algorithms were removed. * The proprietary `'node.keyObject'` import/export format was removed. Contributed by Filip Skokan. https://github.com/nodejs/node/pull/42507 https://github.com/nodejs/node/pull/43310 Updated Corepack to 0.12.1 - https://github.com/nodejs/node/pull/43965 Updated ICU to 71.1 - https://github.com/nodejs/node/pull/42655 Updated npm to 8.15.0 - https://github.com/nodejs/node/pull/43917 Updated Undici to 5.8.0 - https://github.com/nodejs/node/pull/43886 (SEMVER-MINOR) crypto: make authTagLength optional for CC20P1305 (Tobias Nießen) https://github.com/nodejs/node/pull/42427 (SEMVER-MINOR) crypto: align webcrypto RSA key import/export with other implementations (Filip Skokan) https://github.com/nodejs/node/pull/42816 (SEMVER-MINOR) dns: export error code constants from `dns/promises` (Feng Yu) https://github.com/nodejs/node/pull/43176 doc: deprecate coercion to integer in process.exit (Daeyeon Jeong) https://github.com/nodejs/node/pull/43738 (SEMVER-MINOR) doc: deprecate diagnostics_channel object subscribe method (Stephen Belanger) https://github.com/nodejs/node/pull/42714 (SEMVER-MINOR) errors: add support for cause in aborterror (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) events: expose CustomEvent on global with CLI flag (Daeyeon Jeong) https://github.com/nodejs/node/pull/43885 (SEMVER-MINOR) events: add `CustomEvent` (Daeyeon Jeong) https://github.com/nodejs/node/pull/43514 (SEMVER-MINOR) events: propagate abortsignal reason in new AbortError ctor in events (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) fs: propagate abortsignal reason in new AbortSignal constructors (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) fs: make params in writing methods optional (LiviaMedeiros) https://github.com/nodejs/node/pull/42601 (SEMVER-MINOR) fs: add `read(buffer[, options])` versions (LiviaMedeiros) https://github.com/nodejs/node/pull/42768 (SEMVER-MINOR) http: add drop request event for http server (theanarkh) https://github.com/nodejs/node/pull/43806 (SEMVER-MINOR) http: add diagnostics channel for http client (theanarkh) https://github.com/nodejs/node/pull/43580 (SEMVER-MINOR) http: add perf_hooks detail for http request and client (theanarkh) https://github.com/nodejs/node/pull/43361 (SEMVER-MINOR) http: add uniqueHeaders option to request and createServer (Paolo Insogna) https://github.com/nodejs/node/pull/41397 (SEMVER-MINOR) http2: propagate abortsignal reason in new AbortError constructor (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) http2: compat support for array headers (OneNail) https://github.com/nodejs/node/pull/42901 (SEMVER-MINOR) lib: propagate abortsignal reason in new AbortError constructor in blob (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) lib: add abortSignal.throwIfAborted() (James M Snell) https://github.com/nodejs/node/pull/40951 (SEMVER-MINOR) lib: improved diagnostics_channel subscribe/unsubscribe (Stephen Belanger) https://github.com/nodejs/node/pull/42714 (SEMVER-MINOR) module: add isBuiltIn method (hemanth.hm) https://github.com/nodejs/node/pull/43396 (SEMVER-MINOR) module,repl: support 'node:'-only core modules (Colin Ihrig) https://github.com/nodejs/node/pull/42325 (SEMVER-MINOR) net: add drop event for net server (theanarkh) https://github.com/nodejs/node/pull/43582 (SEMVER-MINOR) net: add ability to reset a tcp socket (pupilTong) https://github.com/nodejs/node/pull/43112 (SEMVER-MINOR) node-api: emit uncaught-exception on unhandled tsfn callbacks (Chengzhong Wu) https://github.com/nodejs/node/pull/36510 (SEMVER-MINOR) perf_hooks: add PerformanceResourceTiming (RafaelGSS) https://github.com/nodejs/node/pull/42725 (SEMVER-MINOR) report: add more heap infos in process report (theanarkh) https://github.com/nodejs/node/pull/43116 (SEMVER-MINOR) src: add --openssl-legacy-provider option (Daniel Bevenius) https://github.com/nodejs/node/pull/40478 (SEMVER-MINOR) src: define fs.constants.S_IWUSR & S_IRUSR for Win (Liviu Ionescu) https://github.com/nodejs/node/pull/42757 (SEMVER-MINOR) src,doc,test: add --openssl-shared-config option (Daniel Bevenius) https://github.com/nodejs/node/pull/43124 (SEMVER-MINOR) stream: use cause options in AbortError constructors (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) stream: add iterator helper find (Nitzan Uziely) https://github.com/nodejs/node/pull/41849 (SEMVER-MINOR) stream: add writableAborted (Robert Nagy) https://github.com/nodejs/node/pull/40802 (SEMVER-MINOR) timers: propagate signal.reason in awaitable timers (James M Snell) https://github.com/nodejs/node/pull/41008 (SEMVER-MINOR) v8: add v8.startupSnapshot utils (Joyee Cheung) https://github.com/nodejs/node/pull/43329 (SEMVER-MINOR) v8: export more fields in getHeapStatistics (theanarkh) https://github.com/nodejs/node/pull/42784 (SEMVER-MINOR) worker: add hasRef() to MessagePort (Darshan Sen) https://github.com/nodejs/node/pull/42849 PR-URL: https://github.com/nodejs/node/pull/44098
2022-08-02 14:34:18 +02:00
added:
- v18.7.0
- v16.17.0
-->
* Type: {AbortSignal}
Can be used to abort test subtasks when the test has been aborted.
[TAP]: https://testanything.org/
[`--experimental-test-coverage`]: cli.md#--experimental-test-coverage
[`--experimental-test-module-mocks`]: cli.md#--experimental-test-module-mocks
[`--import`]: cli.md#--importmodule
[`--no-experimental-strip-types`]: cli.md#--no-experimental-strip-types
[`--test-concurrency`]: cli.md#--test-concurrency
[`--test-coverage-exclude`]: cli.md#--test-coverage-exclude
[`--test-coverage-include`]: cli.md#--test-coverage-include
[`--test-name-pattern`]: cli.md#--test-name-pattern
[`--test-only`]: cli.md#--test-only
[`--test-reporter-destination`]: cli.md#--test-reporter-destination
[`--test-reporter`]: cli.md#--test-reporter
[`--test-skip-pattern`]: cli.md#--test-skip-pattern
[`--test-update-snapshots`]: cli.md#--test-update-snapshots
[`--test`]: cli.md#--test
[`MockFunctionContext`]: #class-mockfunctioncontext
[`MockTimers`]: #class-mocktimers
[`MockTracker.method`]: #mockmethodobject-methodname-implementation-options
[`MockTracker`]: #class-mocktracker
[`NODE_V8_COVERAGE`]: cli.md#node_v8_coveragedir
[`SuiteContext`]: #class-suitecontext
[`TestContext`]: #class-testcontext
[`context.diagnostic`]: #contextdiagnosticmessage
[`context.skip`]: #contextskipmessage
[`context.todo`]: #contexttodomessage
[`describe()`]: #describename-options-fn
[`glob(7)`]: https://man7.org/linux/man-pages/man7/glob.7.html
[`it()`]: #itname-options-fn
[`run()`]: #runoptions
[`suite()`]: #suitename-options-fn
[`test()`]: #testname-options-fn
[code coverage]: #collecting-code-coverage
[describe options]: #describename-options-fn
[it options]: #testname-options-fn
[stream.compose]: stream.md#streamcomposestreams
[subtests]: #subtests
[suite options]: #suitename-options-fn
[test reporters]: #test-reporters
[test runner execution model]: #test-runner-execution-model