diff options
Diffstat (limited to 'node_modules/ava/lib/reporters')
-rw-r--r-- | node_modules/ava/lib/reporters/improper-usage-messages.js | 4 | ||||
-rw-r--r-- | node_modules/ava/lib/reporters/mini.js | 53 | ||||
-rw-r--r-- | node_modules/ava/lib/reporters/tap.js | 47 | ||||
-rw-r--r-- | node_modules/ava/lib/reporters/verbose.js | 76 |
4 files changed, 130 insertions, 50 deletions
diff --git a/node_modules/ava/lib/reporters/improper-usage-messages.js b/node_modules/ava/lib/reporters/improper-usage-messages.js index 298ef79a5..014a4bf0d 100644 --- a/node_modules/ava/lib/reporters/improper-usage-messages.js +++ b/node_modules/ava/lib/reporters/improper-usage-messages.js @@ -15,7 +15,9 @@ exports.forError = error => { Visit the following URL for more details: ${chalk.blue.underline('https://github.com/avajs/ava#throwsfunctionpromise-error-message')}`; - } else if (assertion === 'snapshot') { + } + + if (assertion === 'snapshot') { const name = error.improperUsage.name; const snapPath = error.improperUsage.snapPath; diff --git a/node_modules/ava/lib/reporters/mini.js b/node_modules/ava/lib/reporters/mini.js index 8acfab8e7..a21d02a6b 100644 --- a/node_modules/ava/lib/reporters/mini.js +++ b/node_modules/ava/lib/reporters/mini.js @@ -5,12 +5,12 @@ const lastLineTracker = require('last-line-stream/tracker'); const plur = require('plur'); const spinners = require('cli-spinners'); const chalk = require('chalk'); +const figures = require('figures'); const cliTruncate = require('cli-truncate'); const cross = require('figures').cross; const indentString = require('indent-string'); const ansiEscapes = require('ansi-escapes'); const trimOffNewlines = require('trim-off-newlines'); -const extractStack = require('../extract-stack'); const codeExcerpt = require('../code-excerpt'); const colors = require('../colors'); const formatSerializedError = require('./format-serialized-error'); @@ -33,6 +33,7 @@ class MiniReporter { this.stream = process.stderr; this.stringDecoder = new StringDecoder(); } + start() { this.interval = setInterval(() => { this.spinnerIndex = (this.spinnerIndex + 1) % this.spinnerFrames.length; @@ -41,6 +42,7 @@ class MiniReporter { return this.prefix(''); } + reset() { this.clearInterval(); this.passCount = 0; @@ -56,13 +58,16 @@ class MiniReporter { this.spinnerIndex = 0; this.lastLineTracker = lastLineTracker(); } + spinnerChar() { return this.spinnerFrames[this.spinnerIndex]; } + clearInterval() { clearInterval(this.interval); this.interval = null; } + test(test) { if (test.todo) { this.todoCount++; @@ -83,6 +88,7 @@ class MiniReporter { return this.prefix(this._test(test)); } + prefix(str) { str = str || this.currentTest; this.currentTest = str; @@ -91,6 +97,7 @@ class MiniReporter { // TODO(jamestalmage): Figure out why it's needed and document it here return ` \n ${this.spinnerChar()} ${str}`; } + _test(test) { const SPINNER_WIDTH = 3; const PADDING = 1; @@ -102,6 +109,7 @@ class MiniReporter { return title + '\n' + this.reportCounts(); } + unhandledError(err) { if (err.type === 'exception') { this.exceptionCount++; @@ -109,6 +117,7 @@ class MiniReporter { this.rejectionCount++; } } + reportCounts(time) { const lines = [ this.passCount > 0 ? '\n ' + colors.pass(this.passCount, 'passed') : '', @@ -124,6 +133,7 @@ class MiniReporter { return lines.join(''); } + finish(runStatus) { this.clearInterval(); let time; @@ -163,6 +173,21 @@ class MiniReporter { } status += ' ' + colors.title(test.title) + '\n'; + + if (test.logs) { + test.logs.forEach(log => { + const logLines = indentString(colors.log(log), 6); + const logLinesWithLeadingFigure = logLines.replace( + /^ {6}/, + ` ${colors.information(figures.info)} ` + ); + + status += logLinesWithLeadingFigure + '\n'; + }); + + status += '\n'; + } + if (test.error.source) { status += ' ' + colors.errorSource(test.error.source.file + ':' + test.error.source.line) + '\n'; @@ -191,9 +216,9 @@ class MiniReporter { } if (test.error.stack) { - const extracted = extractStack(test.error.stack); - if (extracted.includes('\n')) { - status += '\n' + indentString(colors.errorStack(extracted), 2) + '\n'; + const stack = test.error.stack; + if (stack.includes('\n')) { + status += '\n' + indentString(colors.errorStack(stack), 2) + '\n'; } } @@ -212,14 +237,14 @@ class MiniReporter { status += ' ' + colors.error(cross + ' ' + err.message) + '\n\n'; } else { const title = err.type === 'rejection' ? 'Unhandled Rejection' : 'Uncaught Exception'; - let description = err.stack ? err.stack.trimRight() : JSON.stringify(err); - description = description.split('\n'); - const errorTitle = err.name ? description[0] : 'Threw non-error: ' + description[0]; - const errorStack = description.slice(1).join('\n'); - status += ' ' + colors.title(title) + '\n'; - status += ' ' + colors.stack(errorTitle) + '\n'; - status += colors.errorStack(errorStack) + '\n\n'; + + if (err.name) { + status += ' ' + colors.stack(err.summary) + '\n'; + status += colors.errorStack(err.stack) + '\n\n'; + } else { + status += ' Threw non-error: ' + err.summary + '\n'; + } } }); } @@ -235,24 +260,30 @@ class MiniReporter { return '\n' + trimOffNewlines(status) + '\n'; } + section() { return '\n' + chalk.gray.dim('\u2500'.repeat(process.stdout.columns || 80)); } + clear() { return ''; } + write(str) { cliCursor.hide(); this.currentStatus = str; this._update(); this.statusLineCount = this.currentStatus.split('\n').length; } + stdout(data) { this._update(data); } + stderr(data) { this._update(data); } + _update(data) { let str = ''; let ct = this.statusLineCount; diff --git a/node_modules/ava/lib/reporters/tap.js b/node_modules/ava/lib/reporters/tap.js index 37c2cfd95..5ef8a23e3 100644 --- a/node_modules/ava/lib/reporters/tap.js +++ b/node_modules/ava/lib/reporters/tap.js @@ -3,12 +3,6 @@ const format = require('util').format; const indentString = require('indent-string'); const stripAnsi = require('strip-ansi'); const yaml = require('js-yaml'); -const extractStack = require('../extract-stack'); - -// Parses stack trace and extracts original function name, file name and line -function getSourceFromStack(stack) { - return extractStack(stack).split('\n')[0]; -} function dumpError(error, includeMessage) { const obj = Object.assign({}, error.object); @@ -35,7 +29,7 @@ function dumpError(error, includeMessage) { } if (error.stack) { - obj.at = getSourceFromStack(error.stack); + obj.at = error.stack.split('\n')[0]; } return ` ---\n${indentString(yaml.safeDump(obj).trim(), 4)}\n ...`; @@ -45,11 +39,13 @@ class TapReporter { constructor() { this.i = 0; } + start() { return 'TAP version 13'; } + test(test) { - let output; + const output = []; let directive = ''; const passed = test.todo ? 'not ok' : 'ok'; @@ -62,21 +58,34 @@ class TapReporter { const title = stripAnsi(test.title); + const appendLogs = () => { + if (test.logs) { + test.logs.forEach(log => { + const logLines = indentString(log, 4); + const logLinesWithLeadingFigure = logLines.replace( + /^ {4}/, + ' * ' + ); + + output.push(logLinesWithLeadingFigure); + }); + } + }; + + output.push(`# ${title}`); + if (test.error) { - output = [ - '# ' + title, - format('not ok %d - %s', ++this.i, title), - dumpError(test.error, true) - ]; + output.push(format('not ok %d - %s', ++this.i, title)); + appendLogs(); + output.push(dumpError(test.error, true)); } else { - output = [ - `# ${title}`, - format('%s %d - %s %s', passed, ++this.i, title, directive).trim() - ]; + output.push(format('%s %d - %s %s', passed, ++this.i, title, directive).trim()); + appendLogs(); } return output.join('\n'); } + unhandledError(err) { const output = [ `# ${err.message}`, @@ -89,6 +98,7 @@ class TapReporter { return output.join('\n'); } + finish(runStatus) { const output = [ '', @@ -105,12 +115,15 @@ class TapReporter { return output.join('\n'); } + write(str) { console.log(str); } + stdout(data) { process.stderr.write(data); } + stderr(data) { this.stdout(data); } diff --git a/node_modules/ava/lib/reporters/verbose.js b/node_modules/ava/lib/reporters/verbose.js index cd47683e8..c58d8db3b 100644 --- a/node_modules/ava/lib/reporters/verbose.js +++ b/node_modules/ava/lib/reporters/verbose.js @@ -5,7 +5,6 @@ const figures = require('figures'); const chalk = require('chalk'); const plur = require('plur'); const trimOffNewlines = require('trim-off-newlines'); -const extractStack = require('../extract-stack'); const codeExcerpt = require('../code-excerpt'); const colors = require('../colors'); const formatSerializedError = require('./format-serialized-error'); @@ -20,34 +19,46 @@ class VerboseReporter { colors[key].enabled = this.options.color; } } + start() { return ''; } + test(test, runStatus) { + const lines = []; if (test.error) { - return ' ' + colors.error(figures.cross) + ' ' + test.title + ' ' + colors.error(test.error.message); - } - - if (test.todo) { - return ' ' + colors.todo('- ' + test.title); + lines.push(' ' + colors.error(figures.cross) + ' ' + test.title + ' ' + colors.error(test.error.message)); + } else if (test.todo) { + lines.push(' ' + colors.todo('- ' + test.title)); } else if (test.skip) { - return ' ' + colors.skip('- ' + test.title); - } + lines.push(' ' + colors.skip('- ' + test.title)); + } else if (test.failing) { + lines.push(' ' + colors.error(figures.tick) + ' ' + colors.error(test.title)); + } else if (runStatus.fileCount === 1 && runStatus.testCount === 1 && test.title === '[anonymous]') { + // No output + } else { + // Display duration only over a threshold + const threshold = 100; + const duration = test.duration > threshold ? colors.duration(' (' + prettyMs(test.duration) + ')') : ''; - if (test.failing) { - return ' ' + colors.error(figures.tick) + ' ' + colors.error(test.title); + lines.push(' ' + colors.pass(figures.tick) + ' ' + test.title + duration); } - if (runStatus.fileCount === 1 && runStatus.testCount === 1 && test.title === '[anonymous]') { - return undefined; - } + if (test.logs) { + test.logs.forEach(log => { + const logLines = indentString(colors.log(log), 6); + const logLinesWithLeadingFigure = logLines.replace( + /^ {6}/, + ` ${colors.information(figures.info)} ` + ); - // Display duration only over a threshold - const threshold = 100; - const duration = test.duration > threshold ? colors.duration(' (' + prettyMs(test.duration) + ')') : ''; + lines.push(logLinesWithLeadingFigure); + }); + } - return ' ' + colors.pass(figures.tick) + ' ' + test.title + duration; + return lines.length > 0 ? lines.join('\n') : undefined; } + unhandledError(err) { if (err.type === 'exception' && err.name === 'AvaError') { return colors.error(' ' + figures.cross + ' ' + err.message); @@ -61,6 +72,7 @@ class VerboseReporter { let output = colors.error(types[err.type] + ':', err.file) + '\n'; if (err.stack) { + output += ' ' + colors.stack(err.title || err.summary) + '\n'; output += ' ' + colors.stack(err.stack) + '\n'; } else { output += ' ' + colors.stack(JSON.stringify(err)) + '\n'; @@ -70,6 +82,7 @@ class VerboseReporter { return output; } + finish(runStatus) { let output = ''; @@ -86,7 +99,9 @@ class VerboseReporter { ].filter(Boolean); if (lines.length > 0) { - lines[0] += ' ' + chalk.gray.dim('[' + new Date().toLocaleTimeString('en-US', {hour12: false}) + ']'); + if (this.options.watching) { + lines[0] += ' ' + chalk.gray.dim('[' + new Date().toLocaleTimeString('en-US', {hour12: false}) + ']'); + } output += lines.join('\n') + '\n'; } @@ -104,6 +119,21 @@ class VerboseReporter { } output += ' ' + colors.title(test.title) + '\n'; + + if (test.logs) { + test.logs.forEach(log => { + const logLines = indentString(colors.log(log), 6); + const logLinesWithLeadingFigure = logLines.replace( + /^ {6}/, + ` ${colors.information(figures.info)} ` + ); + + output += logLinesWithLeadingFigure + '\n'; + }); + + output += '\n'; + } + if (test.error.source) { output += ' ' + colors.errorSource(test.error.source.file + ':' + test.error.source.line) + '\n'; @@ -132,9 +162,9 @@ class VerboseReporter { } if (test.error.stack) { - const extracted = extractStack(test.error.stack); - if (extracted.includes('\n')) { - output += '\n' + indentString(colors.errorStack(extracted), 2) + '\n'; + const stack = test.error.stack; + if (stack.includes('\n')) { + output += '\n' + indentString(colors.errorStack(stack), 2) + '\n'; } } @@ -153,15 +183,19 @@ class VerboseReporter { return '\n' + trimOffNewlines(output) + '\n'; } + section() { return chalk.gray.dim('\u2500'.repeat(process.stdout.columns || 80)); } + write(str) { console.error(str); } + stdout(data) { process.stderr.write(data); } + stderr(data) { process.stderr.write(data); } |