mirror of
https://github.com/nodejs/node.git
synced 2025-04-30 23:56:58 +00:00
test: move shared module to test/common
`test/fixtures/process-exit-code-cases.js` is a shared module and should be in `test/common` (so it gets linted, etc.) and documented in `test/common/README.md`. PR-URL: https://github.com/nodejs/node/pull/54042 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
This commit is contained in:
parent
3779c2ccd2
commit
dcccf9ab9b
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
This directory contains modules used to test the Node.js implementation.
|
This directory contains modules used to test the Node.js implementation.
|
||||||
|
|
||||||
## Table of Contents
|
## Table of contents
|
||||||
|
|
||||||
* [ArrayStream module](#arraystream-module)
|
* [ArrayStream module](#arraystream-module)
|
||||||
* [Benchmark module](#benchmark-module)
|
* [Benchmark module](#benchmark-module)
|
||||||
@ -19,13 +19,14 @@ This directory contains modules used to test the Node.js implementation.
|
|||||||
* [HTTP2 module](#http2-module)
|
* [HTTP2 module](#http2-module)
|
||||||
* [Internet module](#internet-module)
|
* [Internet module](#internet-module)
|
||||||
* [ongc module](#ongc-module)
|
* [ongc module](#ongc-module)
|
||||||
|
* [process-exit-code-test-cases module](#process-exit-code-test-cases-module)
|
||||||
* [Report module](#report-module)
|
* [Report module](#report-module)
|
||||||
* [tick module](#tick-module)
|
* [tick module](#tick-module)
|
||||||
* [tmpdir module](#tmpdir-module)
|
* [tmpdir module](#tmpdir-module)
|
||||||
* [UDP pair helper](#udp-pair-helper)
|
* [UDP pair helper](#udp-pair-helper)
|
||||||
* [WPT module](#wpt-module)
|
* [WPT module](#wpt-module)
|
||||||
|
|
||||||
## Benchmark Module
|
## Benchmark module
|
||||||
|
|
||||||
The `benchmark` module is used by tests to run benchmarks.
|
The `benchmark` module is used by tests to run benchmarks.
|
||||||
|
|
||||||
@ -35,7 +36,7 @@ The `benchmark` module is used by tests to run benchmarks.
|
|||||||
* `env` [\<Object>][<Object>] Environment variables to be applied during the
|
* `env` [\<Object>][<Object>] Environment variables to be applied during the
|
||||||
run.
|
run.
|
||||||
|
|
||||||
## Child Process Module
|
## Child Process module
|
||||||
|
|
||||||
The `child_process` module is used by tests that launch child processes.
|
The `child_process` module is used by tests that launch child processes.
|
||||||
|
|
||||||
@ -79,7 +80,7 @@ Similar to `expectSyncExit()` with the `status` expected to be 0 and
|
|||||||
Similar to `spawnSyncAndExitWithoutError()`, but with an additional
|
Similar to `spawnSyncAndExitWithoutError()`, but with an additional
|
||||||
`expectations` parameter.
|
`expectations` parameter.
|
||||||
|
|
||||||
## Common Module API
|
## Common module API
|
||||||
|
|
||||||
The `common` module is used by tests for consistency across repeated
|
The `common` module is used by tests for consistency across repeated
|
||||||
tasks.
|
tasks.
|
||||||
@ -488,7 +489,7 @@ was compiled with a pointer size smaller than 64 bits.
|
|||||||
Skip the rest of the tests in the current file when not running on a main
|
Skip the rest of the tests in the current file when not running on a main
|
||||||
thread.
|
thread.
|
||||||
|
|
||||||
## ArrayStream Module
|
## ArrayStream module
|
||||||
|
|
||||||
The `ArrayStream` module provides a simple `Stream` that pushes elements from
|
The `ArrayStream` module provides a simple `Stream` that pushes elements from
|
||||||
a given array.
|
a given array.
|
||||||
@ -503,7 +504,7 @@ stream.run(['a', 'b', 'c']);
|
|||||||
|
|
||||||
It can be used within tests as a simple mock stream.
|
It can be used within tests as a simple mock stream.
|
||||||
|
|
||||||
## Countdown Module
|
## Countdown module
|
||||||
|
|
||||||
The `Countdown` module provides a simple countdown mechanism for tests that
|
The `Countdown` module provides a simple countdown mechanism for tests that
|
||||||
require a particular action to be taken after a given number of completed
|
require a particular action to be taken after a given number of completed
|
||||||
@ -607,7 +608,7 @@ used to interact with the `node inspect` CLI. These functions are:
|
|||||||
* `stepCommand()`
|
* `stepCommand()`
|
||||||
* `quit()`
|
* `quit()`
|
||||||
|
|
||||||
## `DNS` Module
|
## `DNS` module
|
||||||
|
|
||||||
The `DNS` module provides utilities related to the `dns` built-in module.
|
The `DNS` module provides utilities related to the `dns` built-in module.
|
||||||
|
|
||||||
@ -698,7 +699,7 @@ A comma-separated list of variables names that are appended to the global
|
|||||||
variable allowlist. Alternatively, if `NODE_TEST_KNOWN_GLOBALS` is set to `'0'`,
|
variable allowlist. Alternatively, if `NODE_TEST_KNOWN_GLOBALS` is set to `'0'`,
|
||||||
global leak detection is disabled.
|
global leak detection is disabled.
|
||||||
|
|
||||||
## Fixtures Module
|
## Fixtures module
|
||||||
|
|
||||||
The `common/fixtures` module provides convenience methods for working with
|
The `common/fixtures` module provides convenience methods for working with
|
||||||
files in the `test/fixtures` directory.
|
files in the `test/fixtures` directory.
|
||||||
@ -773,7 +774,7 @@ validateSnapshotNodes('TLSWRAP', [
|
|||||||
]);
|
]);
|
||||||
```
|
```
|
||||||
|
|
||||||
## hijackstdio Module
|
## hijackstdio module
|
||||||
|
|
||||||
The `hijackstdio` module provides utility functions for temporarily redirecting
|
The `hijackstdio` module provides utility functions for temporarily redirecting
|
||||||
`stdout` and `stderr` output.
|
`stdout` and `stderr` output.
|
||||||
@ -821,7 +822,7 @@ original state after calling [`hijackstdio.hijackStdErr()`][].
|
|||||||
Restore the original `process.stdout.write()`. Used to restore `stdout` to its
|
Restore the original `process.stdout.write()`. Used to restore `stdout` to its
|
||||||
original state after calling [`hijackstdio.hijackStdOut()`][].
|
original state after calling [`hijackstdio.hijackStdOut()`][].
|
||||||
|
|
||||||
## HTTP/2 Module
|
## HTTP/2 module
|
||||||
|
|
||||||
The http2.js module provides a handful of utilities for creating mock HTTP/2
|
The http2.js module provides a handful of utilities for creating mock HTTP/2
|
||||||
frames for testing of HTTP/2 endpoints
|
frames for testing of HTTP/2 endpoints
|
||||||
@ -940,7 +941,7 @@ upon initial establishment of a connection.
|
|||||||
socket.write(http2.kClientMagic);
|
socket.write(http2.kClientMagic);
|
||||||
```
|
```
|
||||||
|
|
||||||
## Internet Module
|
## Internet module
|
||||||
|
|
||||||
The `common/internet` module provides utilities for working with
|
The `common/internet` module provides utilities for working with
|
||||||
internet-related tests.
|
internet-related tests.
|
||||||
@ -974,7 +975,7 @@ via `NODE_TEST_*` environment variables. For example, to configure
|
|||||||
`internet.addresses.INET_HOST`, set the environment
|
`internet.addresses.INET_HOST`, set the environment
|
||||||
variable `NODE_TEST_INET_HOST` to a specified host.
|
variable `NODE_TEST_INET_HOST` to a specified host.
|
||||||
|
|
||||||
## ongc Module
|
## ongc module
|
||||||
|
|
||||||
The `ongc` module allows a garbage collection listener to be installed. The
|
The `ongc` module allows a garbage collection listener to be installed. The
|
||||||
module exports a single `onGC()` function.
|
module exports a single `onGC()` function.
|
||||||
@ -1002,7 +1003,28 @@ a full `setImmediate()` invocation passes.
|
|||||||
`listener` is an object to make it easier to use a closure; the target object
|
`listener` is an object to make it easier to use a closure; the target object
|
||||||
should not be in scope when `listener.ongc()` is created.
|
should not be in scope when `listener.ongc()` is created.
|
||||||
|
|
||||||
## Report Module
|
## process-exit-code-test-cases module
|
||||||
|
|
||||||
|
The `process-exit-code-test-cases` module provides a set of shared test cases
|
||||||
|
for testing the exit codes of the `process` object. The test cases are shared
|
||||||
|
between `test/parallel/test-process-exit-code.js` and
|
||||||
|
`test/parallel/test-worker-exit-code.js`.
|
||||||
|
|
||||||
|
### `getTestCases(isWorker)`
|
||||||
|
|
||||||
|
* `isWorker` [\<boolean>][<boolean>]
|
||||||
|
* return [\<Array>][<Array>]
|
||||||
|
|
||||||
|
Returns an array of test cases for testing the exit codes of the `process`. Each
|
||||||
|
test case is an object with a `func` property that is a function that runs the
|
||||||
|
test case, a `result` property that is the expected exit code, and sometimes an
|
||||||
|
`error` property that is a regular expression that the error message should
|
||||||
|
match when the test case is run in a worker thread.
|
||||||
|
|
||||||
|
The `isWorker` parameter is used to adjust the test cases for worker threads.
|
||||||
|
The default value is `false`.
|
||||||
|
|
||||||
|
## Report module
|
||||||
|
|
||||||
The `report` module provides helper functions for testing diagnostic reporting
|
The `report` module provides helper functions for testing diagnostic reporting
|
||||||
functionality.
|
functionality.
|
||||||
@ -1051,7 +1073,7 @@ into `targetExecutable` and sign it if necessary.
|
|||||||
If `verifyWorkflow` is false (default) and any of the steps fails,
|
If `verifyWorkflow` is false (default) and any of the steps fails,
|
||||||
it skips the tests. Otherwise, an error is thrown.
|
it skips the tests. Otherwise, an error is thrown.
|
||||||
|
|
||||||
## tick Module
|
## tick module
|
||||||
|
|
||||||
The `tick` module provides a helper function that can be used to call a callback
|
The `tick` module provides a helper function that can be used to call a callback
|
||||||
after a given number of event loop "ticks".
|
after a given number of event loop "ticks".
|
||||||
@ -1061,7 +1083,7 @@ after a given number of event loop "ticks".
|
|||||||
* `x` [\<number>][<number>] Number of event loop "ticks".
|
* `x` [\<number>][<number>] Number of event loop "ticks".
|
||||||
* `cb` [\<Function>][<Function>] A callback function.
|
* `cb` [\<Function>][<Function>] A callback function.
|
||||||
|
|
||||||
## tmpdir Module
|
## tmpdir module
|
||||||
|
|
||||||
The `tmpdir` module supports the use of a temporary directory for testing.
|
The `tmpdir` module supports the use of a temporary directory for testing.
|
||||||
|
|
||||||
@ -1129,7 +1151,7 @@ is an `FakeUDPWrap` connected to the other side.
|
|||||||
|
|
||||||
There is no difference between client or server side beyond their names.
|
There is no difference between client or server side beyond their names.
|
||||||
|
|
||||||
## WPT Module
|
## WPT module
|
||||||
|
|
||||||
### `harness`
|
### `harness`
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ function getTestCases(isWorker = false) {
|
|||||||
function exitWithOneOnUncaught() {
|
function exitWithOneOnUncaught() {
|
||||||
process.exitCode = 99;
|
process.exitCode = 99;
|
||||||
process.on('exit', (code) => {
|
process.on('exit', (code) => {
|
||||||
// cannot use assert because it will be uncaughtException -> 1 exit code
|
// Cannot use assert because it will be uncaughtException -> 1 exit code
|
||||||
// that will render this test useless
|
// that will render this test useless
|
||||||
if (code !== 1 || process.exitCode !== 1) {
|
if (code !== 1 || process.exitCode !== 1) {
|
||||||
console.log('wrong code! expected 1 for uncaughtException');
|
console.log('wrong code! expected 1 for uncaughtException');
|
||||||
@ -113,7 +113,7 @@ function getTestCases(isWorker = false) {
|
|||||||
|
|
||||||
function exitWithThrowInUncaughtHandler() {
|
function exitWithThrowInUncaughtHandler() {
|
||||||
process.on('uncaughtException', () => {
|
process.on('uncaughtException', () => {
|
||||||
throw new Error('ok')
|
throw new Error('ok');
|
||||||
});
|
});
|
||||||
throw new Error('bad');
|
throw new Error('bad');
|
||||||
}
|
}
|
@ -24,7 +24,7 @@ require('../common');
|
|||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const debug = require('util').debuglog('test');
|
const debug = require('util').debuglog('test');
|
||||||
|
|
||||||
const { getTestCases } = require('../fixtures/process-exit-code-cases');
|
const { getTestCases } = require('../common/process-exit-code-cases');
|
||||||
const testCases = getTestCases(false);
|
const testCases = getTestCases(false);
|
||||||
|
|
||||||
if (!process.argv[2]) {
|
if (!process.argv[2]) {
|
||||||
|
@ -8,7 +8,7 @@ const assert = require('assert');
|
|||||||
const worker = require('worker_threads');
|
const worker = require('worker_threads');
|
||||||
const { Worker, parentPort } = worker;
|
const { Worker, parentPort } = worker;
|
||||||
|
|
||||||
const { getTestCases } = require('../fixtures/process-exit-code-cases');
|
const { getTestCases } = require('../common/process-exit-code-cases');
|
||||||
const testCases = getTestCases(true);
|
const testCases = getTestCases(true);
|
||||||
|
|
||||||
// Do not use isMainThread so that this test itself can be run inside a Worker.
|
// Do not use isMainThread so that this test itself can be run inside a Worker.
|
||||||
|
Loading…
Reference in New Issue
Block a user