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 = {}) { run (options = {}) {
const shouldLog = (hasProp(options)('log') && options.log) || !(hasProp(options)('log')); 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) return _runTests(this.tests)
.then(results => { .then(results => {
if (shouldLog) { if (shouldLog) {
process.stdout.clearLine();
process.stdout.cursorTo(0);
const success = results.filter(r => r.result === 'pass'); const success = results.filter(r => r.result === 'pass');
results.passing = success.length;
const successPercent = Math.floor(success.length/results.length * 100); const successPercent = Math.floor(success.length/results.length * 100);
log( log(
`\n${success.length} tests passed of ${results.length}`, `\n${success.length} tests passed of ${results.length}`,
@ -52,6 +50,14 @@ class Gunner {
} }
return results; 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 isEq = require('@codefeathers/iseq');
const { stringify, liftPromise, isPromise } = require('../../util/helpers'); const { liftPromise, stringify, isPromise } = require('../../util/helpers');
const _assertPromise = require('./assertPromise'); const _assertPromise = require('./assertPromise');
const assertPromise = (
pred,
statement,
value,
original,
...testValues
) => _assertPromise(
pred(original, ...testValues),
statement(value, ...testValues)
);
const expectPromise = (pred, statement, options = {}) => const expectPromise = (pred, statement, options = {}) =>
toTest => toTest =>
(...testValues) => (...testValues) =>
liftPromise( liftPromise(
x => assertPromise( resolvedValue => _assertPromise(
pred, pred(toTest, ...testValues),
statement, statement(resolvedValue, ...testValues),
x,
toTest,
...testValues
), ),
toTest toTest,
) )
.catch(rejectedValue => .catch(rejectedValue =>
options.shouldCatch options.shouldCatch
? assertPromise( ? _assertPromise(
pred, pred(toTest, ...testValues),
statement, statement(rejectedValue, ...testValues),
rejectedValue,
toTest,
...testValues
) )
: Promise.reject(rejectedValue) : Promise.reject(rejectedValue)
); );

1
gunner/lib/runTests.js

@ -1,7 +1,6 @@
'use strict'; 'use strict';
const { isPromise } = require('../../util/helpers'); const { isPromise } = require('../../util/helpers');
const { pass, fail } = require('./constants'); const { pass, fail } = require('./constants');
const runTests = tests => Promise.all(tests.map(each => { const runTests = tests => Promise.all(tests.map(each => {

Loading…
Cancel
Save