Browse Source

[refactor]

0.7.0-breaking-rewrite
Muthu Kumar 7 years ago
parent
commit
6154b99e9b
  1. 12
      gunner/index.js
  2. 32
      gunner/lib/expect.js
  3. 1
      gunner/lib/runTests.js

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

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

1
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 => {

Loading…
Cancel
Save