diff options
author | Florian Dold <florian.dold@gmail.com> | 2017-05-28 00:38:50 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2017-05-28 00:40:43 +0200 |
commit | 7fff4499fd915bcea3fa93b1aa8b35f4fe7a6027 (patch) | |
tree | 6de9a1aebd150a23b7f8c273ec657a5d0a18fe3e /node_modules/ava/lib/run-status.js | |
parent | 963b7a41feb29cc4be090a2446bdfe0c1f1bcd81 (diff) |
add linting (and some initial fixes)
Diffstat (limited to 'node_modules/ava/lib/run-status.js')
-rw-r--r-- | node_modules/ava/lib/run-status.js | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/node_modules/ava/lib/run-status.js b/node_modules/ava/lib/run-status.js new file mode 100644 index 000000000..6526f7bdc --- /dev/null +++ b/node_modules/ava/lib/run-status.js @@ -0,0 +1,125 @@ +'use strict'; +const EventEmitter = require('events'); +const chalk = require('chalk'); +const flatten = require('arr-flatten'); +const figures = require('figures'); +const autoBind = require('auto-bind'); +const prefixTitle = require('./prefix-title'); + +function sum(arr, key) { + let result = 0; + + arr.forEach(item => { + result += item[key]; + }); + + return result; +} + +class RunStatus extends EventEmitter { + constructor(opts) { + super(); + + opts = opts || {}; + this.prefixTitles = opts.prefixTitles !== false; + this.hasExclusive = Boolean(opts.runOnlyExclusive); + this.base = opts.base || ''; + this.rejectionCount = 0; + this.exceptionCount = 0; + this.passCount = 0; + this.knownFailureCount = 0; + this.skipCount = 0; + this.todoCount = 0; + this.failCount = 0; + this.fileCount = 0; + this.testCount = 0; + this.remainingCount = 0; + this.previousFailCount = 0; + this.knownFailures = []; + this.errors = []; + this.stats = []; + this.tests = []; + this.failFastEnabled = opts.failFast || false; + + autoBind(this); + } + observeFork(emitter) { + emitter + .on('teardown', this.handleTeardown) + .on('stats', this.handleStats) + .on('test', this.handleTest) + .on('unhandledRejections', this.handleRejections) + .on('uncaughtException', this.handleExceptions) + .on('stdout', this.handleOutput.bind(this, 'stdout')) + .on('stderr', this.handleOutput.bind(this, 'stderr')); + } + handleRejections(data) { + this.rejectionCount += data.rejections.length; + + data.rejections.forEach(err => { + err.type = 'rejection'; + err.file = data.file; + this.emit('error', err, this); + this.errors.push(err); + }); + } + handleExceptions(data) { + this.exceptionCount++; + const err = data.exception; + err.type = 'exception'; + err.file = data.file; + this.emit('error', err, this); + this.errors.push(err); + } + handleTeardown(data) { + this.emit('dependencies', data.file, data.dependencies, this); + } + handleStats(stats) { + this.emit('stats', stats, this); + + if (stats.hasExclusive) { + this.hasExclusive = true; + } + + this.testCount += stats.testCount; + } + handleTest(test) { + test.title = this.prefixTitle(test.file) + test.title; + + if (test.error) { + this.errors.push(test); + } + + if (test.failing && !test.error) { + this.knownFailures.push(test); + } + + this.emit('test', test, this); + } + prefixTitle(file) { + if (!this.prefixTitles) { + return ''; + } + + const separator = ' ' + chalk.gray.dim(figures.pointerSmall) + ' '; + + return prefixTitle(file, this.base, separator); + } + handleOutput(channel, data) { + this.emit(channel, data, this); + } + processResults(results) { + // Assemble stats from all tests + this.stats = results.map(result => result.stats); + this.tests = results.map(result => result.tests); + this.tests = flatten(this.tests); + this.passCount = sum(this.stats, 'passCount'); + this.knownFailureCount = sum(this.stats, 'knownFailureCount'); + this.skipCount = sum(this.stats, 'skipCount'); + this.todoCount = sum(this.stats, 'todoCount'); + this.failCount = sum(this.stats, 'failCount'); + this.remainingCount = this.testCount - this.passCount - this.failCount - this.skipCount - this.todoCount - this.knownFailureCount; + } +} + +module.exports = RunStatus; |