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
|
|
|
|
|
|
|
> Stability: 1 - Experimental
|
|
|
|
|
|
|
|
<!-- source_link=lib/test.js -->
|
|
|
|
|
|
|
|
The `node:test` module facilitates the creation of JavaScript tests that
|
|
|
|
report results in [TAP][] format. To access it:
|
|
|
|
|
|
|
|
```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'));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
As a test file executes, TAP is written to the standard output of the Node.js
|
|
|
|
process. This output can be interpreted by any test harness that understands
|
|
|
|
the TAP format. If any tests fail, the process exit code is set to `1`.
|
|
|
|
|
|
|
|
## 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
|
|
|
|
calling the test context's `skip()` method. Both of these options support
|
|
|
|
including a message that is displayed in the TAP output as shown in the
|
|
|
|
following example.
|
|
|
|
|
|
|
|
```js
|
|
|
|
// The skip option is used, but no message is provided.
|
|
|
|
test('skip option', { skip: true }, (t) => {
|
|
|
|
// This code is never executed.
|
|
|
|
});
|
|
|
|
|
|
|
|
// The skip option is used, and a message is provided.
|
|
|
|
test('skip option with message', { skip: 'this is skipped' }, (t) => {
|
|
|
|
// This code is never executed.
|
|
|
|
});
|
|
|
|
|
|
|
|
test('skip() method', (t) => {
|
|
|
|
// Make sure to return here as well if the test contains additional logic.
|
|
|
|
t.skip();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('skip() method with message', (t) => {
|
|
|
|
// Make sure to return here as well if the test contains additional logic.
|
|
|
|
t.skip('this is skipped');
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
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.
|
|
|
|
`it` is an alias for `test`, except there is no test context passed,
|
2022-07-31 14:58:18 +02:00
|
|
|
since nesting is done using suites.
|
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
|
|
|
|
|
|
|
|
Once a test function finishes executing, the TAP results are output as quickly
|
|
|
|
as possible while maintaining the order of the tests. However, it is possible
|
|
|
|
for the test function to generate asynchronous activity that outlives the test
|
|
|
|
itself. The test runner handles this type of activity, but does not delay the
|
|
|
|
reporting of test results in order to accommodate it.
|
|
|
|
|
|
|
|
In the following example, a test completes with two `setImmediate()`
|
|
|
|
operations still outstanding. The first `setImmediate()` attempts to create a
|
|
|
|
new subtest. Because the parent test has already finished and output its
|
|
|
|
results, the new subtest is immediately marked as failed, and reported in the
|
|
|
|
top level of the file's TAP output.
|
|
|
|
|
|
|
|
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
|
|
|
|
warnings in the top level of the file's TAP output.
|
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-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
|
|
|
|
```
|
|
|
|
|
|
|
|
By default, Node.js will recursively search the current directory for
|
|
|
|
JavaScript source files matching a specific naming convention. Matching files
|
|
|
|
are executed as test files. More information on the expected test file naming
|
|
|
|
convention and behavior can be found in the [test runner execution model][]
|
|
|
|
section.
|
|
|
|
|
|
|
|
Alternatively, one or more paths can be provided as the final argument(s) to
|
|
|
|
the Node.js command, as shown below.
|
|
|
|
|
|
|
|
```bash
|
|
|
|
node --test test1.js test2.mjs custom_test_dir/
|
|
|
|
```
|
|
|
|
|
|
|
|
In this example, the test runner will execute the files `test1.js` and
|
|
|
|
`test2.mjs`. The test runner will also recursively search the
|
|
|
|
`custom_test_dir/` directory for test files to execute.
|
|
|
|
|
|
|
|
### Test runner execution model
|
|
|
|
|
|
|
|
When searching for test files to execute, the test runner behaves as follows:
|
|
|
|
|
|
|
|
* Any files explicitly provided by the user are executed.
|
|
|
|
* If the user did not explicitly specify any paths, the current working
|
|
|
|
directory is recursively searched for files as specified in the following
|
|
|
|
steps.
|
|
|
|
* `node_modules` directories are skipped unless explicitly provided by the
|
|
|
|
user.
|
|
|
|
* If a directory named `test` is encountered, the test runner will search it
|
|
|
|
recursively for all all `.js`, `.cjs`, and `.mjs` files. All of these files
|
|
|
|
are treated as test files, and do not need to match the specific naming
|
|
|
|
convention detailed below. This is to accommodate projects that place all of
|
|
|
|
their tests in a single `test` directory.
|
|
|
|
* In all other directories, `.js`, `.cjs`, and `.mjs` files matching the
|
|
|
|
following patterns are treated as test files:
|
|
|
|
* `^test$` - Files whose basename is the string `'test'`. Examples:
|
|
|
|
`test.js`, `test.cjs`, `test.mjs`.
|
|
|
|
* `^test-.+` - Files whose basename starts with the string `'test-'`
|
|
|
|
followed by one or more characters. Examples: `test-example.js`,
|
|
|
|
`test-another-example.mjs`.
|
|
|
|
* `.+[\.\-\_]test$` - Files whose basename ends with `.test`, `-test`, or
|
|
|
|
`_test`, preceded by one or more characters. Examples: `example.test.js`,
|
|
|
|
`example-test.cjs`, `example_test.mjs`.
|
|
|
|
* Other file types understood by Node.js such as `.node` and `.json` are not
|
|
|
|
automatically executed by the test runner, but are supported if explicitly
|
|
|
|
provided on the command line.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2022-08-15 12:12:11 +03:00
|
|
|
## `run([options])`
|
|
|
|
|
|
|
|
<!-- YAML
|
2022-09-05 13:57:41 -03:00
|
|
|
added: v18.9.0
|
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,
|
|
|
|
then that many files would run in parallel.
|
|
|
|
If truthy, it would run (number of cpu cores - 1)
|
|
|
|
files in parallel.
|
|
|
|
If falsy, it would only run one file at a time.
|
|
|
|
If unspecified, subtests inherit this value from their parent.
|
|
|
|
**Default:** `true`.
|
|
|
|
* `files`: {Array} An array containing the list of files to run.
|
|
|
|
**Default** matching files from [test runner execution model][].
|
|
|
|
* `signal` {AbortSignal} Allows aborting an in-progress test execution.
|
|
|
|
* `timeout` {number} A number of milliseconds the test execution will
|
|
|
|
fail after.
|
|
|
|
If unspecified, subtests inherit this value from their parent.
|
|
|
|
**Default:** `Infinity`.
|
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`.
|
2022-08-15 12:12:11 +03:00
|
|
|
* Returns: {TapStream}
|
|
|
|
|
|
|
|
```js
|
|
|
|
run({ files: [path.resolve('./tests/test.js')] })
|
|
|
|
.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:
|
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,
|
|
|
|
then that many tests would run in parallel.
|
|
|
|
If truthy, it would run (number of cpu cores - 1)
|
|
|
|
tests in parallel.
|
|
|
|
For subtests, it will be `Infinity` tests in parallel.
|
|
|
|
If falsy, 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.
|
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.
|
|
|
|
* Returns: {Promise} Resolved with `undefined` once the test completes.
|
|
|
|
|
|
|
|
The `test()` function is the value imported from the `test` module. Each
|
|
|
|
invocation of this function results in the creation of a test point in the TAP
|
|
|
|
output.
|
|
|
|
|
|
|
|
The `TestContext` object passed to the `fn` argument can be used to perform
|
|
|
|
actions related to the current test. Examples include skipping the test, adding
|
|
|
|
additional TAP diagnostic information, or creating subtests.
|
|
|
|
|
|
|
|
`test()` returns a `Promise` that resolves once the test completes. 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.
|
|
|
|
|
|
|
|
```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.
|
|
|
|
|
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.
|
|
|
|
* Returns: `undefined`.
|
|
|
|
|
|
|
|
The `describe()` function imported from the `node:test` module. Each
|
|
|
|
invocation of this function results in the creation of a Subtest
|
|
|
|
and a test point in the TAP output.
|
|
|
|
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].
|
|
|
|
|
|
|
|
## `it([name][, options][, fn])`
|
|
|
|
|
|
|
|
* `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 suite.
|
|
|
|
supports the same options as `test([name][, options][, fn])`.
|
|
|
|
* `fn` {Function|AsyncFunction} The function under test.
|
|
|
|
If the test uses callbacks, the callback function is passed as an argument.
|
|
|
|
**Default:** A no-op function.
|
|
|
|
* Returns: `undefined`.
|
|
|
|
|
|
|
|
The `it()` function is the value imported from the `node:test` module.
|
|
|
|
Each invocation of this function results in the creation of a test point in the
|
|
|
|
TAP output.
|
|
|
|
|
|
|
|
## `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].
|
|
|
|
|
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 () => {
|
2022-08-23 11:21:10 +03:00
|
|
|
beforeEach(() => t.diagnostic('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 () => {
|
2022-08-23 11:21:10 +03:00
|
|
|
afterEach(() => t.diagnostic('about to run 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
|
|
|
|
added: REPLACEME
|
|
|
|
-->
|
|
|
|
|
|
|
|
The `MockFunctionContext` class is used to inspect or manipulate the behavior of
|
|
|
|
mocks created via the [`MockTracker`][] APIs.
|
|
|
|
|
|
|
|
### `ctx.calls`
|
|
|
|
|
|
|
|
<!-- YAML
|
|
|
|
added: REPLACEME
|
|
|
|
-->
|
|
|
|
|
|
|
|
* {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
|
|
|
|
added: REPLACEME
|
|
|
|
-->
|
|
|
|
|
|
|
|
* 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
|
|
|
|
added: REPLACEME
|
|
|
|
-->
|
|
|
|
|
|
|
|
* `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
|
|
|
|
added: REPLACEME
|
|
|
|
-->
|
|
|
|
|
|
|
|
* `implementation` {Function|AsyncFunction} The function to be used as the
|
|
|
|
mock's implementation for the invocation number specified by `onCall`.
|
|
|
|
* `onCall` {integer} The invocation number that will use `implementation`. If
|
|
|
|
the specified invocation has already occurred then an exception is thrown.
|
|
|
|
**Default:** The number of the next invocation.
|
|
|
|
|
|
|
|
This function is used to change the behavior of an existing mock for a single
|
|
|
|
invocation. Once invocation `onCall` has occurred, the mock will revert to
|
|
|
|
whatever behavior it would have used had `mockImplementationOnce()` not been
|
|
|
|
called.
|
|
|
|
|
|
|
|
The following example creates a mock function using `t.mock.fn()`, calls the
|
|
|
|
mock function, changes the mock implementation to a different function for the
|
|
|
|
next invocation, and then resumes its previous behavior.
|
|
|
|
|
|
|
|
```js
|
|
|
|
test('changes a mock behavior once', (t) => {
|
|
|
|
let cnt = 0;
|
|
|
|
|
|
|
|
function addOne() {
|
|
|
|
cnt++;
|
|
|
|
return cnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
function addTwo() {
|
|
|
|
cnt += 2;
|
|
|
|
return cnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
const fn = t.mock.fn(addOne);
|
|
|
|
|
|
|
|
assert.strictEqual(fn(), 1);
|
|
|
|
fn.mock.mockImplementationOnce(addTwo);
|
|
|
|
assert.strictEqual(fn(), 3);
|
|
|
|
assert.strictEqual(fn(), 4);
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
### `ctx.restore()`
|
|
|
|
|
|
|
|
<!-- YAML
|
|
|
|
added: REPLACEME
|
|
|
|
-->
|
|
|
|
|
|
|
|
Resets the implementation of the mock function to its original behavior. The
|
|
|
|
mock can still be used after calling this function.
|
|
|
|
|
|
|
|
## Class: `MockTracker`
|
|
|
|
|
|
|
|
<!-- YAML
|
|
|
|
added: REPLACEME
|
|
|
|
-->
|
|
|
|
|
|
|
|
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
|
|
|
|
added: REPLACEME
|
|
|
|
-->
|
|
|
|
|
|
|
|
* `original` {Function|AsyncFunction} An optional function to create a mock on.
|
|
|
|
**Default:** A no-op function.
|
|
|
|
* `implementation` {Function|AsyncFunction} An optional function used as the
|
|
|
|
mock implementation for `original`. This is useful for creating mocks that
|
|
|
|
exhibit one behavior for a specified number of calls and then restore the
|
|
|
|
behavior of `original`. **Default:** The function specified by `original`.
|
|
|
|
* `options` {Object} Optional configuration options for the mock function. The
|
|
|
|
following properties are supported:
|
|
|
|
* `times` {integer} The number of times that the mock will use the behavior of
|
|
|
|
`implementation`. Once the mock function has been called `times` times, it
|
|
|
|
will automatically restore the behavior of `original`. This value must be an
|
|
|
|
integer greater than zero. **Default:** `Infinity`.
|
|
|
|
* Returns: {Proxy} The mocked function. The mocked function contains a special
|
|
|
|
`mock` property, which is an instance of [`MockFunctionContext`][], and can
|
|
|
|
be used for inspecting and changing the behavior of the mocked function.
|
|
|
|
|
|
|
|
This function is used to create a mock function.
|
|
|
|
|
|
|
|
The following example creates a mock function that increments a counter by one
|
|
|
|
on each invocation. The `times` option is used to modify the mock behavior such
|
|
|
|
that the first two invocations add two to the counter instead of one.
|
|
|
|
|
|
|
|
```js
|
|
|
|
test('mocks a counting function', (t) => {
|
|
|
|
let cnt = 0;
|
|
|
|
|
|
|
|
function addOne() {
|
|
|
|
cnt++;
|
|
|
|
return cnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
function addTwo() {
|
|
|
|
cnt += 2;
|
|
|
|
return cnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
const fn = t.mock.fn(addOne, addTwo, { times: 2 });
|
|
|
|
|
|
|
|
assert.strictEqual(fn(), 2);
|
|
|
|
assert.strictEqual(fn(), 4);
|
|
|
|
assert.strictEqual(fn(), 5);
|
|
|
|
assert.strictEqual(fn(), 6);
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
### `mock.method(object, methodName[, implementation][, options])`
|
|
|
|
|
|
|
|
<!-- YAML
|
|
|
|
added: REPLACEME
|
|
|
|
-->
|
|
|
|
|
|
|
|
* `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
|
|
|
|
added: REPLACEME
|
|
|
|
-->
|
|
|
|
|
|
|
|
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
|
|
|
|
added: REPLACEME
|
|
|
|
-->
|
|
|
|
|
|
|
|
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-08-15 12:12:11 +03:00
|
|
|
## Class: `TapStream`
|
|
|
|
|
|
|
|
<!-- YAML
|
2022-09-05 13:57:41 -03:00
|
|
|
added: v18.9.0
|
2022-08-15 12:12:11 +03:00
|
|
|
-->
|
|
|
|
|
|
|
|
* Extends {ReadableStream}
|
|
|
|
|
|
|
|
A successful call to [`run()`][] method will return a new {TapStream}
|
|
|
|
object, streaming a [TAP][] output
|
|
|
|
`TapStream` will emit events, in the order of the tests definition
|
|
|
|
|
|
|
|
### Event: `'test:diagnostic'`
|
|
|
|
|
|
|
|
* `message` {string} The diagnostic message.
|
|
|
|
|
|
|
|
Emitted when [`context.diagnostic`][] is called.
|
|
|
|
|
|
|
|
### Event: `'test:fail'`
|
|
|
|
|
|
|
|
* `data` {Object}
|
|
|
|
* `duration` {number} The test duration.
|
|
|
|
* `error` {Error} The failure casing test to fail.
|
|
|
|
* `name` {string} The test name.
|
|
|
|
* `testNumber` {number} The ordinal number of the test.
|
|
|
|
* `todo` {string|undefined} Present if [`context.todo`][] is called
|
|
|
|
* `skip` {string|undefined} Present if [`context.skip`][] is called
|
|
|
|
|
|
|
|
Emitted when a test fails.
|
|
|
|
|
|
|
|
### Event: `'test:pass'`
|
|
|
|
|
|
|
|
* `data` {Object}
|
|
|
|
* `duration` {number} The test duration.
|
|
|
|
* `name` {string} The test name.
|
|
|
|
* `testNumber` {number} The ordinal number of the test.
|
|
|
|
* `todo` {string|undefined} Present if [`context.todo`][] is called
|
|
|
|
* `skip` {string|undefined} Present if [`context.skip`][] is called
|
|
|
|
|
|
|
|
Emitted when a test passes.
|
|
|
|
|
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
|
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.
|
|
|
|
|
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-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-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
|
|
|
-->
|
|
|
|
|
|
|
|
* `message` {string} Message to be displayed as a TAP diagnostic.
|
|
|
|
|
|
|
|
This function is used to write TAP diagnostics to the output. Any diagnostic
|
|
|
|
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
|
|
|
-->
|
|
|
|
|
|
|
|
* `message` {string} Optional skip message to be displayed in TAP output.
|
|
|
|
|
|
|
|
This function causes the test's output to indicate the test as skipped. If
|
|
|
|
`message` is provided, it is included in the TAP output. Calling `skip()` does
|
|
|
|
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
|
|
|
-->
|
|
|
|
|
|
|
|
* `message` {string} Optional `TODO` message to be displayed in TAP output.
|
|
|
|
|
|
|
|
This function adds a `TODO` directive to the test's output. If `message` is
|
|
|
|
provided, it is included in the TAP output. Calling `todo()` does 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) => {
|
|
|
|
// 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:
|
|
|
|
* `concurrency` {number} The number of tests that can be run at the same time.
|
|
|
|
If unspecified, subtests inherit this value from their parent.
|
|
|
|
**Default:** `1`.
|
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-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/
|
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-04-15 13:37:28 -04:00
|
|
|
[`--test`]: cli.md#--test
|
2022-04-04 18:36:40 -04:00
|
|
|
[`MockFunctionContext`]: #class-mockfunctioncontext
|
|
|
|
[`MockTracker`]: #class-mocktracker
|
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
|
|
|
|
[`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-04-15 13:37:28 -04:00
|
|
|
[test runner execution model]: #test-runner-execution-model
|