From 4c7d36e96d948c510c13d7ba339c60e5da8e76a6 Mon Sep 17 00:00:00 2001 From: Mathias Lykkegaard Lorenzen Date: Wed, 9 Oct 2019 21:08:46 +0200 Subject: [PATCH 1/2] Fix for issue causing subprocess to never end fixes #23 and #29. For some reason, if `buffer` is set to `false`, the `await subprocess` call never ends, no matter if the test passes or not. See #29 for steps to reproduce in this very repo. --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index e47f0c7..00e1a70 100644 --- a/index.js +++ b/index.js @@ -43,7 +43,7 @@ module.exports = options => { args.unshift(nycBin); } - const subprocess = execa(process.execPath, args, {buffer: false}); + const subprocess = execa(process.execPath, args, {buffer: true}); if (!options.silent) { subprocess.stdout.pipe(process.stdout); From 013b350da5bc8b053698be74f32b2a0dfc7c009e Mon Sep 17 00:00:00 2001 From: Mathias Lorenzen Date: Mon, 14 Oct 2019 11:15:08 +0200 Subject: [PATCH 2/2] alternative fix for originally proposed solution. --- index.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 00e1a70..e0b7eaa 100644 --- a/index.js +++ b/index.js @@ -43,15 +43,26 @@ module.exports = options => { args.unshift(nycBin); } - const subprocess = execa(process.execPath, args, {buffer: true}); + const processPromise = execa(process.execPath, args, {buffer: false}); + + const closePromise = new Promise((resolve, reject) => { + processPromise.on('close', exitCode => + exitCode === 0 ? + resolve() : + reject()); + }); if (!options.silent) { - subprocess.stdout.pipe(process.stdout); - subprocess.stderr.pipe(process.stderr); + processPromise.stdout.pipe(process.stdout); + processPromise.stderr.pipe(process.stderr); } try { - await subprocess; + await Promise.race([ + processPromise, + closePromise + ]); + callback(); } catch (_) { callback(new PluginError('gulp-ava', 'One or more tests failed'));