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;