Browse Source

[several] Minor fixes

master
Muthu Kumar 6 years ago
parent
commit
d66303acc1
  1. 2
      package.json
  2. 4
      src/gunner.js
  3. 2
      src/lib/assertPromise.js
  4. 2
      src/lib/expect.js
  5. 94
      src/lib/logger.js
  6. 12
      src/runner/index.js
  7. 8
      src/strategy/index.js

2
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": {

4
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;

2
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));

2
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;

94
src/lib/logger.js

@ -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,
};

12
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);
});
};

8
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;
}

Loading…
Cancel
Save