Skip to content
Myr

command.executableSubcommand.signals.test.js

This file

Path

tests/command.executableSubcommand.signals.test.js

62 lines · 2.2 KiB · JavaScript

Last changed by

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

History of this file

Take it

The walk stopped after 200 commits: lines older than b2842dc point at it.

update chinese readme (#1727)wenjiebefore adoptionb2842dc

lines 1–2why, one step back
1const childProcess = require('child_process');
2const path = require('path');

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

lines 3–4why, one step back
3const { test, describe } = require('node:test');
4const assert = require('node:assert/strict');

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 5why, one step back
5

Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1

line 6why, one step back
6const pmPath = path.join(__dirname, 'fixtures', 'pm');

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 7why, one step back
7

Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1

line 8why, one step back
8// Disabling some tests on Windows as:

update chinese readme (#1727)wenjiebefore adoptionb2842dc

lines 9–10why, one step back
9// "Windows does not support sending signals"
10// https://nodejs.org/api/process.html#process_signal_events

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 11–12why, one step back
11const describeOrSkipOnWindows =
12 process.platform === 'win32' ? describe.skip : describe;

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 13why, one step back
13

Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1

line 14why, one step back
14describeOrSkipOnWindows('signals', () => {

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

lines 15–20why, one step back
15 describe('signal forwarding tests', () => {
16 const signals = ['SIGINT', 'SIGHUP', 'SIGTERM', 'SIGUSR1', 'SIGUSR2'];17 for (const signal of signals) {18 test(`when program sent ${signal} then executableSubcommand sent signal too`, (t, done) => {19 // Spawn program. The listen subcommand waits for a signal and writes the name of the signal to stdout.20 const proc = childProcess.spawn(pmPath, ['listen'], {});

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 21why, one step back
21

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

lines 22–34why, one step back
22 let processOutput = '';
23 proc.stdout.on('data', (data) => {24 if (processOutput.length === 0) {25 // Send signal to program.26 proc.kill(`${signal}`);27 }28 processOutput += data.toString();29 });30 proc.on('close', (code) => {31 // Check the child subcommand received the signal too.32 assert.equal(processOutput, `Listening for signal...${signal}`);33 done();34 });

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 35why, one step back
35 });

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

lines 36–37why, one step back
36 }
37 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 38why, one step back
38

Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1

lines 39–40why, one step back
39 test('when executable subcommand sent signal then program exit code is non-zero', () => {
40 const { status } = childProcess.spawnSync(pmPath, ['terminate'], {});

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 41why, one step back
41 assert.equal(status > 0, true);

Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1

line 42why, one step back
42 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 43why, one step back
43

Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1

line 44why, one step back
44 test('when command has exitOverride and executable subcommand sent signal then exit code is non-zero', () => {

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 45–49why, one step back
45 const { status } = childProcess.spawnSync(
46 pmPath,47 ['exit-override', 'terminate'],48 {},49 );

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 50why, one step back
50 assert.equal(status > 0, true);

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 51why, one step back
51 });

Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1

lines 52–54why, one step back
52
53 // Not a signal test, but closely related code so adding here.54 test('when command has exitOverride and executable subcommand fails then program exit code is subcommand exit code', () => {

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 55–59why, one step back
55 const { status } = childProcess.spawnSync(
56 pmPath,57 ['exit-override', 'fail'],58 {},59 );

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 60why, one step back
60 assert.equal(status, 42);

Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1

lines 61–62why, one step back
61 });
62});