From de27f4ccbb676399cb34efaf1e8d2bc2c969280f Mon Sep 17 00:00:00 2001 From: Muthu Kumar Date: Tue, 4 Sep 2018 12:49:53 +0530 Subject: [PATCH] [Runner] Added Gunner/Runner module --- .eslintignore | 1 + Runner.js | 1 + package.json | 2 +- src/runner/index.js | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 .eslintignore create mode 100644 Runner.js create mode 100644 src/runner/index.js diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..0baf809 --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +*.min.js \ No newline at end of file diff --git a/Runner.js b/Runner.js new file mode 100644 index 0000000..2910d70 --- /dev/null +++ b/Runner.js @@ -0,0 +1 @@ +module.exports = require('./src/runner'); diff --git a/package.json b/package.json index 93b590b..c0fd850 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@klenty/gunner", - "version": "0.6.0", + "version": "0.6.5", "description": "Zero magic, fast test-runner and assertion framework. No magic globals.", "main": "index.js", "repository": { diff --git a/src/runner/index.js b/src/runner/index.js new file mode 100644 index 0000000..d2155b7 --- /dev/null +++ b/src/runner/index.js @@ -0,0 +1,39 @@ +const Promise = require('bluebird'); + +const { flatten } = require('../util'); +const logger = require('../lib/logger'); + +const runner = instances => (options = {}) => { + + instances = Array.isArray(instances) ? instances : [ instances ]; + + if(!instances.length) + throw new Error(`No instances were passed to Gunner Runner`); + + const type = instances[0].__proto__.constructor.name; + + if (type !== "Gunner" && type !== "Strategy") + throw new Error (`Runner ${type} is not one of Gunner or Strategy`); + + const RunInstances = instances.filter(i => + i.__proto__.constructor.name === type); + + if (RunInstances.length !== instances.length) + throw new Error (`Not all instances were of type ${type}`); + + return Promise.map(RunInstances, instance => { + return ( + instance + .run() + ); + }) + .then(results => { + results = flatten(results); + const log = logger.create(options, true); + log(results); + return results; + }); + +}; + +module.exports = runner;