Skip to content

Commit 715462c

Browse files
committed
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`.
1 parent 852a1a6 commit 715462c

File tree

4 files changed

+42
-20
lines changed

4 files changed

+42
-20
lines changed

test/common/README.md

Lines changed: 38 additions & 16 deletions
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)
@@ -20,13 +20,14 @@ This directory contains modules used to test the Node.js implementation.
2020
* [HTTP2 module](#http2-module)
2121
* [Internet module](#internet-module)
2222
* [ongc module](#ongc-module)
23+
* [process-exit-code-test-cases module](#process-exit-code-test-cases-module)
2324
* [Report module](#report-module)
2425
* [tick module](#tick-module)
2526
* [tmpdir module](#tmpdir-module)
2627
* [UDP pair helper](#udp-pair-helper)
2728
* [WPT module](#wpt-module)
2829

29-
## Benchmark Module
30+
## Benchmark module
3031

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

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

39-
## Child Process Module
40+
## Child Process module
4041

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

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

83-
## Common Module API
84+
## Common module API
8485

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

492-
## ArrayStream Module
493+
## ArrayStream module
493494

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

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

507-
## Countdown Module
508+
## Countdown module
508509

509510
The `Countdown` module provides a simple countdown mechanism for tests that
510511
require a particular action to be taken after a given number of completed
@@ -608,7 +609,7 @@ used to interact with the `node inspect` CLI. These functions are:
608609
* `stepCommand()`
609610
* `quit()`
610611

611-
## `DNS` Module
612+
## `DNS` module
612613

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

@@ -707,7 +708,7 @@ A comma-separated list of variables names that are appended to the global
707708
variable allowlist. Alternatively, if `NODE_TEST_KNOWN_GLOBALS` is set to `'0'`,
708709
global leak detection is disabled.
709710

710-
## Fixtures Module
711+
## Fixtures module
711712

712713
The `common/fixtures` module provides convenience methods for working with
713714
files in the `test/fixtures` directory.
@@ -782,7 +783,7 @@ validateSnapshotNodes('TLSWRAP', [
782783
]);
783784
```
784785

785-
## hijackstdio Module
786+
## hijackstdio module
786787

787788
The `hijackstdio` module provides utility functions for temporarily redirecting
788789
`stdout` and `stderr` output.
@@ -830,7 +831,7 @@ original state after calling [`hijackstdio.hijackStdErr()`][].
830831
Restore the original `process.stdout.write()`. Used to restore `stdout` to its
831832
original state after calling [`hijackstdio.hijackStdOut()`][].
832833

833-
## HTTP/2 Module
834+
## HTTP/2 module
834835

835836
The http2.js module provides a handful of utilities for creating mock HTTP/2
836837
frames for testing of HTTP/2 endpoints
@@ -949,7 +950,7 @@ upon initial establishment of a connection.
949950
socket.write(http2.kClientMagic);
950951
```
951952

952-
## Internet Module
953+
## Internet module
953954

954955
The `common/internet` module provides utilities for working with
955956
internet-related tests.
@@ -983,7 +984,7 @@ via `NODE_TEST_*` environment variables. For example, to configure
983984
`internet.addresses.INET_HOST`, set the environment
984985
variable `NODE_TEST_INET_HOST` to a specified host.
985986

986-
## ongc Module
987+
## ongc module
987988

988989
The `ongc` module allows a garbage collection listener to be installed. The
989990
module exports a single `onGC()` function.
@@ -1011,7 +1012,28 @@ a full `setImmediate()` invocation passes.
10111012
`listener` is an object to make it easier to use a closure; the target object
10121013
should not be in scope when `listener.ongc()` is created.
10131014

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

10161038
The `report` module provides helper functions for testing diagnostic reporting
10171039
functionality.
@@ -1060,7 +1082,7 @@ into `targetExecutable` and sign it if necessary.
10601082
If `verifyWorkflow` is false (default) and any of the steps fails,
10611083
it skips the tests. Otherwise, an error is thrown.
10621084

1063-
## tick Module
1085+
## tick module
10641086

10651087
The `tick` module provides a helper function that can be used to call a callback
10661088
after a given number of event loop "ticks".
@@ -1070,7 +1092,7 @@ after a given number of event loop "ticks".
10701092
* `x` [\<number>][<number>] Number of event loop "ticks".
10711093
* `cb` [\<Function>][<Function>] A callback function.
10721094

1073-
## tmpdir Module
1095+
## tmpdir module
10741096

10751097
The `tmpdir` module supports the use of a temporary directory for testing.
10761098

@@ -1138,7 +1160,7 @@ is an `FakeUDPWrap` connected to the other side.
11381160

11391161
There is no difference between client or server side beyond their names.
11401162

1141-
## WPT Module
1163+
## WPT module
11421164

11431165
### `harness`
11441166

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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)