2022-02-09 00:23:36 -05:00
|
|
|
# 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-->
|
2022-02-09 00:23:36 -05:00
|
|
|
|
2023-02-28 17:37:27 +01:00
|
|
|
<!-- YAML
|
|
|
|
added:
|
|
|
|
- v18.0.0
|
|
|
|
- v16.17.0
|
2023-03-06 17:18:14 -05:00
|
|
|
changes:
|
2023-04-03 11:30:30 +01:00
|
|
|
- version: v20.0.0
|
2023-03-06 17:18:14 -05:00
|
|
|
pr-url: https://github.com/nodejs/node/pull/46983
|
|
|
|
description: The test runner is now stable.
|
2023-02-28 17:37:27 +01:00
|
|
|
-->
|
|
|
|
|
2023-03-06 17:18:14 -05:00
|
|
|
> Stability: 2 - Stable
|
2022-02-09 00:23:36 -05:00
|
|
|
|
|
|
|
<!-- source_link=lib/test.js -->
|
|
|
|
|
2022-12-19 19:35:57 +02:00
|
|
|
The `node:test` module facilitates the creation of JavaScript tests.
|
|
|
|
To access it:
|
2022-02-09 00:23:36 -05:00
|
|
|
|
|
|
|
```mjs
|
|
|
|
import test from 'node:test';
|
|
|
|
```
|
|
|
|
|
|
|
|
```cjs
|
|
|
|
const test = require('node:test');
|
|
|
|
```
|
|
|
|
|
|
|
|
This module is only available under the `node:` scheme. The following will not
|
|
|
|
work:
|
|
|
|
|
|
|
|
```mjs
|
|
|
|
import test from 'test';
|
|
|
|
```
|
|
|
|
|
|
|
|
```cjs
|
|
|
|
const test = require('test');
|
|
|
|
```
|
|
|
|
|
|
|
|
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` resolves.
|
|
|
|
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 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'));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2022-12-19 19:35:57 +02:00
|
|
|
If any tests fail, the process exit code is set to `1`.
|
2022-02-09 00:23:36 -05:00
|
|
|
|
|
|
|
## Subtests
|
|
|
|
|
|
|
|
The test context's `test()` method allows subtests to be created. 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) => {
|
|
|
|
await t.test('subtest 1', (t) => {
|
|
|
|
assert.strictEqual(1, 1);
|
|
|
|
});
|
|
|
|
|
|
|
|
await t.test('subtest 2', (t) => {
|
|
|
|
assert.strictEqual(2, 2);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
In this example, `await` is used to ensure that both subtests have completed.
|
|
|
|
This is necessary because parent tests do not wait for their subtests to
|
|
|
|
complete. Any subtests that are still outstanding when their parent finishes
|
|
|
|
are cancelled and treated as failures. 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
|
2022-12-19 19:35:57 +02:00
|
|
|
calling the test context's `skip()` method as shown in the
|
2022-02-09 00:23:36 -05:00
|
|
|
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');
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2022-06-14 10:54:50 +03:00
|
|
|
## `describe`/`it` syntax
|
|
|
|
|
|
|
|
Running tests can also be done using `describe` to declare a suite
|
|
|
|
and `it` to declare a test.
|
|
|
|
A suite is used to organize and group related tests together.
|
2023-02-28 21:58:49 +02:00
|
|
|
`it` is a shorthand for [`test()`][].
|
2022-06-14 10:54:50 +03:00
|
|
|
|
|
|
|
```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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2022-07-31 14:58:18 +02:00
|
|
|
`describe` and `it` are imported from the `node:test` module.
|
2022-06-14 10:54:50 +03:00
|
|
|
|
|
|
|
```mjs
|
|
|
|
import { describe, it } from 'node:test';
|
|
|
|
```
|
|
|
|
|
|
|
|
```cjs
|
|
|
|
const { describe, it } = require('node:test');
|
|
|
|
```
|
|
|
|
|
2022-11-07 13:52:11 -05:00
|
|
|
## `only` tests
|
2022-04-04 10:14:49 -04:00
|
|
|
|
|
|
|
If Node.js is started with the [`--test-only`][] command-line option, it is
|
|
|
|
possible to skip all top level tests except for a selected subset by passing
|
|
|
|
the `only` option to the tests that should be run. When a test with the `only`
|
|
|
|
option set is run, all subtests are also run. The test context's `runOnly()`
|
|
|
|
method can be used to implement the same behavior at the subtest level.
|
|
|
|
|
|
|
|
```js
|
|
|
|
// Assume Node.js is run with the --test-only command-line option.
|
|
|
|
// The 'only' option is set, so this test is run.
|
|
|
|
test('this test is run', { only: true }, async (t) => {
|
|
|
|
// Within this test, all subtests are run by default.
|
|
|
|
await t.test('running subtest');
|
|
|
|
|
|
|
|
// The test context can be updated to run subtests with the 'only' option.
|
|
|
|
t.runOnly(true);
|
|
|
|
await t.test('this subtest is now skipped');
|
|
|
|
await t.test('this subtest is run', { only: true });
|
|
|
|
|
|
|
|
// Switch the context back to execute all tests.
|
|
|
|
t.runOnly(false);
|
|
|
|
await t.test('this subtest is now run');
|
|
|
|
|
|
|
|
// Explicitly do not run these tests.
|
|
|
|
await t.test('skipped subtest 3', { only: false });
|
|
|
|
await 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');
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2022-08-31 21:33:39 -04:00
|
|
|
## Filtering tests by name
|
|
|
|
|
|
|
|
The [`--test-name-pattern`][] command-line option can be used to only run tests
|
|
|
|
whose name matches the provided pattern. Test name patterns are interpreted as
|
|
|
|
JavaScript regular expressions. The `--test-name-pattern` option 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.
|
|
|
|
|
|
|
|
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) => {
|
|
|
|
await t.test('test 2');
|
|
|
|
await t.test('test 3');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Test 4', async (t) => {
|
|
|
|
await t.test('Test 5');
|
|
|
|
await 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"` would match `Test 4` and
|
|
|
|
`Test 5` because the pattern is case-insensitive.
|
|
|
|
|
|
|
|
Test name patterns do not change the set of files that the test runner executes.
|
|
|
|
|
2022-02-09 00:23:36 -05:00
|
|
|
## Extraneous asynchronous activity
|
|
|
|
|
2022-12-19 19:35:57 +02:00
|
|
|
Once a test function finishes executing, the results are reported as quickly
|
2022-02-09 00:23:36 -05:00
|
|
|
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
|
2022-12-19 19:35:57 +02:00
|
|
|
results, the new subtest is immediately marked as failed, and reported later
|
|
|
|
to the {TestsStream}.
|
2022-02-09 00:23:36 -05:00
|
|
|
|
|
|
|
The second `setImmediate()` creates an `uncaughtException` event.
|
|
|
|
`uncaughtException` and `unhandledRejection` events originating from a completed
|
2022-11-07 21:02:56 +09:00
|
|
|
test are marked as failed by the `test` module and reported as diagnostic
|
2022-12-19 19:35:57 +02:00
|
|
|
warnings at the top level by the {TestsStream}.
|
2022-02-09 00:23:36 -05:00
|
|
|
|
|
|
|
```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.
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2022-11-13 23:40:26 +02:00
|
|
|
## 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
|
2022-11-13 23:40:26 +02:00
|
|
|
-->
|
|
|
|
|
|
|
|
> 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.
|
|
|
|
|
2022-04-15 13:37:28 -04:00
|
|
|
## 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
|
|
|
|
```
|
|
|
|
|
2023-06-22 15:18:23 +03:00
|
|
|
By default Node.js will run all files matching these patterns:
|
2022-04-15 13:37:28 -04:00
|
|
|
|
2023-06-22 15:18:23 +03:00
|
|
|
* `**/*.test.?(c|m)js`
|
|
|
|
* `**/*-test.?(c|m)js`
|
|
|
|
* `**/*_test.?(c|m)js`
|
|
|
|
* `**/test-*.?(c|m)js`
|
|
|
|
* `**/test.?(c|m)js`
|
|
|
|
* `**/test/**/*.?(c|m)js`
|
|
|
|
|
|
|
|
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)`][].
|
2022-04-15 13:37:28 -04:00
|
|
|
|
|
|
|
```bash
|
2023-06-22 15:18:23 +03:00
|
|
|
node --test **/*.test.js **/*.spec.js
|
2022-04-15 13:37:28 -04:00
|
|
|
```
|
|
|
|
|
2023-06-22 15:18:23 +03:00
|
|
|
Matching files are executed as test files.
|
|
|
|
More information on the test file execution can be found
|
|
|
|
in the [test runner execution model][] section.
|
2022-04-15 13:37:28 -04:00
|
|
|
|
|
|
|
### Test runner execution model
|
|
|
|
|
|
|
|
Each matching test file is executed in a separate child process. 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.
|
|
|
|
|
2023-04-24 17:38:12 +02:00
|
|
|
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()`][].
|
|
|
|
|
2022-12-21 13:26:16 -05:00
|
|
|
## Collecting code coverage
|
|
|
|
|
2023-03-06 17:18:14 -05:00
|
|
|
> Stability: 1 - Experimental
|
|
|
|
|
2023-01-07 21:16:54 -05:00
|
|
|
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 not included in the coverage report. If
|
|
|
|
coverage is enabled, the coverage report is sent to any [test reporters][] via
|
|
|
|
the `'test:coverage'` event.
|
2022-12-21 13:26:16 -05:00
|
|
|
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
The test runner's code coverage functionality has the following limitations,
|
|
|
|
which will be addressed in a future Node.js release:
|
|
|
|
|
|
|
|
* Source maps are not supported.
|
|
|
|
* Excluding specific files or directories from the coverage report is not
|
|
|
|
supported.
|
|
|
|
|
2022-04-04 18:36:40 -04:00
|
|
|
## 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.calls.length, 0);
|
|
|
|
assert.strictEqual(sum(3, 4), 7);
|
|
|
|
assert.strictEqual(sum.mock.calls.length, 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.calls.length, 0);
|
|
|
|
assert.strictEqual(sum(3, 4), 7);
|
|
|
|
assert.strictEqual(sum.mock.calls.length, 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.calls.length, 0);
|
|
|
|
assert.strictEqual(number.add(3), 8);
|
|
|
|
assert.strictEqual(number.add.mock.calls.length, 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);
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2023-06-22 01:01:52 -03:00
|
|
|
### 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(['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(['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();
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
```js
|
|
|
|
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(['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'll 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(['setTimeout']);
|
|
|
|
setTimeout(fn, 9999);
|
|
|
|
assert.strictEqual(fn.mock.callCount(), 0);
|
|
|
|
|
|
|
|
// Advance in time
|
|
|
|
context.mock.timers.tick(9999);
|
|
|
|
assert.strictEqual(fn.mock.callCount(), 1);
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
```js
|
|
|
|
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(['setTimeout']);
|
|
|
|
setTimeout(fn, 9999);
|
|
|
|
assert.strictEqual(fn.mock.callCount(), 0);
|
|
|
|
|
|
|
|
// Advance in time
|
|
|
|
context.mock.timers.tick(9999);
|
|
|
|
assert.strictEqual(fn.mock.callCount(), 1);
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2022-12-19 19:35:57 +02:00
|
|
|
## Test reporters
|
|
|
|
|
|
|
|
<!-- YAML
|
2023-03-04 23:12:52 -05:00
|
|
|
added:
|
|
|
|
- v19.6.0
|
|
|
|
- v18.15.0
|
2023-03-28 15:10:34 +03:00
|
|
|
changes:
|
2023-07-10 08:12:52 -04:00
|
|
|
- version:
|
|
|
|
- v19.9.0
|
|
|
|
- v18.17.0
|
2023-03-28 15:10:34 +03:00
|
|
|
pr-url: https://github.com/nodejs/node/pull/47238
|
|
|
|
description: Reporters are now exposed at `node:test/reporters`.
|
2022-12-19 19:35:57 +02:00
|
|
|
-->
|
|
|
|
|
|
|
|
The `node:test` module supports passing [`--test-reporter`][]
|
|
|
|
flags for the test runner to use a specific reporter.
|
|
|
|
|
|
|
|
The following built-reporters are supported:
|
|
|
|
|
|
|
|
* `tap`
|
2023-03-06 12:20:51 +02:00
|
|
|
The `tap` reporter outputs the test results in the [TAP][] format.
|
2022-12-19 19:35:57 +02:00
|
|
|
|
|
|
|
* `spec`
|
|
|
|
The `spec` reporter outputs the test results in a human-readable format.
|
|
|
|
|
|
|
|
* `dot`
|
2022-12-22 13:40:32 -08:00
|
|
|
The `dot` reporter outputs the test results in a compact format,
|
2022-12-19 19:35:57 +02:00
|
|
|
where each passing test is represented by a `.`,
|
|
|
|
and each failing test is represented by a `X`.
|
|
|
|
|
2023-03-06 12:20:51 +02:00
|
|
|
When `stdout` is a [TTY][], the `spec` reporter is used by default.
|
|
|
|
Otherwise, the `tap` reporter is used by default.
|
|
|
|
|
2023-03-06 17:18:14 -05:00
|
|
|
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}.
|
|
|
|
|
2023-03-28 15:10:34 +03:00
|
|
|
The reporters are available via the `node:test/reporters` module:
|
|
|
|
|
|
|
|
```mjs
|
|
|
|
import { tap, spec, dot } from 'node:test/reporters';
|
|
|
|
```
|
|
|
|
|
|
|
|
```cjs
|
|
|
|
const { tap, spec, dot } = require('node:test/reporters');
|
|
|
|
```
|
|
|
|
|
2022-12-19 19:35:57 +02:00
|
|
|
### Custom reporters
|
|
|
|
|
|
|
|
[`--test-reporter`][] can be used to specify a path to custom reporter.
|
2023-03-13 13:01:15 +01:00
|
|
|
A custom reporter is a module that exports a value
|
2022-12-19 19:35:57 +02:00
|
|
|
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) {
|
2023-07-26 16:15:24 +03:00
|
|
|
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;
|
2022-12-19 19:35:57 +02:00
|
|
|
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':
|
2023-07-26 16:15:24 +03:00
|
|
|
case 'test:stderr':
|
|
|
|
case 'test:stdout':
|
2022-12-19 19:35:57 +02:00
|
|
|
callback(null, event.data.message);
|
|
|
|
break;
|
2023-02-23 09:15:37 +00:00
|
|
|
case 'test:coverage': {
|
|
|
|
const { totalLineCount } = event.data.summary.totals;
|
|
|
|
callback(null, `total line count: ${totalLineCount}\n`);
|
|
|
|
break;
|
|
|
|
}
|
2022-12-19 19:35:57 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
export default customReporter;
|
|
|
|
```
|
|
|
|
|
|
|
|
```cjs
|
|
|
|
const { Transform } = require('node:stream');
|
|
|
|
|
|
|
|
const customReporter = new Transform({
|
|
|
|
writableObjectMode: true,
|
|
|
|
transform(event, encoding, callback) {
|
|
|
|
switch (event.type) {
|
2023-07-26 16:15:24 +03:00
|
|
|
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;
|
2022-12-19 19:35:57 +02:00
|
|
|
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':
|
2023-07-26 16:15:24 +03:00
|
|
|
case 'test:stderr':
|
|
|
|
case 'test:stdout':
|
2022-12-19 19:35:57 +02:00
|
|
|
callback(null, event.data.message);
|
|
|
|
break;
|
2023-02-23 09:15:37 +00:00
|
|
|
case 'test:coverage': {
|
|
|
|
const { totalLineCount } = event.data.summary.totals;
|
|
|
|
callback(null, `total line count: ${totalLineCount}\n`);
|
|
|
|
break;
|
|
|
|
}
|
2022-12-19 19:35:57 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
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) {
|
2023-07-26 16:15:24 +03:00
|
|
|
case 'test:dequeue':
|
|
|
|
yield `test ${event.data.name} dequeued`;
|
|
|
|
break;
|
|
|
|
case 'test:enqueue':
|
|
|
|
yield `test ${event.data.name} enqueued`;
|
|
|
|
break;
|
|
|
|
case 'test:watch:drained':
|
|
|
|
yield 'test watch queue drained';
|
|
|
|
break;
|
2022-12-19 19:35:57 +02:00
|
|
|
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';
|
|
|
|
break;
|
|
|
|
case 'test:diagnostic':
|
2023-07-26 16:15:24 +03:00
|
|
|
case 'test:stderr':
|
|
|
|
case 'test:stdout':
|
2022-12-19 19:35:57 +02:00
|
|
|
yield `${event.data.message}\n`;
|
|
|
|
break;
|
2023-02-23 09:15:37 +00:00
|
|
|
case 'test:coverage': {
|
|
|
|
const { totalLineCount } = event.data.summary.totals;
|
|
|
|
yield `total line count: ${totalLineCount}\n`;
|
|
|
|
break;
|
|
|
|
}
|
2022-12-19 19:35:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
```cjs
|
|
|
|
module.exports = async function * customReporter(source) {
|
|
|
|
for await (const event of source) {
|
|
|
|
switch (event.type) {
|
2023-07-26 16:15:24 +03:00
|
|
|
case 'test:dequeue':
|
|
|
|
yield `test ${event.data.name} dequeued`;
|
|
|
|
break;
|
|
|
|
case 'test:enqueue':
|
|
|
|
yield `test ${event.data.name} enqueued`;
|
|
|
|
break;
|
|
|
|
case 'test:watch:drained':
|
|
|
|
yield 'test watch queue drained';
|
|
|
|
break;
|
2022-12-19 19:35:57 +02:00
|
|
|
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':
|
2023-07-26 16:15:24 +03:00
|
|
|
case 'test:stderr':
|
|
|
|
case 'test:stdout':
|
2022-12-19 19:35:57 +02:00
|
|
|
yield `${event.data.message}\n`;
|
|
|
|
break;
|
2023-02-23 09:15:37 +00:00
|
|
|
case 'test:coverage': {
|
|
|
|
const { totalLineCount } = event.data.summary.totals;
|
|
|
|
yield `total line count: ${totalLineCount}\n`;
|
|
|
|
break;
|
|
|
|
}
|
2022-12-19 19:35:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
```
|
|
|
|
|
2022-12-22 13:40:32 -08:00
|
|
|
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`][].
|
|
|
|
|
2022-12-19 19:35:57 +02:00
|
|
|
### 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.
|
|
|
|
|
2022-08-15 12:12:11 +03:00
|
|
|
## `run([options])`
|
|
|
|
|
|
|
|
<!-- YAML
|
2022-12-08 14:06:06 -05:00
|
|
|
added:
|
|
|
|
- v18.9.0
|
|
|
|
- v16.19.0
|
2023-04-20 00:16:57 +02:00
|
|
|
changes:
|
2023-07-10 08:12:52 -04:00
|
|
|
- version:
|
|
|
|
- v20.1.0
|
|
|
|
- v18.17.0
|
2023-04-20 00:16:57 +02:00
|
|
|
pr-url: https://github.com/nodejs/node/pull/47628
|
|
|
|
description: Add a testNamePatterns option.
|
2022-08-15 12:12:11 +03:00
|
|
|
-->
|
|
|
|
|
|
|
|
* `options` {Object} Configuration options for running tests. The following
|
|
|
|
properties are supported:
|
|
|
|
* `concurrency` {number|boolean} If a number is provided,
|
2023-04-24 17:38:12 +02:00
|
|
|
then that many test processes would run in parallel, where each process
|
|
|
|
corresponds to one test file.
|
2023-01-31 18:50:59 +02:00
|
|
|
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`.
|
2022-08-15 12:12:11 +03:00
|
|
|
* `files`: {Array} An array containing the list of files to run.
|
|
|
|
**Default** matching files from [test runner execution model][].
|
2022-09-10 20:01:42 +03:00
|
|
|
* `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`.
|
|
|
|
**Default:** `undefined`.
|
2023-06-02 00:01:48 +03:00
|
|
|
* `setup` {Function} A function that accepts the `TestsStream` instance
|
|
|
|
and can be used to setup listeners before any tests are run.
|
|
|
|
**Default:** `undefined`.
|
|
|
|
* `signal` {AbortSignal} Allows aborting an in-progress test execution.
|
2023-04-20 00:16:57 +02:00
|
|
|
* `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`.
|
2023-06-02 00:01:48 +03:00
|
|
|
* `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`.
|
2023-07-05 06:57:28 +03:00
|
|
|
* `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_.
|
2022-12-19 19:35:57 +02:00
|
|
|
* Returns: {TestsStream}
|
2022-08-15 12:12:11 +03:00
|
|
|
|
2023-03-28 15:10:34 +03:00
|
|
|
```mjs
|
|
|
|
import { tap } from 'node:test/reporters';
|
|
|
|
import process from 'node:process';
|
|
|
|
|
|
|
|
run({ files: [path.resolve('./tests/test.js')] })
|
|
|
|
.compose(tap)
|
|
|
|
.pipe(process.stdout);
|
|
|
|
```
|
|
|
|
|
|
|
|
```cjs
|
|
|
|
const { tap } = require('node:test/reporters');
|
|
|
|
|
2022-08-15 12:12:11 +03:00
|
|
|
run({ files: [path.resolve('./tests/test.js')] })
|
2023-03-28 15:10:34 +03:00
|
|
|
.compose(tap)
|
2022-08-15 12:12:11 +03:00
|
|
|
.pipe(process.stdout);
|
|
|
|
```
|
|
|
|
|
2022-02-09 00:23:36 -05:00
|
|
|
## `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
|
2022-07-14 11:11:42 +03:00
|
|
|
changes:
|
2023-07-10 08:12:52 -04:00
|
|
|
- version:
|
|
|
|
- v20.2.0
|
|
|
|
- v18.17.0
|
2023-05-15 08:23:22 +03:00
|
|
|
pr-url: https://github.com/nodejs/node/pull/47909
|
|
|
|
description: Added the `skip`, `todo`, and `only` shorthands.
|
2022-10-11 14:54:19 -05:00
|
|
|
- version:
|
|
|
|
- v18.8.0
|
|
|
|
- v16.18.0
|
2022-07-26 07:43:56 +03:00
|
|
|
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
|
2022-07-25 22:32:16 -04:00
|
|
|
pr-url: https://github.com/nodejs/node/pull/43505
|
|
|
|
description: Add a `timeout` option.
|
2022-02-09 00:23:36 -05:00
|
|
|
-->
|
|
|
|
|
|
|
|
* `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:
|
2022-07-25 03:11:46 +05:30
|
|
|
* `concurrency` {number|boolean} If a number is provided,
|
2023-04-24 17:38:12 +02:00
|
|
|
then that many tests would run in parallel within the application thread.
|
2023-04-28 20:32:08 +02:00
|
|
|
If `true`, all scheduled asynchronous tests run concurrently within the
|
|
|
|
thread. If `false`, only one test runs at a time.
|
2022-02-09 00:23:36 -05:00
|
|
|
If unspecified, subtests inherit this value from their parent.
|
2022-07-25 03:11:46 +05:30
|
|
|
**Default:** `false`.
|
2022-04-04 10:14:49 -04:00
|
|
|
* `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`.
|
2022-07-26 13:52:51 +02:00
|
|
|
* `signal` {AbortSignal} Allows aborting an in-progress test.
|
2022-02-09 00:23:36 -05:00
|
|
|
* `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`.
|
2022-07-14 11:11:42 +03:00
|
|
|
* `timeout` {number} A number of milliseconds the test will fail after.
|
|
|
|
If unspecified, subtests inherit this value from their parent.
|
2022-07-20 17:40:43 +02:00
|
|
|
**Default:** `Infinity`.
|
2022-06-14 10:54:50 +03:00
|
|
|
* `fn` {Function|AsyncFunction} The function under test. The first argument
|
2022-02-09 00:23:36 -05:00
|
|
|
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.
|
2023-02-28 22:26:58 +02:00
|
|
|
* Returns: {Promise} Resolved with `undefined` once
|
|
|
|
the test completes, or immediately if the test runs within [`describe()`][].
|
2022-02-09 00:23:36 -05:00
|
|
|
|
|
|
|
The `test()` function is the value imported from the `test` module. Each
|
2022-12-19 19:35:57 +02:00
|
|
|
invocation of this function results in reporting the test to the {TestsStream}.
|
2022-02-09 00:23:36 -05:00
|
|
|
|
|
|
|
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
|
2022-12-19 19:35:57 +02:00
|
|
|
additional diagnostic information, or creating subtests.
|
2022-02-09 00:23:36 -05:00
|
|
|
|
2023-02-28 22:26:58 +02:00
|
|
|
`test()` returns a `Promise` that resolves once the test completes.
|
|
|
|
if `test()` is called within a `describe()` block, it resolve immediately.
|
|
|
|
The return value can usually be discarded for top level tests.
|
|
|
|
However, the return value from subtests should be used to prevent the parent
|
|
|
|
test from finishing first and cancelling the subtest
|
|
|
|
as shown in the following example.
|
2022-02-09 00:23:36 -05:00
|
|
|
|
|
|
|
```js
|
|
|
|
test('top level test', async (t) => {
|
|
|
|
// The setTimeout() in the following subtest would cause it to outlive its
|
|
|
|
// parent test if 'await' is removed on the next line. Once the parent test
|
|
|
|
// completes, it will cancel any outstanding subtests.
|
|
|
|
await t.test('longer running subtest', async (t) => {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
setTimeout(resolve, 1000);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2022-07-20 17:40:43 +02:00
|
|
|
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.
|
|
|
|
|
2023-05-15 08:23:22 +03:00
|
|
|
## `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].
|
|
|
|
|
2022-06-14 10:54:50 +03:00
|
|
|
## `describe([name][, options][, fn])`
|
|
|
|
|
|
|
|
* `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} Configuration options for the suite.
|
2022-07-31 14:58:18 +02:00
|
|
|
supports the same options as `test([name][, options][, fn])`.
|
2022-07-20 15:32:58 +03:00
|
|
|
* `fn` {Function|AsyncFunction} The function under suite
|
|
|
|
declaring all subtests and subsuites.
|
|
|
|
The first argument to this function is a [`SuiteContext`][] object.
|
2022-06-14 10:54:50 +03:00
|
|
|
**Default:** A no-op function.
|
2023-06-29 06:39:44 +01:00
|
|
|
* Returns: {Promise} Immediately fulfilled with `undefined`.
|
2022-06-14 10:54:50 +03:00
|
|
|
|
|
|
|
The `describe()` function imported from the `node:test` module. Each
|
2022-12-19 19:35:57 +02:00
|
|
|
invocation of this function results in the creation of a Subtest.
|
2022-06-14 10:54:50 +03:00
|
|
|
After invocation of top level `describe` functions,
|
2022-07-31 14:58:18 +02:00
|
|
|
all top level tests and suites will execute.
|
2022-06-14 10:54:50 +03:00
|
|
|
|
|
|
|
## `describe.skip([name][, options][, fn])`
|
|
|
|
|
|
|
|
Shorthand for skipping a suite, same as [`describe([name], { skip: true }[, fn])`][describe options].
|
|
|
|
|
|
|
|
## `describe.todo([name][, options][, fn])`
|
|
|
|
|
|
|
|
Shorthand for marking a suite as `TODO`, same as
|
|
|
|
[`describe([name], { todo: true }[, fn])`][describe options].
|
|
|
|
|
2023-02-21 22:28:03 +00:00
|
|
|
## `describe.only([name][, options][, fn])`
|
|
|
|
|
|
|
|
<!-- YAML
|
2023-03-14 08:50:18 +01:00
|
|
|
added:
|
|
|
|
- v19.8.0
|
|
|
|
- v18.15.0
|
2023-02-21 22:28:03 +00:00
|
|
|
-->
|
|
|
|
|
|
|
|
Shorthand for marking a suite as `only`, same as
|
|
|
|
[`describe([name], { only: true }[, fn])`][describe options].
|
|
|
|
|
2022-06-14 10:54:50 +03:00
|
|
|
## `it([name][, options][, fn])`
|
|
|
|
|
2023-02-28 21:58:49 +02:00
|
|
|
<!-- YAML
|
|
|
|
added:
|
|
|
|
- v18.6.0
|
|
|
|
- v16.17.0
|
|
|
|
changes:
|
2023-04-10 23:02:28 -04:00
|
|
|
- version:
|
|
|
|
- v19.8.0
|
|
|
|
- v18.16.0
|
2023-02-28 21:58:49 +02:00
|
|
|
pr-url: https://github.com/nodejs/node/pull/46889
|
|
|
|
description: Calling `it()` is now equivalent to calling `test()`.
|
|
|
|
-->
|
|
|
|
|
|
|
|
Shorthand for [`test()`][].
|
2022-06-14 10:54:50 +03:00
|
|
|
|
2023-02-28 21:58:49 +02:00
|
|
|
The `it()` function is imported from the `node:test` module.
|
2022-06-14 10:54:50 +03:00
|
|
|
|
|
|
|
## `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].
|
|
|
|
|
2023-02-21 22:28:03 +00:00
|
|
|
## `it.only([name][, options][, fn])`
|
|
|
|
|
|
|
|
<!-- YAML
|
2023-03-14 08:50:18 +01:00
|
|
|
added:
|
|
|
|
- v19.8.0
|
|
|
|
- v18.15.0
|
2023-02-21 22:28:03 +00:00
|
|
|
-->
|
|
|
|
|
|
|
|
Shorthand for marking a test as `only`,
|
|
|
|
same as [`it([name], { only: true }[, fn])`][it options].
|
|
|
|
|
2022-10-03 21:56:25 -04:00
|
|
|
## `before([fn][, options])`
|
2022-06-30 10:14:35 +03:00
|
|
|
|
|
|
|
<!-- YAML
|
2022-10-11 14:54:19 -05:00
|
|
|
added:
|
|
|
|
- v18.8.0
|
|
|
|
- v16.18.0
|
2022-06-30 10:14:35 +03:00
|
|
|
-->
|
|
|
|
|
|
|
|
* `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:
|
2022-07-31 14:58:18 +02:00
|
|
|
* `signal` {AbortSignal} Allows aborting an in-progress hook.
|
2022-06-30 10:14:35 +03:00
|
|
|
* `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 running a suite.
|
|
|
|
|
|
|
|
```js
|
|
|
|
describe('tests', async () => {
|
|
|
|
before(() => console.log('about to run some test'));
|
|
|
|
it('is a subtest', () => {
|
|
|
|
assert.ok('some relevant assertion here');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2022-10-03 21:56:25 -04:00
|
|
|
## `after([fn][, options])`
|
2022-06-30 10:14:35 +03:00
|
|
|
|
|
|
|
<!-- YAML
|
2022-10-11 14:54:19 -05:00
|
|
|
added:
|
|
|
|
- v18.8.0
|
|
|
|
- v16.18.0
|
2022-06-30 10:14:35 +03:00
|
|
|
-->
|
|
|
|
|
|
|
|
* `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:
|
2022-07-31 14:58:18 +02:00
|
|
|
* `signal` {AbortSignal} Allows aborting an in-progress hook.
|
2022-06-30 10:14:35 +03:00
|
|
|
* `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 running a suite.
|
|
|
|
|
|
|
|
```js
|
|
|
|
describe('tests', async () => {
|
|
|
|
after(() => console.log('finished running tests'));
|
|
|
|
it('is a subtest', () => {
|
|
|
|
assert.ok('some relevant assertion here');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2022-10-03 21:56:25 -04:00
|
|
|
## `beforeEach([fn][, options])`
|
2022-06-30 10:14:35 +03:00
|
|
|
|
|
|
|
<!-- YAML
|
2022-10-11 14:54:19 -05:00
|
|
|
added:
|
|
|
|
- v18.8.0
|
|
|
|
- v16.18.0
|
2022-06-30 10:14:35 +03:00
|
|
|
-->
|
|
|
|
|
|
|
|
* `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:
|
2022-07-31 14:58:18 +02:00
|
|
|
* `signal` {AbortSignal} Allows aborting an in-progress hook.
|
2022-06-30 10:14:35 +03:00
|
|
|
* `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 suite.
|
|
|
|
|
|
|
|
```js
|
|
|
|
describe('tests', async () => {
|
2023-02-10 11:46:24 +00:00
|
|
|
beforeEach(() => console.log('about to run a test'));
|
2022-06-30 10:14:35 +03:00
|
|
|
it('is a subtest', () => {
|
|
|
|
assert.ok('some relevant assertion here');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2022-10-03 21:56:25 -04:00
|
|
|
## `afterEach([fn][, options])`
|
2022-06-30 10:14:35 +03:00
|
|
|
|
|
|
|
<!-- YAML
|
2022-10-11 14:54:19 -05:00
|
|
|
added:
|
|
|
|
- v18.8.0
|
|
|
|
- v16.18.0
|
2022-06-30 10:14:35 +03:00
|
|
|
-->
|
|
|
|
|
|
|
|
* `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:
|
2022-07-31 14:58:18 +02:00
|
|
|
* `signal` {AbortSignal} Allows aborting an in-progress hook.
|
2022-06-30 10:14:35 +03:00
|
|
|
* `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
|
|
|
|
describe('tests', async () => {
|
2023-02-10 11:46:24 +00:00
|
|
|
afterEach(() => console.log('finished running a test'));
|
2022-06-30 10:14:35 +03:00
|
|
|
it('is a subtest', () => {
|
|
|
|
assert.ok('some relevant assertion here');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2022-04-04 18:36:40 -04:00
|
|
|
## 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
|
2022-04-04 18:36:40 -04:00
|
|
|
-->
|
|
|
|
|
|
|
|
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
|
2022-04-04 18:36:40 -04:00
|
|
|
-->
|
|
|
|
|
|
|
|
* {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
|
2022-04-04 18:36:40 -04:00
|
|
|
-->
|
|
|
|
|
|
|
|
* 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
|
2022-04-04 18:36:40 -04:00
|
|
|
-->
|
|
|
|
|
|
|
|
* `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
|
2022-04-04 18:36:40 -04:00
|
|
|
-->
|
|
|
|
|
|
|
|
* `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);
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2022-12-09 05:28:38 +09:00
|
|
|
### `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
|
2022-12-09 05:28:38 +09:00
|
|
|
-->
|
|
|
|
|
|
|
|
Resets the call history of the mock function.
|
|
|
|
|
2022-04-04 18:36:40 -04:00
|
|
|
### `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
|
2022-04-04 18:36:40 -04:00
|
|
|
-->
|
|
|
|
|
|
|
|
Resets the implementation of the mock function to its original behavior. The
|
|
|
|
mock can still be used after calling this function.
|
|
|
|
|
|
|
|
## 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
|
2022-04-04 18:36:40 -04:00
|
|
|
-->
|
|
|
|
|
|
|
|
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
|
2022-04-04 18:36:40 -04:00
|
|
|
-->
|
|
|
|
|
|
|
|
* `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);
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2022-11-18 18:31:49 +09:00
|
|
|
### `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
|
2022-11-18 18:31:49 +09:00
|
|
|
-->
|
|
|
|
|
|
|
|
This function is syntax sugar for [`MockTracker.method`][] with `options.getter`
|
|
|
|
set to `true`.
|
|
|
|
|
2022-04-04 18:36:40 -04:00
|
|
|
### `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
|
2022-04-04 18:36:40 -04:00
|
|
|
-->
|
|
|
|
|
|
|
|
* `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.calls.length, 0);
|
|
|
|
assert.strictEqual(number.subtract(3), 2);
|
|
|
|
assert.strictEqual(number.subtract.mock.calls.length, 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.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
|
2022-04-04 18:36:40 -04:00
|
|
|
-->
|
|
|
|
|
|
|
|
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
|
2022-04-04 18:36:40 -04:00
|
|
|
-->
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
2022-11-18 18:31:49 +09:00
|
|
|
### `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
|
2022-11-18 18:31:49 +09:00
|
|
|
-->
|
|
|
|
|
|
|
|
This function is syntax sugar for [`MockTracker.method`][] with `options.setter`
|
|
|
|
set to `true`.
|
|
|
|
|
2023-06-22 01:01:52 -03:00
|
|
|
## Class: `MockTimers`
|
|
|
|
|
|
|
|
<!-- YAML
|
|
|
|
added:
|
2023-07-03 10:45:00 -03:00
|
|
|
- v20.4.0
|
2023-06-22 01:01:52 -03:00
|
|
|
-->
|
|
|
|
|
|
|
|
> Stability: 1 - Experimental
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
The [`MockTracker`][] provides a top-level `timers` export
|
|
|
|
which is a `MockTimers` instance.
|
|
|
|
|
|
|
|
### `timers.enable([timers])`
|
|
|
|
|
|
|
|
<!-- YAML
|
|
|
|
added:
|
2023-07-03 10:45:00 -03:00
|
|
|
- v20.4.0
|
2023-06-22 01:01:52 -03:00
|
|
|
-->
|
|
|
|
|
|
|
|
Enables timer mocking for the specified timers.
|
|
|
|
|
|
|
|
* `timers` {Array} An optional array containing the timers to mock.
|
2023-08-31 03:42:03 -03:00
|
|
|
The currently supported timer values are `'setInterval'`, `'setTimeout'`,
|
|
|
|
and `'setImmediate'`. If no value is provided, all timers (`'setInterval'`,
|
|
|
|
`'clearInterval'`, `'setTimeout'`, `'clearTimeout'`, `'setImmediate'`,
|
|
|
|
and `'clearImmediate'`) will be mocked by default.
|
2023-06-22 01:01:52 -03:00
|
|
|
|
|
|
|
**Note:** When you enable mocking for a specific timer, its associated
|
|
|
|
clear function will also be implicitly mocked.
|
|
|
|
|
|
|
|
Example usage:
|
|
|
|
|
|
|
|
```mjs
|
|
|
|
import { mock } from 'node:test';
|
|
|
|
mock.timers.enable(['setInterval']);
|
|
|
|
```
|
|
|
|
|
2023-08-26 23:57:18 +09:00
|
|
|
```cjs
|
2023-06-22 01:01:52 -03:00
|
|
|
const { mock } = require('node:test');
|
|
|
|
mock.timers.enable(['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.
|
|
|
|
|
|
|
|
Alternatively, if you call `mock.timers.enable()` without any parameters:
|
|
|
|
|
|
|
|
All timers (`'setInterval'`, `'clearInterval'`, `'setTimeout'`, and `'clearTimeout'`)
|
|
|
|
will be mocked. The `setInterval`, `clearInterval`, `setTimeout`, and `clearTimeout`
|
|
|
|
functions from `node:timers`, `node:timers/promises`,
|
|
|
|
and `globalThis` will be mocked.
|
|
|
|
|
|
|
|
### `timers.reset()`
|
|
|
|
|
|
|
|
<!-- YAML
|
|
|
|
added:
|
2023-07-03 10:45:00 -03:00
|
|
|
- v20.4.0
|
2023-06-22 01:01:52 -03:00
|
|
|
-->
|
|
|
|
|
|
|
|
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();
|
|
|
|
```
|
|
|
|
|
2023-08-26 23:57:18 +09:00
|
|
|
```cjs
|
2023-06-22 01:01:52 -03:00
|
|
|
const { mock } = require('node:test');
|
|
|
|
mock.timers.reset();
|
|
|
|
```
|
|
|
|
|
2023-06-29 10:45:44 +03:00
|
|
|
### `timers[Symbol.dispose]()`
|
|
|
|
|
|
|
|
Calls `timers.reset()`.
|
|
|
|
|
2023-06-22 01:01:52 -03:00
|
|
|
### `timers.tick(milliseconds)`
|
|
|
|
|
|
|
|
<!-- YAML
|
|
|
|
added:
|
2023-07-03 10:45:00 -03:00
|
|
|
- v20.4.0
|
2023-06-22 01:01:52 -03:00
|
|
|
-->
|
|
|
|
|
|
|
|
Advances time for all mocked timers.
|
|
|
|
|
|
|
|
* `milliseconds` {number} The amount of time, in milliseconds,
|
|
|
|
to advance the timers.
|
|
|
|
|
|
|
|
**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(['setTimeout']);
|
|
|
|
|
|
|
|
setTimeout(fn, 9999);
|
|
|
|
|
|
|
|
assert.strictEqual(fn.mock.callCount(), 0);
|
|
|
|
|
|
|
|
// Advance in time
|
|
|
|
context.mock.timers.tick(9999);
|
|
|
|
|
|
|
|
assert.strictEqual(fn.mock.callCount(), 1);
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2023-08-26 23:57:18 +09:00
|
|
|
```cjs
|
2023-06-22 01:01:52 -03:00
|
|
|
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(['setTimeout']);
|
|
|
|
|
|
|
|
setTimeout(fn, 9999);
|
|
|
|
assert.strictEqual(fn.mock.callCount(), 0);
|
|
|
|
|
|
|
|
// Advance in time
|
|
|
|
context.mock.timers.tick(9999);
|
|
|
|
|
|
|
|
assert.strictEqual(fn.mock.callCount(), 1);
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
Alternativelly, 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(['setTimeout']);
|
|
|
|
const nineSecs = 9000;
|
|
|
|
setTimeout(fn, nineSecs);
|
|
|
|
|
|
|
|
const twoSeconds = 3000;
|
|
|
|
context.mock.timers.tick(twoSeconds);
|
|
|
|
context.mock.timers.tick(twoSeconds);
|
|
|
|
context.mock.timers.tick(twoSeconds);
|
|
|
|
|
|
|
|
assert.strictEqual(fn.mock.callCount(), 1);
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2023-08-26 23:57:18 +09:00
|
|
|
```cjs
|
2023-06-22 01:01:52 -03:00
|
|
|
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(['setTimeout']);
|
|
|
|
const nineSecs = 9000;
|
|
|
|
setTimeout(fn, nineSecs);
|
|
|
|
|
|
|
|
const twoSeconds = 3000;
|
|
|
|
context.mock.timers.tick(twoSeconds);
|
|
|
|
context.mock.timers.tick(twoSeconds);
|
|
|
|
context.mock.timers.tick(twoSeconds);
|
|
|
|
|
|
|
|
assert.strictEqual(fn.mock.callCount(), 1);
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
#### Using clear functions
|
|
|
|
|
|
|
|
As mentioned, all clear functions from timers (`clearTimeout` and `clearInterval`)
|
|
|
|
are implicity 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(['setTimeout']);
|
|
|
|
const id = setTimeout(fn, 9999);
|
|
|
|
|
|
|
|
// Implicity 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);
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2023-08-26 23:57:18 +09:00
|
|
|
```cjs
|
2023-06-22 01:01:52 -03:00
|
|
|
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(['setTimeout']);
|
|
|
|
const id = setTimeout(fn, 9999);
|
|
|
|
|
|
|
|
// Implicity 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(['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);
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2023-08-26 23:57:18 +09:00
|
|
|
```cjs
|
2023-06-22 01:01:52 -03:00
|
|
|
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(['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(['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));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2023-08-26 23:57:18 +09:00
|
|
|
```cjs
|
2023-06-22 01:01:52 -03:00
|
|
|
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(['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:
|
2023-07-03 10:45:00 -03:00
|
|
|
- v20.4.0
|
2023-06-22 01:01:52 -03:00
|
|
|
-->
|
|
|
|
|
|
|
|
Triggers all pending mocked timers immediately.
|
|
|
|
|
|
|
|
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(['setTimeout']);
|
|
|
|
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]);
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2023-08-26 23:57:18 +09:00
|
|
|
```cjs
|
2023-06-22 01:01:52 -03:00
|
|
|
const assert = require('node:assert');
|
|
|
|
const { test } = require('node:test');
|
|
|
|
|
|
|
|
test('runAll functions following the given order', (context) => {
|
|
|
|
context.mock.timers.enable(['setTimeout']);
|
|
|
|
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]);
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
**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.
|
|
|
|
|
2022-12-19 19:35:57 +02:00
|
|
|
## Class: `TestsStream`
|
2022-08-15 12:12:11 +03:00
|
|
|
|
|
|
|
<!-- YAML
|
2022-12-16 20:30:13 +00:00
|
|
|
added:
|
|
|
|
- v18.9.0
|
|
|
|
- v16.19.0
|
2023-08-08 20:43:42 +02:00
|
|
|
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.
|
2022-08-15 12:12:11 +03:00
|
|
|
-->
|
|
|
|
|
|
|
|
* Extends {ReadableStream}
|
|
|
|
|
2022-12-19 19:35:57 +02:00
|
|
|
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
|
2022-08-15 12:12:11 +03:00
|
|
|
|
2022-12-21 13:26:16 -05:00
|
|
|
### 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.
|
2023-08-30 22:22:45 +02:00
|
|
|
* `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.
|
2022-12-21 13:26:16 -05:00
|
|
|
* `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.
|
|
|
|
|
2023-06-13 21:33:43 +03:00
|
|
|
### Event: `'test:dequeue'`
|
|
|
|
|
|
|
|
* `data` {Object}
|
2023-07-30 18:17:39 -04:00
|
|
|
* `column` {number|undefined} The column number where the test is defined, or
|
|
|
|
`undefined` if the test was run through the REPL.
|
2023-06-13 21:33:43 +03:00
|
|
|
* `file` {string|undefined} The path of the test file,
|
2023-06-14 15:41:27 +03:00
|
|
|
`undefined` if test was run through the REPL.
|
2023-07-30 18:17:39 -04:00
|
|
|
* `line` {number|undefined} The line number where the test is defined, or
|
|
|
|
`undefined` if the test was run through the REPL.
|
2023-06-13 21:33:43 +03:00
|
|
|
* `name` {string} The test name.
|
|
|
|
* `nesting` {number} The nesting level of the test.
|
|
|
|
|
|
|
|
Emitted when a test is dequeued, right before it is executed.
|
|
|
|
|
2022-08-15 12:12:11 +03:00
|
|
|
### Event: `'test:diagnostic'`
|
|
|
|
|
2022-12-19 19:35:57 +02:00
|
|
|
* `data` {Object}
|
2023-07-30 18:17:39 -04:00
|
|
|
* `column` {number|undefined} The column number where the test is defined, or
|
|
|
|
`undefined` if the test was run through the REPL.
|
2023-01-02 23:22:54 +02:00
|
|
|
* `file` {string|undefined} The path of the test file,
|
2023-06-14 15:41:27 +03:00
|
|
|
`undefined` if test was run through the REPL.
|
2023-07-30 18:17:39 -04:00
|
|
|
* `line` {number|undefined} The line number where the test is defined, or
|
|
|
|
`undefined` if the test was run through the REPL.
|
2022-12-19 19:35:57 +02:00
|
|
|
* `message` {string} The diagnostic message.
|
|
|
|
* `nesting` {number} The nesting level of the test.
|
2022-08-15 12:12:11 +03:00
|
|
|
|
|
|
|
Emitted when [`context.diagnostic`][] is called.
|
|
|
|
|
2023-06-13 21:33:43 +03:00
|
|
|
### Event: `'test:enqueue'`
|
|
|
|
|
|
|
|
* `data` {Object}
|
2023-07-30 18:17:39 -04:00
|
|
|
* `column` {number|undefined} The column number where the test is defined, or
|
|
|
|
`undefined` if the test was run through the REPL.
|
2023-06-13 21:33:43 +03:00
|
|
|
* `file` {string|undefined} The path of the test file,
|
2023-06-14 15:41:27 +03:00
|
|
|
`undefined` if test was run through the REPL.
|
2023-07-30 18:17:39 -04:00
|
|
|
* `line` {number|undefined} The line number where the test is defined, or
|
|
|
|
`undefined` if the test was run through the REPL.
|
2023-06-13 21:33:43 +03:00
|
|
|
* `name` {string} The test name.
|
|
|
|
* `nesting` {number} The nesting level of the test.
|
|
|
|
|
|
|
|
Emitted when a test is enqueued for execution.
|
|
|
|
|
2022-08-15 12:12:11 +03:00
|
|
|
### Event: `'test:fail'`
|
|
|
|
|
|
|
|
* `data` {Object}
|
2023-07-30 18:17:39 -04:00
|
|
|
* `column` {number|undefined} The column number where the test is defined, or
|
|
|
|
`undefined` if the test was run through the REPL.
|
2022-11-21 23:50:21 +01:00
|
|
|
* `details` {Object} Additional execution metadata.
|
2023-07-25 20:34:16 +07:00
|
|
|
* `duration_ms` {number} The duration of the test in milliseconds.
|
2023-07-22 10:02:40 -06:00
|
|
|
* `error` {Error} An error wrapping the error thrown by the test.
|
|
|
|
* `cause` {Error} The actual error thrown by the test.
|
2023-08-08 20:43:42 +02:00
|
|
|
* `type` {string|undefined} The type of the test, used to denote whether
|
|
|
|
this is a suite.
|
2023-01-02 23:22:54 +02:00
|
|
|
* `file` {string|undefined} The path of the test file,
|
2023-06-14 15:41:27 +03:00
|
|
|
`undefined` if test was run through the REPL.
|
2023-07-30 18:17:39 -04:00
|
|
|
* `line` {number|undefined} The line number where the test is defined, or
|
|
|
|
`undefined` if the test was run through the REPL.
|
2022-08-15 12:12:11 +03:00
|
|
|
* `name` {string} The test name.
|
2022-12-19 19:35:57 +02:00
|
|
|
* `nesting` {number} The nesting level of the test.
|
2022-08-15 12:12:11 +03:00
|
|
|
* `testNumber` {number} The ordinal number of the test.
|
2022-12-19 19:35:57 +02:00
|
|
|
* `todo` {string|boolean|undefined} Present if [`context.todo`][] is called
|
|
|
|
* `skip` {string|boolean|undefined} Present if [`context.skip`][] is called
|
2022-08-15 12:12:11 +03:00
|
|
|
|
|
|
|
Emitted when a test fails.
|
|
|
|
|
|
|
|
### Event: `'test:pass'`
|
|
|
|
|
|
|
|
* `data` {Object}
|
2023-07-30 18:17:39 -04:00
|
|
|
* `column` {number|undefined} The column number where the test is defined, or
|
|
|
|
`undefined` if the test was run through the REPL.
|
2022-11-21 23:50:21 +01:00
|
|
|
* `details` {Object} Additional execution metadata.
|
2023-07-25 20:34:16 +07:00
|
|
|
* `duration_ms` {number} The duration of the test in milliseconds.
|
2023-08-08 20:43:42 +02:00
|
|
|
* `type` {string|undefined} The type of the test, used to denote whether
|
|
|
|
this is a suite.
|
2023-01-02 23:22:54 +02:00
|
|
|
* `file` {string|undefined} The path of the test file,
|
2023-06-14 15:41:27 +03:00
|
|
|
`undefined` if test was run through the REPL.
|
2023-07-30 18:17:39 -04:00
|
|
|
* `line` {number|undefined} The line number where the test is defined, or
|
|
|
|
`undefined` if the test was run through the REPL.
|
2022-08-15 12:12:11 +03:00
|
|
|
* `name` {string} The test name.
|
2022-12-19 19:35:57 +02:00
|
|
|
* `nesting` {number} The nesting level of the test.
|
2022-08-15 12:12:11 +03:00
|
|
|
* `testNumber` {number} The ordinal number of the test.
|
2022-12-19 19:35:57 +02:00
|
|
|
* `todo` {string|boolean|undefined} Present if [`context.todo`][] is called
|
|
|
|
* `skip` {string|boolean|undefined} Present if [`context.skip`][] is called
|
2022-08-15 12:12:11 +03:00
|
|
|
|
|
|
|
Emitted when a test passes.
|
|
|
|
|
2022-12-19 19:35:57 +02:00
|
|
|
### Event: `'test:plan'`
|
|
|
|
|
|
|
|
* `data` {Object}
|
2023-07-30 18:17:39 -04:00
|
|
|
* `column` {number|undefined} The column number where the test is defined, or
|
|
|
|
`undefined` if the test was run through the REPL.
|
2023-01-02 23:22:54 +02:00
|
|
|
* `file` {string|undefined} The path of the test file,
|
2023-06-14 15:41:27 +03:00
|
|
|
`undefined` if test was run through the REPL.
|
2023-07-30 18:17:39 -04:00
|
|
|
* `line` {number|undefined} The line number where the test is defined, or
|
|
|
|
`undefined` if the test was run through the REPL.
|
2022-12-19 19:35:57 +02:00
|
|
|
* `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.
|
|
|
|
|
|
|
|
### Event: `'test:start'`
|
|
|
|
|
|
|
|
* `data` {Object}
|
2023-07-30 18:17:39 -04:00
|
|
|
* `column` {number|undefined} The column number where the test is defined, or
|
|
|
|
`undefined` if the test was run through the REPL.
|
2023-01-02 23:22:54 +02:00
|
|
|
* `file` {string|undefined} The path of the test file,
|
2023-06-14 15:41:27 +03:00
|
|
|
`undefined` if test was run through the REPL.
|
2023-07-30 18:17:39 -04:00
|
|
|
* `line` {number|undefined} The line number where the test is defined, or
|
|
|
|
`undefined` if the test was run through the REPL.
|
2022-12-19 19:35:57 +02:00
|
|
|
* `name` {string} The test name.
|
|
|
|
* `nesting` {number} The nesting level of the test.
|
|
|
|
|
2023-06-13 21:33:43 +03:00
|
|
|
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.
|
2022-12-19 19:35:57 +02:00
|
|
|
|
2023-05-23 12:44:48 +08:00
|
|
|
### Event: `'test:stderr'`
|
|
|
|
|
|
|
|
* `data` {Object}
|
2023-07-30 18:17:39 -04:00
|
|
|
* `column` {number|undefined} The column number where the test is defined, or
|
|
|
|
`undefined` if the test was run through the REPL.
|
2023-05-23 12:44:48 +08:00
|
|
|
* `file` {string} The path of the test file.
|
2023-07-30 18:17:39 -04:00
|
|
|
* `line` {number|undefined} The line number where the test is defined, or
|
|
|
|
`undefined` if the test was run through the REPL.
|
2023-05-23 12:44:48 +08:00
|
|
|
* `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.
|
|
|
|
|
|
|
|
### Event: `'test:stdout'`
|
|
|
|
|
|
|
|
* `data` {Object}
|
2023-07-30 18:17:39 -04:00
|
|
|
* `column` {number|undefined} The column number where the test is defined, or
|
|
|
|
`undefined` if the test was run through the REPL.
|
2023-05-23 12:44:48 +08:00
|
|
|
* `file` {string} The path of the test file.
|
2023-07-30 18:17:39 -04:00
|
|
|
* `line` {number|undefined} The line number where the test is defined, or
|
|
|
|
`undefined` if the test was run through the REPL.
|
2023-05-23 12:44:48 +08:00
|
|
|
* `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.
|
|
|
|
|
2023-05-31 02:53:57 +03:00
|
|
|
### Event: `'test:watch:drained'`
|
|
|
|
|
|
|
|
Emitted when no more tests are queued for execution in watch mode.
|
|
|
|
|
2022-02-09 00:23:36 -05:00
|
|
|
## 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
|
2023-04-18 23:59:49 +03:00
|
|
|
changes:
|
2023-07-10 08:12:52 -04:00
|
|
|
- version:
|
|
|
|
- v20.1.0
|
|
|
|
- v18.17.0
|
2023-04-18 23:59:49 +03:00
|
|
|
pr-url: https://github.com/nodejs/node/pull/47586
|
|
|
|
description: The `before` function was added to TestContext.
|
2022-02-09 00:23:36 -05:00
|
|
|
-->
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
2023-04-18 23:59:49 +03:00
|
|
|
### `context.before([fn][, options])`
|
|
|
|
|
|
|
|
<!-- YAML
|
2023-07-10 08:12:52 -04:00
|
|
|
added:
|
|
|
|
- v20.1.0
|
|
|
|
- v18.17.0
|
2023-04-18 23:59:49 +03:00
|
|
|
-->
|
|
|
|
|
|
|
|
* `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.
|
|
|
|
|
2022-10-03 21:56:25 -04:00
|
|
|
### `context.beforeEach([fn][, options])`
|
2022-06-30 10:14:35 +03:00
|
|
|
|
|
|
|
<!-- YAML
|
2022-10-11 14:54:19 -05:00
|
|
|
added:
|
|
|
|
- v18.8.0
|
|
|
|
- v16.18.0
|
2022-06-30 10:14:35 +03:00
|
|
|
-->
|
|
|
|
|
|
|
|
* `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:
|
2022-07-31 14:58:18 +02:00
|
|
|
* `signal` {AbortSignal} Allows aborting an in-progress hook.
|
2022-06-30 10:14:35 +03:00
|
|
|
* `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) => {
|
2022-08-23 11:21:10 +03:00
|
|
|
t.beforeEach((t) => t.diagnostic(`about to run ${t.name}`));
|
2022-06-30 10:14:35 +03:00
|
|
|
await t.test(
|
|
|
|
'This is a subtest',
|
|
|
|
(t) => {
|
|
|
|
assert.ok('some relevant assertion here');
|
2022-11-17 08:19:12 -05:00
|
|
|
},
|
2022-06-30 10:14:35 +03:00
|
|
|
);
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2022-12-08 17:21:22 -05:00
|
|
|
### `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
|
2022-12-08 17:21:22 -05:00
|
|
|
-->
|
|
|
|
|
|
|
|
* `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');
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2022-10-03 21:56:25 -04:00
|
|
|
### `context.afterEach([fn][, options])`
|
2022-06-30 10:14:35 +03:00
|
|
|
|
|
|
|
<!-- YAML
|
2022-10-11 14:54:19 -05:00
|
|
|
added:
|
|
|
|
- v18.8.0
|
|
|
|
- v16.18.0
|
2022-06-30 10:14:35 +03:00
|
|
|
-->
|
|
|
|
|
|
|
|
* `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:
|
2022-07-31 14:58:18 +02:00
|
|
|
* `signal` {AbortSignal} Allows aborting an in-progress hook.
|
2022-06-30 10:14:35 +03:00
|
|
|
* `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) => {
|
2022-08-23 11:21:10 +03:00
|
|
|
t.afterEach((t) => t.diagnostic(`finished running ${t.name}`));
|
2022-06-30 10:14:35 +03:00
|
|
|
await t.test(
|
|
|
|
'This is a subtest',
|
|
|
|
(t) => {
|
|
|
|
assert.ok('some relevant assertion here');
|
2022-11-17 08:19:12 -05:00
|
|
|
},
|
2022-06-30 10:14:35 +03:00
|
|
|
);
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2022-02-09 00:23:36 -05:00
|
|
|
### `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
|
2022-02-09 00:23:36 -05:00
|
|
|
-->
|
|
|
|
|
2022-12-19 19:35:57 +02:00
|
|
|
* `message` {string} Message to be reported.
|
2022-02-09 00:23:36 -05:00
|
|
|
|
2022-12-19 19:35:57 +02:00
|
|
|
This function is used to write diagnostics to the output. Any diagnostic
|
2022-02-09 00:23:36 -05:00
|
|
|
information is included at the end of the test's results. This function does
|
|
|
|
not return a value.
|
|
|
|
|
2022-06-09 12:23:40 +02:00
|
|
|
```js
|
|
|
|
test('top level test', (t) => {
|
|
|
|
t.diagnostic('A diagnostic message');
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2022-06-30 10:14:35 +03:00
|
|
|
### `context.name`
|
|
|
|
|
|
|
|
<!-- YAML
|
2022-10-11 14:54:19 -05:00
|
|
|
added:
|
|
|
|
- v18.8.0
|
|
|
|
- v16.18.0
|
2022-06-30 10:14:35 +03:00
|
|
|
-->
|
|
|
|
|
2022-07-31 14:58:18 +02:00
|
|
|
The name of the test.
|
2022-06-30 10:14:35 +03:00
|
|
|
|
2022-04-04 10:14:49 -04:00
|
|
|
### `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
|
2022-04-04 10:14:49 -04:00
|
|
|
-->
|
|
|
|
|
|
|
|
* `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.
|
|
|
|
|
2022-06-09 12:23:40 +02:00
|
|
|
```js
|
|
|
|
test('top level test', (t) => {
|
|
|
|
// The test context can be set to run subtests with the 'only' option.
|
|
|
|
t.runOnly(true);
|
|
|
|
return Promise.all([
|
|
|
|
t.test('this subtest is now skipped'),
|
|
|
|
t.test('this subtest is run', { only: true }),
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2022-07-20 15:32:58 +03:00
|
|
|
### `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
|
2022-07-20 15:32:58 +03:00
|
|
|
-->
|
|
|
|
|
2022-07-26 13:52:51 +02:00
|
|
|
* {AbortSignal} Can be used to abort test subtasks when the test has been
|
|
|
|
aborted.
|
2022-07-20 15:32:58 +03:00
|
|
|
|
|
|
|
```js
|
|
|
|
test('top level test', async (t) => {
|
|
|
|
await fetch('some/uri', { signal: t.signal });
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2022-02-09 00:23:36 -05:00
|
|
|
### `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
|
2022-02-09 00:23:36 -05:00
|
|
|
-->
|
|
|
|
|
2022-12-19 19:35:57 +02:00
|
|
|
* `message` {string} Optional skip message.
|
2022-02-09 00:23:36 -05:00
|
|
|
|
|
|
|
This function causes the test's output to indicate the test as skipped. If
|
2022-12-19 19:35:57 +02:00
|
|
|
`message` is provided, it is included in the output. Calling `skip()` does
|
2022-02-09 00:23:36 -05:00
|
|
|
not terminate execution of the test function. This function does not return a
|
|
|
|
value.
|
|
|
|
|
2022-06-09 12:23:40 +02:00
|
|
|
```js
|
|
|
|
test('top level test', (t) => {
|
|
|
|
// Make sure to return here as well if the test contains additional logic.
|
|
|
|
t.skip('this is skipped');
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2022-02-09 00:23:36 -05:00
|
|
|
### `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
|
2022-02-09 00:23:36 -05:00
|
|
|
-->
|
|
|
|
|
2022-12-19 19:35:57 +02:00
|
|
|
* `message` {string} Optional `TODO` message.
|
2022-02-09 00:23:36 -05:00
|
|
|
|
|
|
|
This function adds a `TODO` directive to the test's output. If `message` is
|
2022-12-19 19:35:57 +02:00
|
|
|
provided, it is included in the output. Calling `todo()` does not terminate
|
2022-02-09 00:23:36 -05:00
|
|
|
execution of the test function. This function does not return a value.
|
|
|
|
|
2022-06-09 12:23:40 +02:00
|
|
|
```js
|
|
|
|
test('top level test', (t) => {
|
|
|
|
// This test is marked as `TODO`
|
|
|
|
t.todo('this is a todo');
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2022-02-09 00:23:36 -05:00
|
|
|
### `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
|
2022-07-14 11:11:42 +03:00
|
|
|
changes:
|
2022-10-11 14:54:19 -05:00
|
|
|
- version:
|
|
|
|
- v18.8.0
|
|
|
|
- v16.18.0
|
2022-07-26 07:43:56 +03:00
|
|
|
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
|
2022-07-25 22:32:16 -04:00
|
|
|
pr-url: https://github.com/nodejs/node/pull/43505
|
|
|
|
description: Add a `timeout` option.
|
2022-02-09 00:23:36 -05:00
|
|
|
-->
|
|
|
|
|
|
|
|
* `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:
|
2023-01-31 18:50:59 +02:00
|
|
|
* `concurrency` {number|boolean|null} If a number is provided,
|
2023-04-24 17:38:12 +02:00
|
|
|
then that many tests would run in parallel within the application thread.
|
2023-01-31 18:50:59 +02:00
|
|
|
If `true`, it would run all subtests in parallel.
|
|
|
|
If `false`, it would only run one test at a time.
|
2022-02-09 00:23:36 -05:00
|
|
|
If unspecified, subtests inherit this value from their parent.
|
2023-01-31 18:50:59 +02:00
|
|
|
**Default:** `null`.
|
2022-04-04 10:14:49 -04:00
|
|
|
* `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`.
|
2022-07-26 13:52:51 +02:00
|
|
|
* `signal` {AbortSignal} Allows aborting an in-progress test.
|
2022-02-09 00:23:36 -05:00
|
|
|
* `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`.
|
2022-07-14 11:11:42 +03:00
|
|
|
* `timeout` {number} A number of milliseconds the test will fail after.
|
|
|
|
If unspecified, subtests inherit this value from their parent.
|
2022-07-20 17:40:43 +02:00
|
|
|
**Default:** `Infinity`.
|
2022-06-14 10:54:50 +03:00
|
|
|
* `fn` {Function|AsyncFunction} The function under test. The first argument
|
2022-02-09 00:23:36 -05:00
|
|
|
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.
|
|
|
|
* Returns: {Promise} Resolved with `undefined` once the test completes.
|
|
|
|
|
|
|
|
This function is used to create subtests under the current test. This function
|
|
|
|
behaves in the same fashion as the top level [`test()`][] function.
|
|
|
|
|
2022-06-09 12:23:40 +02:00
|
|
|
```js
|
|
|
|
test('top level test', async (t) => {
|
|
|
|
await t.test(
|
|
|
|
'This is a subtest',
|
|
|
|
{ only: false, skip: false, concurrency: 1, todo: false },
|
|
|
|
(t) => {
|
|
|
|
assert.ok('some relevant assertion here');
|
2022-11-17 08:19:12 -05:00
|
|
|
},
|
2022-06-09 12:23:40 +02:00
|
|
|
);
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2022-07-20 15:32:58 +03:00
|
|
|
## 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
|
2022-07-20 15:32:58 +03:00
|
|
|
-->
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
2022-06-30 10:14:35 +03:00
|
|
|
### `context.name`
|
|
|
|
|
|
|
|
<!-- YAML
|
2022-10-11 14:54:19 -05:00
|
|
|
added:
|
|
|
|
- v18.8.0
|
|
|
|
- v16.18.0
|
2022-06-30 10:14:35 +03:00
|
|
|
-->
|
|
|
|
|
2022-07-31 14:58:18 +02:00
|
|
|
The name of the suite.
|
2022-06-30 10:14:35 +03:00
|
|
|
|
2022-07-20 15:32:58 +03:00
|
|
|
### `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
|
2022-07-20 15:32:58 +03:00
|
|
|
-->
|
|
|
|
|
2022-07-26 13:52:51 +02:00
|
|
|
* {AbortSignal} Can be used to abort test subtasks when the test has been
|
|
|
|
aborted.
|
2022-07-20 15:32:58 +03:00
|
|
|
|
2022-02-09 00:23:36 -05:00
|
|
|
[TAP]: https://testanything.org/
|
2023-03-06 12:20:51 +02:00
|
|
|
[TTY]: tty.md
|
2023-01-07 21:16:54 -05:00
|
|
|
[`--experimental-test-coverage`]: cli.md#--experimental-test-coverage
|
2022-12-22 13:40:32 -08:00
|
|
|
[`--import`]: cli.md#--importmodule
|
2022-08-31 21:33:39 -04:00
|
|
|
[`--test-name-pattern`]: cli.md#--test-name-pattern
|
2022-04-04 10:14:49 -04:00
|
|
|
[`--test-only`]: cli.md#--test-only
|
2022-12-19 19:35:57 +02:00
|
|
|
[`--test-reporter-destination`]: cli.md#--test-reporter-destination
|
|
|
|
[`--test-reporter`]: cli.md#--test-reporter
|
2022-04-15 13:37:28 -04:00
|
|
|
[`--test`]: cli.md#--test
|
2022-04-04 18:36:40 -04:00
|
|
|
[`MockFunctionContext`]: #class-mockfunctioncontext
|
2023-06-22 01:01:52 -03:00
|
|
|
[`MockTimers`]: #class-mocktimers
|
2022-11-18 18:31:49 +09:00
|
|
|
[`MockTracker.method`]: #mockmethodobject-methodname-implementation-options
|
2022-04-04 18:36:40 -04:00
|
|
|
[`MockTracker`]: #class-mocktracker
|
2022-12-21 13:26:16 -05:00
|
|
|
[`NODE_V8_COVERAGE`]: cli.md#node_v8_coveragedir
|
2022-07-20 15:32:58 +03:00
|
|
|
[`SuiteContext`]: #class-suitecontext
|
2022-02-09 00:23:36 -05:00
|
|
|
[`TestContext`]: #class-testcontext
|
2022-08-15 12:12:11 +03:00
|
|
|
[`context.diagnostic`]: #contextdiagnosticmessage
|
|
|
|
[`context.skip`]: #contextskipmessage
|
|
|
|
[`context.todo`]: #contexttodomessage
|
2023-02-28 22:26:58 +02:00
|
|
|
[`describe()`]: #describename-options-fn
|
2023-06-22 15:18:23 +03:00
|
|
|
[`glob(7)`]: https://man7.org/linux/man-pages/man7/glob.7.html
|
2022-08-15 12:12:11 +03:00
|
|
|
[`run()`]: #runoptions
|
2022-02-09 00:23:36 -05:00
|
|
|
[`test()`]: #testname-options-fn
|
2022-06-14 10:54:50 +03:00
|
|
|
[describe options]: #describename-options-fn
|
|
|
|
[it options]: #testname-options-fn
|
2022-12-19 19:35:57 +02:00
|
|
|
[stream.compose]: stream.md#streamcomposestreams
|
2022-12-21 13:26:16 -05:00
|
|
|
[test reporters]: #test-reporters
|
2022-04-15 13:37:28 -04:00
|
|
|
[test runner execution model]: #test-runner-execution-model
|