generator-error.js
This file
Path
test/transform/generator-error.js
119 lines · 5.5 KiB · JavaScript
Last changed by
TweaksSindre Sorhusbefore adoption698a1b8
History of this fileTake it
The walk stopped after 200 commits: lines older than 0bd0f0d point at it.
TweaksSindre Sorhusbefore adoption698a1b8
line 1why, one step back1import assert from 'node:assert/strict';Split type files (#978)ehmickybefore adoption0bd0f0d
line 2why, one step back2import {once} from 'node:events';Fix `execaSync()` output transformsSindre Sorhusbefore adoptione0b5dbc
line 3why, one step back3import {readFile, rm} from 'node:fs/promises';TweaksSindre Sorhusbefore adoption698a1b8
line 4why, one step back4import test from 'node:test';Fix `execaSync()` output transformsSindre Sorhusbefore adoptione0b5dbc
line 5why, one step back5import tempfile from 'tempfile';TweaksSindre Sorhusbefore adoption698a1b8
line 6why, one step back6import {assertThrows, assertRejects, assertLike} from '../helpers/assert.js';Split type files (#978)ehmickybefore adoption0bd0f0d
lines 7–8why, one step back7import {execa, execaSync} from '../../index.js';8import {foobarString} from '../helpers/input.js';TweaksSindre Sorhusbefore adoption698a1b8
lines 9–14why, one step back9import {10 noopGenerator,11 infiniteGenerator,12 convertTransformToFinal,13 throwingGenerator,14} from '../helpers/generator.js';Split type files (#978)ehmickybefore adoption0bd0f0d
line 15why, one step back15import {generatorsMap} from '../helpers/map.js';Upgrade xo (#980)ehmickybefore adoptionccfa412
line 16why, one step back16import {setFixtureDirectory} from '../helpers/fixtures-directory.js';Add `result.ipc`/`error.ipc` (#1067)ehmickybefore adoption3ab34de
line 17why, one step back17import {getEarlyErrorSubprocess, expectedEarlyError} from '../helpers/early-error.js';Split type files (#978)ehmickybefore adoption0bd0f0d
line 18why, one step back18Upgrade xo (#980)ehmickybefore adoptionccfa412
line 19why, one step back19setFixtureDirectory();Split type files (#978)ehmickybefore adoption0bd0f0d
line 20why, one step back20TweaksSindre Sorhusbefore adoption698a1b8
line 21why, one step back21const assertProcessError = async (type, execaMethod, getSubprocess) => {Split type files (#978)ehmickybefore adoption0bd0f0d
lines 22–24why, one step back22 const cause = new Error(foobarString);23 const transform = generatorsMap[type].throwing(cause)();24 const error = execaMethod === execaTweaksSindre Sorhusbefore adoption698a1b8
lines 25–26why, one step back25 ? await assertRejects(getSubprocess(transform))26 : assertThrows(() => {Split type files (#978)ehmickybefore adoption0bd0f0d
lines 27–28why, one step back27 getSubprocess(transform);28 });TweaksSindre Sorhusbefore adoption698a1b8
line 29why, one step back29 assert.equal(error.cause, cause);Split type files (#978)ehmickybefore adoption0bd0f0d
lines 30–31why, one step back30};31TweaksSindre Sorhusbefore adoption698a1b8
lines 32–33why, one step back32const testThrowingGenerator = async (type, final, execaMethod) => {33 await assertProcessError(type, execaMethod, transform => execaMethod('noop.js', {Split type files (#978)ehmickybefore adoption0bd0f0d
lines 34–37why, one step back34 stdout: convertTransformToFinal(transform, final),35 }));36};37TweaksSindre Sorhusbefore adoption698a1b8
lines 38–43why, one step back38test('Generators "transform" errors make subprocess fail', () => testThrowingGenerator('generator', false, execa));39test('Generators "final" errors make subprocess fail', () => testThrowingGenerator('generator', true, execa));40test('Generators "transform" errors make subprocess fail, sync', () => testThrowingGenerator('generator', false, execaSync));41test('Generators "final" errors make subprocess fail, sync', () => testThrowingGenerator('generator', true, execaSync));42test('Duplexes "transform" errors make subprocess fail', () => testThrowingGenerator('duplex', false, execa));43test('WebTransform "transform" errors make subprocess fail', () => testThrowingGenerator('webTransform', false, execa));Split type files (#978)ehmickybefore adoption0bd0f0d
line 44why, one step back44TweaksSindre Sorhusbefore adoption698a1b8
lines 45–46why, one step back45const testSingleErrorOutput = async (type, execaMethod) => {46 await assertProcessError(type, execaMethod, transform => execaMethod('noop.js', {Split type files (#978)ehmickybefore adoption0bd0f0d
lines 47–54why, one step back47 stdout: [48 generatorsMap[type].noop(false),49 transform,50 generatorsMap[type].noop(false),51 ],52 }));53};54TweaksSindre Sorhusbefore adoption698a1b8
lines 55–58why, one step back55test('Generators errors make subprocess fail even when other output generators do not throw', () => testSingleErrorOutput('generator', execa));56test('Generators errors make subprocess fail even when other output generators do not throw, sync', () => testSingleErrorOutput('generator', execaSync));57test('Duplexes errors make subprocess fail even when other output generators do not throw', () => testSingleErrorOutput('duplex', execa));58test('WebTransform errors make subprocess fail even when other output generators do not throw', () => testSingleErrorOutput('webTransform', execa));Split type files (#978)ehmickybefore adoption0bd0f0d
line 59why, one step back59TweaksSindre Sorhusbefore adoption698a1b8
lines 60–61why, one step back60const testSingleErrorInput = async (type, execaMethod) => {61 await assertProcessError(type, execaMethod, transform => execaMethod('stdin.js', {Split type files (#978)ehmickybefore adoption0bd0f0d
lines 62–70why, one step back62 stdin: [63 ['foobar\n'],64 generatorsMap[type].noop(false),65 transform,66 generatorsMap[type].noop(false),67 ],68 }));69};70TweaksSindre Sorhusbefore adoption698a1b8
lines 71–74why, one step back71test('Generators errors make subprocess fail even when other input generators do not throw', () => testSingleErrorInput('generator', execa));72test('Generators errors make subprocess fail even when other input generators do not throw, sync', () => testSingleErrorInput('generator', execaSync));73test('Duplexes errors make subprocess fail even when other input generators do not throw', () => testSingleErrorInput('duplex', execa));74test('WebTransform errors make subprocess fail even when other input generators do not throw', () => testSingleErrorInput('webTransform', execa));Split type files (#978)ehmickybefore adoption0bd0f0d
line 75why, one step back75TweaksSindre Sorhusbefore adoption698a1b8
line 76why, one step back76const testGeneratorCancel = async error => {Split type files (#978)ehmickybefore adoption0bd0f0d
lines 77–79why, one step back77 const subprocess = execa('noop.js', {stdout: infiniteGenerator()});78 await once(subprocess.stdout, 'data');79 subprocess.stdout.destroy(error);TweaksSindre Sorhusbefore adoption698a1b8
line 80why, one step back80 await (error === undefined ? assert.doesNotReject(subprocess) : assertRejects(subprocess));Split type files (#978)ehmickybefore adoption0bd0f0d
lines 81–82why, one step back81};82TweaksSindre Sorhusbefore adoption698a1b8
lines 83–84why, one step back83test('Running generators are canceled on subprocess abort', () => testGeneratorCancel(undefined));84test('Running generators are canceled on subprocess error', () => testGeneratorCancel(new Error('test')));Split type files (#978)ehmickybefore adoption0bd0f0d
line 85why, one step back85TweaksSindre Sorhusbefore adoption698a1b8
line 86why, one step back86const testGeneratorDestroy = async transform => {Split type files (#978)ehmickybefore adoption0bd0f0d
lines 87–90why, one step back87 const subprocess = execa('forever.js', {stdout: transform});88 const cause = new Error('test');89 subprocess.stdout.destroy(cause);90 subprocess.kill();TweaksSindre Sorhusbefore adoption698a1b8
line 91why, one step back91 assertLike(await assertRejects(subprocess), {cause});Split type files (#978)ehmickybefore adoption0bd0f0d
lines 92–93why, one step back92};93TweaksSindre Sorhusbefore adoption698a1b8
lines 94–95why, one step back94test('Generators are destroyed on subprocess error, sync', () => testGeneratorDestroy(noopGenerator(false)));95test('Generators are destroyed on subprocess error, async', () => testGeneratorDestroy(infiniteGenerator()));Split type files (#978)ehmickybefore adoption0bd0f0d
line 96why, one step back96TweaksSindre Sorhusbefore adoption698a1b8
lines 97–99why, one step back97test('Generators are destroyed on early subprocess exit', async () => {98 const error = await assertRejects(getEarlyErrorSubprocess({stdout: infiniteGenerator()}));99 assertLike(error, expectedEarlyError);Split type files (#978)ehmickybefore adoption0bd0f0d
line 100why, one step back100});Fix `execaSync()` output transformsSindre Sorhusbefore adoptione0b5dbc
lines 101–102why, one step back101102// A transform failing on one file descriptor must not prevent the other ones from being redirected to their targetTweaksSindre Sorhusbefore adoption698a1b8
line 103why, one step back103const testTransformErrorOtherFd = async execaMethod => {Fix `execaSync()` output transformsSindre Sorhusbefore adoptione0b5dbc
lines 104–111why, one step back104 const filePath = tempfile();105 const cause = new Error(foobarString);106 const runSubprocess = () => execaMethod('noop-both.js', [foobarString], {107 stdout: throwingGenerator(cause)(),108 stderr: {file: filePath},109 });110111 await (execaMethod === execaTweaksSindre Sorhusbefore adoption698a1b8
lines 112–114why, one step back112 ? assertRejects(runSubprocess())113 : assertThrows(runSubprocess));114 assert.equal(await readFile(filePath, 'utf8'), `${foobarString}\n`);Fix `execaSync()` output transformsSindre Sorhusbefore adoptione0b5dbc
lines 115–117why, one step back115 await rm(filePath);116};117TweaksSindre Sorhusbefore adoption698a1b8
lines 118–119why, one step back118test('Transform errors on stdout do not skip the stderr file', () => testTransformErrorOtherFd(execa));119test('Transform errors on stdout do not skip the stderr file, sync', () => testTransformErrorOtherFd(execaSync));