From 3215a58843717596201d667376fea1d740840617 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Mon, 28 Dec 2020 18:29:30 -0800 Subject: [PATCH] test: add already-aborted-controller test for spawn() PR-URL: https://github.com/nodejs/node/pull/36644 Reviewed-By: Benjamin Gruenbaum Reviewed-By: Daijiro Wachi --- .../test-child-process-spawn-controller.js | 44 ++++++++++++++----- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/test/parallel/test-child-process-spawn-controller.js b/test/parallel/test-child-process-spawn-controller.js index 2ac3a0ddd514a7..07f9cef3557d75 100644 --- a/test/parallel/test-child-process-spawn-controller.js +++ b/test/parallel/test-child-process-spawn-controller.js @@ -5,18 +5,38 @@ const common = require('../common'); const assert = require('assert'); const cp = require('child_process'); -// Verify that passing an AbortSignal works -const controller = new AbortController(); -const { signal } = controller; +{ + // Verify that passing an AbortSignal works + const controller = new AbortController(); + const { signal } = controller; -const echo = cp.spawn('echo', ['fun'], { - encoding: 'utf8', - shell: true, - signal -}); + const echo = cp.spawn('echo', ['fun'], { + encoding: 'utf8', + shell: true, + signal + }); -echo.on('error', common.mustCall((e) => { - assert.strictEqual(e.name, 'AbortError'); -})); + echo.on('error', common.mustCall((e) => { + assert.strictEqual(e.name, 'AbortError'); + })); -controller.abort(); + controller.abort(); +} + +{ + // Verify that passing an already-aborted signal works. + const controller = new AbortController(); + const { signal } = controller; + + controller.abort(); + + const echo = cp.spawn('echo', ['fun'], { + encoding: 'utf8', + shell: true, + signal + }); + + echo.on('error', common.mustCall((e) => { + assert.strictEqual(e.name, 'AbortError'); + })); +}