abort.js
This file
Path
test/pipe/abort.js
199 lines · 7.2 KiB · JavaScript
Last changed by
Fix wrong-typed options and arguments being silently ignored or coercedSindre Sorhusbefore adoptionb57d643
History of this fileTake it
The walk stopped after 200 commits: lines older than 9f65b86 point at it.
TweaksSindre Sorhusbefore adoption698a1b8
line 1why, one step back1import assert from 'node:assert/strict';100% test coverage (#1018)ehmickybefore adoption9f65b86
line 2why, one step back2import {once} from 'node:events';Fix wrong-typed options and arguments being silently ignored or coercedSindre Sorhusbefore adoptionb57d643
line 3why, one step back3import {setTimeout} from 'node:timers/promises';TweaksSindre Sorhusbefore adoption698a1b8
lines 4–5why, one step back4import test from 'node:test';5import {assertRejects, assertLike} from '../helpers/assert.js';100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 6–11why, one step back6import {execa} from '../../index.js';7import {setFixtureDirectory} from '../helpers/fixtures-directory.js';8import {foobarString} from '../helpers/input.js';910setFixtureDirectory();11TweaksSindre Sorhusbefore adoption698a1b8
lines 12–13why, one step back12const assertUnPipeError = async pipePromise => {13 const error = await assertRejects(pipePromise);100% test coverage (#1018)ehmickybefore adoption9f65b86
line 14why, one step back14TweaksSindre Sorhusbefore adoption698a1b8
lines 15–16why, one step back15 assert.equal(error.command, 'source.pipe(destination)');16 assert.equal(error.escapedCommand, error.command);100% test coverage (#1018)ehmickybefore adoption9f65b86
line 17why, one step back17TweaksSindre Sorhusbefore adoption698a1b8
lines 18–30why, one step back18 assert.equal(typeof error.cwd, 'string');19 assert.equal(error.failed, true);20 assert.equal(error.timedOut, false);21 assert.equal(error.isCanceled, false);22 assert.equal(error.isTerminated, false);23 assert.equal(error.exitCode, undefined);24 assert.equal(error.signal, undefined);25 assert.equal(error.signalDescription, undefined);26 assert.equal(error.stdout, undefined);27 assert.equal(error.stderr, undefined);28 assert.equal(error.all, undefined);29 assert.deepEqual(error.stdio, Array.from({length: error.stdio.length}));30 assert.deepEqual(error.pipedFrom, []);100% test coverage (#1018)ehmickybefore adoption9f65b86
line 31why, one step back31TweaksSindre Sorhusbefore adoption698a1b8
lines 32–35why, one step back32 assert.ok(error.originalMessage.includes('Pipe canceled'));33 assert.ok(error.shortMessage.includes(`Command failed: ${error.command}`));34 assert.ok(error.shortMessage.includes(error.originalMessage));35 assert.ok(error.message.includes(error.shortMessage));100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 36–37why, one step back36};37TweaksSindre Sorhusbefore adoption698a1b8
line 38why, one step back38test('Can unpipe a single subprocess', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 39–44why, one step back39 const abortController = new AbortController();40 const source = execa('stdin.js');41 const destination = execa('stdin.js');42 const pipePromise = source.pipe(destination, {unpipeSignal: abortController.signal});4344 abortController.abort();TweaksSindre Sorhusbefore adoption698a1b8
line 45why, one step back45 await assertUnPipeError(pipePromise);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 46–49why, one step back4647 source.stdin.end(foobarString);48 destination.stdin.end('.');49TweaksSindre Sorhusbefore adoption698a1b8
lines 50–51why, one step back50 assertLike(await destination, {stdout: '.'});51 assertLike(await source, {stdout: foobarString});100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 52–53why, one step back52});53TweaksSindre Sorhusbefore adoption698a1b8
line 54why, one step back54test('Can use an already aborted signal', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 55–60why, one step back55 const abortController = new AbortController();56 abortController.abort();57 const source = execa('empty.js');58 const destination = execa('empty.js');59 const pipePromise = source.pipe(destination, {unpipeSignal: abortController.signal});60TweaksSindre Sorhusbefore adoption698a1b8
line 61why, one step back61 await assertUnPipeError(pipePromise);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 62–63why, one step back62});63TweaksSindre Sorhusbefore adoption698a1b8
line 64why, one step back64test('Can unpipe a subprocess among other sources', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 65–72why, one step back65 const abortController = new AbortController();66 const source = execa('stdin.js');67 const secondSource = execa('noop.js', [foobarString]);68 const destination = execa('stdin.js');69 const pipePromise = source.pipe(destination, {unpipeSignal: abortController.signal});70 const secondPipePromise = secondSource.pipe(destination);7172 abortController.abort();TweaksSindre Sorhusbefore adoption698a1b8
line 73why, one step back73 await assertUnPipeError(pipePromise);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 74–76why, one step back7475 source.stdin.end('.');76TweaksSindre Sorhusbefore adoption698a1b8
lines 77–80why, one step back77 assert.equal(await secondPipePromise, await destination);78 assertLike(await destination, {stdout: foobarString});79 assertLike(await source, {stdout: '.'});80 assertLike(await secondSource, {stdout: foobarString});100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 81–82why, one step back81});82TweaksSindre Sorhusbefore adoption698a1b8
line 83why, one step back83test('Can unpipe a subprocess among other sources on the same subprocess', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 84–90why, one step back84 const abortController = new AbortController();85 const source = execa('stdin-both.js');86 const destination = execa('stdin.js');87 const pipePromise = source.pipe(destination, {unpipeSignal: abortController.signal});88 const secondPipePromise = source.pipe(destination, {from: 'stderr'});8990 abortController.abort();TweaksSindre Sorhusbefore adoption698a1b8
line 91why, one step back91 await assertUnPipeError(pipePromise);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 92–94why, one step back9293 source.stdin.end(foobarString);94TweaksSindre Sorhusbefore adoption698a1b8
lines 95–97why, one step back95 assert.equal(await secondPipePromise, await destination);96 assertLike(await destination, {stdout: foobarString});97 assertLike(await source, {stdout: foobarString, stderr: foobarString});100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 98–99why, one step back98});99TweaksSindre Sorhusbefore adoption698a1b8
line 100why, one step back100test('Can unpipe a subprocess among other destinations', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 101–108why, one step back101 const abortController = new AbortController();102 const source = execa('stdin.js');103 const destination = execa('stdin.js');104 const secondDestination = execa('stdin.js');105 const pipePromise = source.pipe(destination, {unpipeSignal: abortController.signal});106 const secondPipePromise = source.pipe(secondDestination);107108 abortController.abort();TweaksSindre Sorhusbefore adoption698a1b8
line 109why, one step back109 await assertUnPipeError(pipePromise);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 110–113why, one step back110111 source.stdin.end(foobarString);112 destination.stdin.end('.');113TweaksSindre Sorhusbefore adoption698a1b8
lines 114–117why, one step back114 assert.equal(await secondPipePromise, await secondDestination);115 assertLike(await destination, {stdout: '.'});116 assertLike(await source, {stdout: foobarString});117 assertLike(await secondDestination, {stdout: foobarString});100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 118–119why, one step back118});119TweaksSindre Sorhusbefore adoption698a1b8
line 120why, one step back120test('Can unpipe then re-pipe a subprocess', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 121–127why, one step back121 const abortController = new AbortController();122 const source = execa('stdin.js');123 const destination = execa('stdin.js');124 const pipePromise = source.pipe(destination, {unpipeSignal: abortController.signal});125126 source.stdin.write('.');127 const [firstWrite] = await once(source.stdout, 'data');TweaksSindre Sorhusbefore adoption698a1b8
line 128why, one step back128 assert.equal(firstWrite.toString(), '.');100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 129–130why, one step back129130 abortController.abort();TweaksSindre Sorhusbefore adoption698a1b8
line 131why, one step back131 await assertUnPipeError(pipePromise);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 132–135why, one step back132133 source.pipe(destination);134 source.stdin.end('.');135TweaksSindre Sorhusbefore adoption698a1b8
lines 136–137why, one step back136 assertLike(await destination, {stdout: '..'});137 assertLike(await source, {stdout: '..'});100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 138–139why, one step back138});139TweaksSindre Sorhusbefore adoption698a1b8
line 140why, one step back140test('Can unpipe to prevent termination to propagate to source', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 141–146why, one step back141 const abortController = new AbortController();142 const source = execa('stdin.js');143 const destination = execa('stdin.js');144 const pipePromise = source.pipe(destination, {unpipeSignal: abortController.signal});145146 abortController.abort();TweaksSindre Sorhusbefore adoption698a1b8
line 147why, one step back147 await assertUnPipeError(pipePromise);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 148–149why, one step back148149 destination.kill();TweaksSindre Sorhusbefore adoption698a1b8
line 150why, one step back150 assertLike(await assertRejects(destination), {signal: 'SIGTERM'});100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 151–152why, one step back151152 source.stdin.end(foobarString);TweaksSindre Sorhusbefore adoption698a1b8
line 153why, one step back153 assertLike(await source, {stdout: foobarString});100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 154–155why, one step back154});155TweaksSindre Sorhusbefore adoption698a1b8
line 156why, one step back156test('Can unpipe to prevent termination to propagate to destination', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 157–162why, one step back157 const abortController = new AbortController();158 const source = execa('noop-forever.js', [foobarString]);159 const destination = execa('stdin.js');160 const pipePromise = source.pipe(destination, {unpipeSignal: abortController.signal});161162 abortController.abort();TweaksSindre Sorhusbefore adoption698a1b8
line 163why, one step back163 await assertUnPipeError(pipePromise);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 164–165why, one step back164165 source.kill();TweaksSindre Sorhusbefore adoption698a1b8
line 166why, one step back166 assertLike(await assertRejects(source), {signal: 'SIGTERM'});100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 167–168why, one step back167168 destination.stdin.end(foobarString);TweaksSindre Sorhusbefore adoption698a1b8
line 169why, one step back169 assertLike(await destination, {stdout: foobarString});Fix wrong-typed options and arguments being silently ignored or coercedSindre Sorhusbefore adoptionb57d643
lines 170–198why, one step back170});171172test('The "unpipeSignal" option must be an AbortSignal', async () => {173 const source = execa('noop.js', [foobarString]);174 const {cause} = await assertRejects(source.pipe('stdin.js', {unpipeSignal: foobarString}));175 assert.equal(cause.message, `The \`unpipeSignal\` option must be an AbortSignal: ${foobarString}.`);176 await source;177});178179// The unpiped destination ending later must not abort the source, which is still piped to the other destination180test('Unpiping one destination does not affect the other destinations of the same source', async () => {181 const source = execa('noop-repeat.js', ['1', `${foobarString}\n`]);182 const unpipedDestination = execa('stdin.js');183 const receivingDestination = execa('stdin.js');184 const controller = new AbortController();185 const pipePromise = source.pipe(unpipedDestination, {unpipeSignal: controller.signal});186 source.pipe(receivingDestination).catch(() => {});187188 controller.abort();189 await assertRejects(pipePromise);190 unpipedDestination.stdin.end();191 await unpipedDestination;192 await setTimeout(100);193 source.kill();194195 const {isTerminated} = await assertRejects(source);196 assert.ok(isTerminated);197 const {stdout} = await receivingDestination;198 assert.ok(stdout.split('\n').length > 2);100% test coverage (#1018)ehmickybefore adoption9f65b86
line 199why, one step back199});