From d66303acc17144fafb84274e4279feb3fe4a9eb8 Mon Sep 17 00:00:00 2001 From: Muthu Kumar Date: Fri, 14 Sep 2018 11:27:30 +0530 Subject: [PATCH] [several] Minor fixes --- package.json | 2 +- src/gunner.js | 4 +-- src/lib/assertPromise.js | 2 +- src/lib/expect.js | 2 +- src/lib/logger.js | 94 ------------------------------------------------ src/runner/index.js | 12 +++---- src/strategy/index.js | 8 ++--- 7 files changed, 13 insertions(+), 111 deletions(-) delete mode 100644 src/lib/logger.js diff --git a/package.json b/package.json index 21ec63e..364d0cd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@klenty/gunner", - "version": "0.9.0", + "version": "0.9.1", "description": "Zero magic, fast test-runner and assertion framework. No magic globals.", "main": "index.js", "repository": { diff --git a/src/gunner.js b/src/gunner.js index 7510725..6bd058b 100644 --- a/src/gunner.js +++ b/src/gunner.js @@ -6,7 +6,7 @@ const caller = require('./lib/caller'); const emitter = require('./lib/emitter'); const reporter = require('./reporters/default'); const testrunner = require('./lib/testrunner'); -const { expect, expectMany } = require('./lib/expect'); +const expect = require('./lib/expect'); const symbols = require('./util/symbols'); @@ -94,6 +94,6 @@ class Gunner { module.exports = Gunner; module.exports.Gunner = Gunner; module.exports.expect = expect; -module.exports.expectMany = expectMany; +module.exports.expectMany = expect.expectMany; module.exports.Start = symbols.Start; module.exports.End = symbols.End; diff --git a/src/lib/assertPromise.js b/src/lib/assertPromise.js index ece8fb3..ce294a8 100644 --- a/src/lib/assertPromise.js +++ b/src/lib/assertPromise.js @@ -7,7 +7,7 @@ const assertPromise = (bool, statementTuple, options = {}) => { let [ statement, ...args ] = statementTuple; statement = options.skipStatement ? () => options.skipStatement : statement; - console.log('skipStatement', statement()) + if(isPromise(bool)) return bool.catch(() => createRejectionStatement(statement, ...args)); diff --git a/src/lib/expect.js b/src/lib/expect.js index 0c1f0ff..962ab8a 100644 --- a/src/lib/expect.js +++ b/src/lib/expect.js @@ -59,5 +59,5 @@ const expect = (thing, args) => const expectMany = Promise.all.bind(Promise); -module.exports.expect = expect; +module.exports = expect; module.exports.expectMany = expectMany; diff --git a/src/lib/logger.js b/src/lib/logger.js deleted file mode 100644 index d0fde1e..0000000 --- a/src/lib/logger.js +++ /dev/null @@ -1,94 +0,0 @@ -const chalk = require('chalk'); -const { taggedStringify: _ } = require('../util'); -const { EOL, greenLine, redLine } = require('../util/constants'); - -const processResults = (results, options) => { - - const success = results.filter(r => r.result === 'pass'); - results.passing = success.length; - const successPercent = Math.floor( - success.length/results.length * 100 - ); - let resultString = ''; - resultString += - chalk`\n{green ${success.length} }` - + `tests passed of ${results.length} ` - + `[${successPercent}% success]\n` - + EOL; - results.forEach(r => { - const trace = (options.trace && r.error) - ? _`\n Traceback:\n ${r.error}` - : ''; - - resultString += - `${r.result === 'pass' - ? chalk`{green ✅}` - : chalk`{red ❌}`} :: ` - + `${r.description}` - + `${trace}`; - }); - return resultString; - -}; - -/** - * Creates a Logger that only logs if 'log' option was true - * @param {Object} options - * @param {boolean=} options.log - * @param {boolean=} shouldProcess - */ -const logger = (options = {}, shouldProcess) => { - - const log = (...items) => { - - if (!options.log) return; - - let logEmit; - if (typeof options.log === 'function') { - logEmit = (...x) => { - console.log(...x); - options.log(...x); - }; - } - else logEmit = console.log; - - if (!shouldProcess) - logEmit(...items); - else { - - const [ results ] = items; - const success = results.filter(r => r.result === 'pass'); - const successPercent = Math.floor( - success.length/results.length * 100 - ); - - logEmit(processResults(results, options)); - - const demarkerLine = - successPercent === 100 - ? greenLine - : redLine; - - logEmit( - EOL, - demarkerLine, - EOL, EOL, - chalk.green(` ${success.length}`), - `tests passed of ${results.length}`, - `[${successPercent}% success]`, - EOL, EOL, - demarkerLine - ); - - } - - }; - - log.true = options.log; - return log; - -}; - -module.exports = { - create: logger, -}; diff --git a/src/runner/index.js b/src/runner/index.js index 6166f09..7d9642a 100644 --- a/src/runner/index.js +++ b/src/runner/index.js @@ -1,5 +1,4 @@ const { flatten } = require('../util'); -const logger = require('../lib/logger'); const runner = instances => (options = {}) => { @@ -19,17 +18,14 @@ const runner = instances => (options = {}) => { if (RunInstances.length !== instances.length) throw new Error (`Not all instances were of type ${type}`); - return Promise.map(RunInstances, instance => { + return Promise.all(RunInstances.map(instance => { return ( instance - .run() + .run(options) ); - }) + })) .then(results => { - results = flatten(results); - const log = logger.create(options, true); - log(results); - return results; + return flatten(results); }); }; diff --git a/src/strategy/index.js b/src/strategy/index.js index aede770..8e578cc 100644 --- a/src/strategy/index.js +++ b/src/strategy/index.js @@ -39,10 +39,10 @@ class Strategy { */ fetchSpecs (options) { this.__await__.push( - Promise.all( - requireDeep(options).map( - each => this.__gunnerInstances = this.compiler(this)(each) - ))); + requireDeep(options) + .then(required => required.map( + each => this.__gunnerInstances = this.compiler(this)(each) + ))); return this; }