MCPcopy Index your code
hub / github.com/nodejs/node / getTestCases

Function getTestCases

test/common/process-exit-code-cases.js:5–137  ·  view source on GitHub ↗
(isWorker = false)

Source from the content-addressed store, hash-verified

3const assert = require('assert');
4
5function getTestCases(isWorker = false) {
6 const cases = [];
7 function exitsOnExitCodeSet() {
8 process.exitCode = 42;
9 process.on('exit', (code) => {
10 assert.strictEqual(process.exitCode, 42);
11 assert.strictEqual(code, 42);
12 });
13 }
14 cases.push({ func: exitsOnExitCodeSet, result: 42 });
15
16 function changesCodeViaExit() {
17 process.exitCode = 99;
18 process.on('exit', (code) => {
19 assert.strictEqual(process.exitCode, 42);
20 assert.strictEqual(code, 42);
21 });
22 process.exit(42);
23 }
24 cases.push({ func: changesCodeViaExit, result: 42 });
25
26 function changesCodeZeroExit() {
27 process.exitCode = 99;
28 process.on('exit', (code) => {
29 assert.strictEqual(process.exitCode, 0);
30 assert.strictEqual(code, 0);
31 });
32 process.exit(0);
33 }
34 cases.push({ func: changesCodeZeroExit, result: 0 });
35
36 function exitWithOneOnUncaught() {
37 process.exitCode = 99;
38 process.on('exit', (code) => {
39 // Cannot use assert because it will be uncaughtException -> 1 exit code
40 // that will render this test useless
41 if (code !== 1 || process.exitCode !== 1) {
42 console.log('wrong code! expected 1 for uncaughtException');
43 process.exit(99);
44 }
45 });
46 throw new Error('ok');
47 }
48 cases.push({
49 func: exitWithOneOnUncaught,
50 result: 1,
51 error: /^Error: ok$/,
52 });
53
54 function changeCodeInsideExit() {
55 process.exitCode = 95;
56 process.on('exit', (code) => {
57 assert.strictEqual(process.exitCode, 95);
58 assert.strictEqual(code, 95);
59 process.exitCode = 99;
60 });
61 }
62 cases.push({ func: changeCodeInsideExit, result: 99 });

Callers 2

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…