From 6154b99e9b666c4e033d044da75311c3f5c4cc69 Mon Sep 17 00:00:00 2001 From: Muthu Kumar Date: Wed, 8 Aug 2018 20:01:54 +0530 Subject: [PATCH] [refactor] --- gunner/index.js | 12 +++++++++--- gunner/lib/expect.js | 32 ++++++++------------------------ gunner/lib/runTests.js | 1 - 3 files changed, 17 insertions(+), 28 deletions(-) diff --git a/gunner/index.js b/gunner/index.js index f1767d0..66ba5e2 100644 --- a/gunner/index.js +++ b/gunner/index.js @@ -28,13 +28,11 @@ class Gunner { run (options = {}) { const shouldLog = (hasProp(options)('log') && options.log) || !(hasProp(options)('log')); - if (shouldLog) process.stdout.write(`Running ${this.tests.length} tests${this.name ? ` for ${this.name}` : ''}...`); return _runTests(this.tests) .then(results => { if (shouldLog) { - process.stdout.clearLine(); - process.stdout.cursorTo(0); const success = results.filter(r => r.result === 'pass'); + results.passing = success.length; const successPercent = Math.floor(success.length/results.length * 100); log( `\n${success.length} tests passed of ${results.length}`, @@ -52,6 +50,14 @@ class Gunner { } return results; + }) + .then(results => { + if (options.exit) { + if(results.passing < results.length) + process.exit(1); + process.exit(0); + } + return results; }); } diff --git a/gunner/lib/expect.js b/gunner/lib/expect.js index fe1e5c2..cec83c6 100644 --- a/gunner/lib/expect.js +++ b/gunner/lib/expect.js @@ -1,40 +1,24 @@ const isEq = require('@codefeathers/iseq'); -const { stringify, liftPromise, isPromise } = require('../../util/helpers'); +const { liftPromise, stringify, isPromise } = require('../../util/helpers'); const _assertPromise = require('./assertPromise'); -const assertPromise = ( - pred, - statement, - value, - original, - ...testValues -) => _assertPromise( - pred(original, ...testValues), - statement(value, ...testValues) -); const expectPromise = (pred, statement, options = {}) => toTest => (...testValues) => liftPromise( - x => assertPromise( - pred, - statement, - x, - toTest, - ...testValues + resolvedValue => _assertPromise( + pred(toTest, ...testValues), + statement(resolvedValue, ...testValues), ), - toTest + toTest, ) .catch(rejectedValue => options.shouldCatch - ? assertPromise( - pred, - statement, - rejectedValue, - toTest, - ...testValues + ? _assertPromise( + pred(toTest, ...testValues), + statement(rejectedValue, ...testValues), ) : Promise.reject(rejectedValue) ); diff --git a/gunner/lib/runTests.js b/gunner/lib/runTests.js index 3d65991..a94a306 100644 --- a/gunner/lib/runTests.js +++ b/gunner/lib/runTests.js @@ -1,7 +1,6 @@ 'use strict'; const { isPromise } = require('../../util/helpers'); - const { pass, fail } = require('./constants'); const runTests = tests => Promise.all(tests.map(each => {