From 30cb091681c992d9d66e4bb6090397a1e1fb891b Mon Sep 17 00:00:00 2001 From: ehmicky Date: Thu, 6 Jun 2019 10:00:00 +0200 Subject: [PATCH] Fix tests --- test.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/test.js b/test.js index c1e322f72b..7229b80084 100644 --- a/test.js +++ b/test.js @@ -362,14 +362,25 @@ test('use relative path with \'..\' chars', async t => { }); if (process.platform !== 'win32') { - test('execa() rejects if running non-executable', async t => { - const cp = execa('non-executable'); - await t.throwsAsync(cp); - }); + // On Node 8, `child_process.spawn()` throws synchronously, but not on Node >=10 + // TODO: remove Node 8 test case once we stop supporting Node 8 + if (process.version.startsWith('v8')) { + test('execa() throws if running non-executable', t => { + t.throws(() => execa('non-executable')); + }); - test('execa() rejects with correct error and doesn\'t throw if running non-executable with input', async t => { - await t.throwsAsync(execa('non-executable', {input: 'Hey!'}), /EACCES/); - }); + test('execa() throws with correct error and doesn\'t throw if running non-executable with input', t => { + t.throws(() => execa('non-executable', {input: 'Hey!'}), /EACCES/); + }); + } else { + test('execa() rejects if running non-executable', async t => { + await t.throwsAsync(execa('non-executable')); + }); + + test('execa() rejects with correct error and doesn\'t throw if running non-executable with input', async t => { + await t.throwsAsync(execa('non-executable', {input: 'Hey!'}), /EACCES/); + }); + } } test('error.killed is true if process was killed directly', async t => {