Skip to content

Commit

Permalink
test: move shared module to test/common
Browse files Browse the repository at this point in the history
`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>
  • Loading branch information
Trott authored and marco-ippolito committed Aug 19, 2024
1 parent e326342 commit 77761af
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 20 deletions.
54 changes: 38 additions & 16 deletions test/common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

## Table of Contents
## Table of contents

* [ArrayStream module](#arraystream-module)
* [Benchmark module](#benchmark-module)
Expand All @@ -19,13 +19,14 @@ This directory contains modules used to test the Node.js implementation.
* [HTTP2 module](#http2-module)
* [Internet module](#internet-module)
* [ongc module](#ongc-module)
* [process-exit-code-test-cases module](#process-exit-code-test-cases-module)
* [Report module](#report-module)
* [tick module](#tick-module)
* [tmpdir module](#tmpdir-module)
* [UDP pair helper](#udp-pair-helper)
* [WPT module](#wpt-module)

## Benchmark Module
## Benchmark module

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

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

## Child Process Module
## Child Process module

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

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

## Common Module API
## Common module API

The `common` module is used by tests for consistency across repeated
tasks.
Expand Down Expand Up @@ -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
thread.

## ArrayStream Module
## ArrayStream module

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

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
require a particular action to be taken after a given number of completed
Expand Down Expand Up @@ -607,7 +608,7 @@ used to interact with the `node inspect` CLI. These functions are:
* `stepCommand()`
* `quit()`

## `DNS` Module
## `DNS` module

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

Expand Down Expand Up @@ -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'`,
global leak detection is disabled.

## Fixtures Module
## Fixtures module

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

## hijackstdio Module
## hijackstdio module

The `hijackstdio` module provides utility functions for temporarily redirecting
`stdout` and `stderr` output.
Expand Down Expand Up @@ -821,7 +822,7 @@ original state after calling [`hijackstdio.hijackStdErr()`][].
Restore the original `process.stdout.write()`. Used to restore `stdout` to its
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
frames for testing of HTTP/2 endpoints
Expand Down Expand Up @@ -940,7 +941,7 @@ upon initial establishment of a connection.
socket.write(http2.kClientMagic);
```

## Internet Module
## Internet module

The `common/internet` module provides utilities for working with
internet-related tests.
Expand Down Expand Up @@ -974,7 +975,7 @@ via `NODE_TEST_*` environment variables. For example, to configure
`internet.addresses.INET_HOST`, set the environment
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
module exports a single `onGC()` function.
Expand Down Expand Up @@ -1002,7 +1003,28 @@ a full `setImmediate()` invocation passes.
`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.

## 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
functionality.
Expand Down Expand Up @@ -1051,7 +1073,7 @@ into `targetExecutable` and sign it if necessary.
If `verifyWorkflow` is false (default) and any of the steps fails,
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
after a given number of event loop "ticks".
Expand All @@ -1061,7 +1083,7 @@ after a given number of event loop "ticks".
* `x` [\<number>][<number>] Number of event loop "ticks".
* `cb` [\<Function>][<Function>] A callback function.

## tmpdir Module
## tmpdir module

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

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

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

## WPT Module
## WPT module

### `harness`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function getTestCases(isWorker = false) {
function exitWithOneOnUncaught() {
process.exitCode = 99;
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
if (code !== 1 || process.exitCode !== 1) {
console.log('wrong code! expected 1 for uncaughtException');
Expand Down Expand Up @@ -113,7 +113,7 @@ function getTestCases(isWorker = false) {

function exitWithThrowInUncaughtHandler() {
process.on('uncaughtException', () => {
throw new Error('ok')
throw new Error('ok');
});
throw new Error('bad');
}
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-process-exit-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ require('../common');
const assert = require('assert');
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);

if (!process.argv[2]) {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-worker-exit-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const assert = require('assert');
const worker = require('worker_threads');
const { Worker, parentPort } = worker;

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

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

0 comments on commit 77761af

Please sign in to comment.