Skip to content

Commit b2a465e

Browse files
Trotttargos
authored andcommitted
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: #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>
1 parent c535ade commit b2a465e

File tree

4 files changed

+42
-20
lines changed

4 files changed

+42
-20
lines changed

test/common/README.md

+38-16
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This directory contains modules used to test the Node.js implementation.
44

5-
## Table of Contents
5+
## Table of contents
66

77
* [ArrayStream module](#arraystream-module)
88
* [Benchmark module](#benchmark-module)
@@ -19,13 +19,14 @@ This directory contains modules used to test the Node.js implementation.
1919
* [HTTP2 module](#http2-module)
2020
* [Internet module](#internet-module)
2121
* [ongc module](#ongc-module)
22+
* [process-exit-code-test-cases module](#process-exit-code-test-cases-module)
2223
* [Report module](#report-module)
2324
* [tick module](#tick-module)
2425
* [tmpdir module](#tmpdir-module)
2526
* [UDP pair helper](#udp-pair-helper)
2627
* [WPT module](#wpt-module)
2728

28-
## Benchmark Module
29+
## Benchmark module
2930

3031
The `benchmark` module is used by tests to run benchmarks.
3132

@@ -35,7 +36,7 @@ The `benchmark` module is used by tests to run benchmarks.
3536
* `env` [\<Object>][<Object>] Environment variables to be applied during the
3637
run.
3738

38-
## Child Process Module
39+
## Child Process module
3940

4041
The `child_process` module is used by tests that launch child processes.
4142

@@ -79,7 +80,7 @@ Similar to `expectSyncExit()` with the `status` expected to be 0 and
7980
Similar to `spawnSyncAndExitWithoutError()`, but with an additional
8081
`expectations` parameter.
8182

82-
## Common Module API
83+
## Common module API
8384

8485
The `common` module is used by tests for consistency across repeated
8586
tasks.
@@ -488,7 +489,7 @@ was compiled with a pointer size smaller than 64 bits.
488489
Skip the rest of the tests in the current file when not running on a main
489490
thread.
490491

491-
## ArrayStream Module
492+
## ArrayStream module
492493

493494
The `ArrayStream` module provides a simple `Stream` that pushes elements from
494495
a given array.
@@ -503,7 +504,7 @@ stream.run(['a', 'b', 'c']);
503504

504505
It can be used within tests as a simple mock stream.
505506

506-
## Countdown Module
507+
## Countdown module
507508

508509
The `Countdown` module provides a simple countdown mechanism for tests that
509510
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:
607608
* `stepCommand()`
608609
* `quit()`
609610

610-
## `DNS` Module
611+
## `DNS` module
611612

612613
The `DNS` module provides utilities related to the `dns` built-in module.
613614

@@ -698,7 +699,7 @@ A comma-separated list of variables names that are appended to the global
698699
variable allowlist. Alternatively, if `NODE_TEST_KNOWN_GLOBALS` is set to `'0'`,
699700
global leak detection is disabled.
700701

701-
## Fixtures Module
702+
## Fixtures module
702703

703704
The `common/fixtures` module provides convenience methods for working with
704705
files in the `test/fixtures` directory.
@@ -773,7 +774,7 @@ validateSnapshotNodes('TLSWRAP', [
773774
]);
774775
```
775776

776-
## hijackstdio Module
777+
## hijackstdio module
777778

778779
The `hijackstdio` module provides utility functions for temporarily redirecting
779780
`stdout` and `stderr` output.
@@ -821,7 +822,7 @@ original state after calling [`hijackstdio.hijackStdErr()`][].
821822
Restore the original `process.stdout.write()`. Used to restore `stdout` to its
822823
original state after calling [`hijackstdio.hijackStdOut()`][].
823824

824-
## HTTP/2 Module
825+
## HTTP/2 module
825826

826827
The http2.js module provides a handful of utilities for creating mock HTTP/2
827828
frames for testing of HTTP/2 endpoints
@@ -940,7 +941,7 @@ upon initial establishment of a connection.
940941
socket.write(http2.kClientMagic);
941942
```
942943

943-
## Internet Module
944+
## Internet module
944945

945946
The `common/internet` module provides utilities for working with
946947
internet-related tests.
@@ -974,7 +975,7 @@ via `NODE_TEST_*` environment variables. For example, to configure
974975
`internet.addresses.INET_HOST`, set the environment
975976
variable `NODE_TEST_INET_HOST` to a specified host.
976977

977-
## ongc Module
978+
## ongc module
978979

979980
The `ongc` module allows a garbage collection listener to be installed. The
980981
module exports a single `onGC()` function.
@@ -1002,7 +1003,28 @@ a full `setImmediate()` invocation passes.
10021003
`listener` is an object to make it easier to use a closure; the target object
10031004
should not be in scope when `listener.ongc()` is created.
10041005

1005-
## Report Module
1006+
## process-exit-code-test-cases module
1007+
1008+
The `process-exit-code-test-cases` module provides a set of shared test cases
1009+
for testing the exit codes of the `process` object. The test cases are shared
1010+
between `test/parallel/test-process-exit-code.js` and
1011+
`test/parallel/test-worker-exit-code.js`.
1012+
1013+
### `getTestCases(isWorker)`
1014+
1015+
* `isWorker` [\<boolean>][<boolean>]
1016+
* return [\<Array>][<Array>]
1017+
1018+
Returns an array of test cases for testing the exit codes of the `process`. Each
1019+
test case is an object with a `func` property that is a function that runs the
1020+
test case, a `result` property that is the expected exit code, and sometimes an
1021+
`error` property that is a regular expression that the error message should
1022+
match when the test case is run in a worker thread.
1023+
1024+
The `isWorker` parameter is used to adjust the test cases for worker threads.
1025+
The default value is `false`.
1026+
1027+
## Report module
10061028

10071029
The `report` module provides helper functions for testing diagnostic reporting
10081030
functionality.
@@ -1051,7 +1073,7 @@ into `targetExecutable` and sign it if necessary.
10511073
If `verifyWorkflow` is false (default) and any of the steps fails,
10521074
it skips the tests. Otherwise, an error is thrown.
10531075

1054-
## tick Module
1076+
## tick module
10551077

10561078
The `tick` module provides a helper function that can be used to call a callback
10571079
after a given number of event loop "ticks".
@@ -1061,7 +1083,7 @@ after a given number of event loop "ticks".
10611083
* `x` [\<number>][<number>] Number of event loop "ticks".
10621084
* `cb` [\<Function>][<Function>] A callback function.
10631085

1064-
## tmpdir Module
1086+
## tmpdir module
10651087

10661088
The `tmpdir` module supports the use of a temporary directory for testing.
10671089

@@ -1129,7 +1151,7 @@ is an `FakeUDPWrap` connected to the other side.
11291151

11301152
There is no difference between client or server side beyond their names.
11311153

1132-
## WPT Module
1154+
## WPT module
11331155

11341156
### `harness`
11351157

test/fixtures/process-exit-code-cases.js test/common/process-exit-code-cases.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function getTestCases(isWorker = false) {
3636
function exitWithOneOnUncaught() {
3737
process.exitCode = 99;
3838
process.on('exit', (code) => {
39-
// cannot use assert because it will be uncaughtException -> 1 exit code
39+
// Cannot use assert because it will be uncaughtException -> 1 exit code
4040
// that will render this test useless
4141
if (code !== 1 || process.exitCode !== 1) {
4242
console.log('wrong code! expected 1 for uncaughtException');
@@ -113,7 +113,7 @@ function getTestCases(isWorker = false) {
113113

114114
function exitWithThrowInUncaughtHandler() {
115115
process.on('uncaughtException', () => {
116-
throw new Error('ok')
116+
throw new Error('ok');
117117
});
118118
throw new Error('bad');
119119
}

test/parallel/test-process-exit-code.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ require('../common');
2424
const assert = require('assert');
2525
const debug = require('util').debuglog('test');
2626

27-
const { getTestCases } = require('../fixtures/process-exit-code-cases');
27+
const { getTestCases } = require('../common/process-exit-code-cases');
2828
const testCases = getTestCases(false);
2929

3030
if (!process.argv[2]) {

test/parallel/test-worker-exit-code.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const assert = require('assert');
88
const worker = require('worker_threads');
99
const { Worker, parentPort } = worker;
1010

11-
const { getTestCases } = require('../fixtures/process-exit-code-cases');
11+
const { getTestCases } = require('../common/process-exit-code-cases');
1212
const testCases = getTestCases(true);
1313

1414
// Do not use isMainThread so that this test itself can be run inside a Worker.

0 commit comments

Comments
 (0)