From 2e3a5512e9bafd9ae354c5d26821ff62cfa70c93 Mon Sep 17 00:00:00 2001 From: Ian Walter Date: Wed, 24 Apr 2019 21:37:12 -0400 Subject: [PATCH] Fixing #37: registration pool termination issue --- cli.js | 7 +++---- index.js | 20 ++++++++++---------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/cli.js b/cli.js index 54530e00..7375c226 100755 --- a/cli.js +++ b/cli.js @@ -30,17 +30,16 @@ async function run () { const { passed, failed, skipped } = await bff(config) // Log the results of running the tests. - console.log('') + process.stdout.write('\n') print.info(`${passed} passed. ${failed} failed. ${skipped} skipped.`) // If any tests failed, exit with a non-zero exit code. - if (failed) { - process.exit(1) - } + process.exit(failed ? 1 : 0) } try { run() } catch (err) { print.error(err) + process.exit(1) } diff --git a/index.js b/index.js index 48cc880c..837ee3e3 100644 --- a/index.js +++ b/index.js @@ -11,7 +11,7 @@ const { toHookExec, getSnapshotState } = require('./lib') * worker pool to be executed. */ function run (config) { - return new Promise(async resolve => { + return new Promise(async (resolve, reject) => { // Create the run context using the passed configuration and defaults. const context = { ...config, @@ -99,6 +99,13 @@ function run (config) { // for the current test file. context.filesRegistered++ + // Terminate the registration pool if all the test files have been + // registered. + if (context.filesRegistered === context.files.length) { + registrationPool.terminate() + .then(() => print.debug('Registration pool terminated')) + } + // Add the number of tests returned by test registration to the running // total of all tests that need to be executed. context.testsRegistered += tests.length @@ -230,19 +237,12 @@ function run (config) { resolve(context) } } catch (err) { - print.error(err) + reject(err) } }) }) } catch (err) { - print.error(err) - } finally { - // Terminate the registration pool if all the test files have been - // registered. - if (context.filesRegistered === context.files.length) { - registrationPool.terminate() - .then(() => print.debug('Registration pool terminated')) - } + reject(err) } }) }