|
@ -1,6 +1,6 @@ |
|
|
'use strict'; |
|
|
'use strict'; |
|
|
|
|
|
|
|
|
const { log } = console; |
|
|
const { EOL } = require('os'); |
|
|
const chalk = require('chalk'); |
|
|
const chalk = require('chalk'); |
|
|
|
|
|
|
|
|
Promise = require('bluebird'); |
|
|
Promise = require('bluebird'); |
|
@ -8,8 +8,9 @@ Promise.object = require('@codefeathers/promise.object'); |
|
|
|
|
|
|
|
|
const _runTests = require('./lib/runTests'); |
|
|
const _runTests = require('./lib/runTests'); |
|
|
const _expect = require('./lib/expect'); |
|
|
const _expect = require('./lib/expect'); |
|
|
|
|
|
const logger = require('./lib/logger'); |
|
|
|
|
|
|
|
|
const { stringify, hasProp } = require('./util'); |
|
|
const { hasProp } = require('./util'); |
|
|
const symbols = require('./util/symbols'); |
|
|
const symbols = require('./util/symbols'); |
|
|
|
|
|
|
|
|
class Gunner { |
|
|
class Gunner { |
|
@ -80,47 +81,39 @@ class Gunner { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
run (options = {}) { |
|
|
run (options = {}) { |
|
|
const shouldLog = ( |
|
|
options.log = (options || {})['log'] || !(hasProp(options)('log')); |
|
|
(hasProp(options)('log') |
|
|
return _runTests(this, options) |
|
|
&& options.log) |
|
|
|
|
|
|| !(hasProp(options)('log')) |
|
|
|
|
|
); |
|
|
|
|
|
return _runTests(this) |
|
|
|
|
|
.then(results => { |
|
|
.then(results => { |
|
|
if (shouldLog) { |
|
|
|
|
|
const success = results.filter(r => r.result === 'pass'); |
|
|
const success = results.filter(r => r.result === 'pass'); |
|
|
results.passing = success.length; |
|
|
|
|
|
const successPercent = Math.floor( |
|
|
const successPercent = Math.floor( |
|
|
success.length/results.length * 100 |
|
|
success.length/results.length * 100 |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
const beforeAfterLine = |
|
|
|
|
|
successPercent === 100 |
|
|
|
|
|
? chalk`{green ------------------------------------}` |
|
|
|
|
|
: chalk`{red ------------------------------------}`; |
|
|
|
|
|
|
|
|
|
|
|
const log = logger.create(options); |
|
|
log( |
|
|
log( |
|
|
chalk`\n{green ${success.length}}`, |
|
|
EOL, |
|
|
|
|
|
beforeAfterLine, |
|
|
|
|
|
EOL, EOL, |
|
|
|
|
|
chalk`{green ${success.length}}`, |
|
|
`tests passed of ${results.length}`, |
|
|
`tests passed of ${results.length}`, |
|
|
`[${successPercent}% success]\n` |
|
|
`[${successPercent}% success]`, |
|
|
|
|
|
EOL, EOL, |
|
|
|
|
|
beforeAfterLine |
|
|
); |
|
|
); |
|
|
results.forEach(r => { |
|
|
|
|
|
const trace = (options.trace && r.error) |
|
|
|
|
|
? `\n Traceback:\n ${stringify(r.error)}` |
|
|
|
|
|
: ''; |
|
|
|
|
|
|
|
|
|
|
|
log( |
|
|
if((successPercent !== 100) && typeof process !== 'undefined') |
|
|
`${r.result === 'pass' |
|
|
process.exitCode = 1; |
|
|
? chalk`{green ✅}` |
|
|
|
|
|
: chalk`{red ❌}`} ::`,
|
|
|
|
|
|
`${r.description}`, |
|
|
|
|
|
`${trace}` |
|
|
|
|
|
); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return results; |
|
|
return results; |
|
|
}) |
|
|
}) |
|
|
.then(results => { |
|
|
.then(results => { |
|
|
if (options.exit) { |
|
|
if (options.exit && typeof process !== 'undefined') |
|
|
if(results.passing < results.length) |
|
|
process.exit(); |
|
|
process.exit(1); |
|
|
|
|
|
process.exit(0); |
|
|
|
|
|
} |
|
|
|
|
|
return results; |
|
|
return results; |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|