From 88585d25456951589cac3100155ddb8aca643cfe Mon Sep 17 00:00:00 2001 From: ehmicky Date: Tue, 7 May 2019 02:58:18 -0700 Subject: [PATCH] Fix `options.detached` test (#215) --- fixtures/detach | 13 ++++--------- fixtures/forever | 2 +- test.js | 11 +++++------ 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/fixtures/detach b/fixtures/detach index f85eb4af86..7da1f8fd6b 100755 --- a/fixtures/detach +++ b/fixtures/detach @@ -1,13 +1,8 @@ #!/usr/bin/env node -const fs = require('fs'); -const execa = require('..'); - -const fd = fs.openSync(process.argv[2], 'w'); +'use strict'; -const cp = execa('noop', ['foo'], { - detached: true, - stdio: ['ignore', fd] -}); -cp.unref(); +const execa = require('..'); +const subprocess = execa('node', ['./fixtures/forever'], {detached: true}); +console.log(subprocess.pid); process.exit(); diff --git a/fixtures/forever b/fixtures/forever index af3141bd24..b64113fa86 100755 --- a/fixtures/forever +++ b/fixtures/forever @@ -1,4 +1,4 @@ #!/usr/bin/env node 'use strict'; -setTimeout(() => {}, 20000); +setTimeout(() => {}, 1e8); diff --git a/test.js b/test.js index abbf7d77c8..2cb3095348 100644 --- a/test.js +++ b/test.js @@ -581,13 +581,12 @@ test('do not buffer when streaming', async t => { }); test('detach child process', async t => { - const file = tempfile('.txt'); - - await execa('detach', [file]); - - await delay(5000); + const {stdout} = await execa('detach'); + const pid = Number(stdout); + t.true(Number.isInteger(pid)); + t.true(isRunning(pid)); - t.is(fs.readFileSync(file, 'utf8'), 'foo\n'); + process.kill(pid, 'SIGKILL'); }); // See #128