aboutsummaryrefslogtreecommitdiff
path: root/node_modules/ava/lib/reporters
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/ava/lib/reporters')
-rw-r--r--node_modules/ava/lib/reporters/format-serialized-error.js26
-rw-r--r--node_modules/ava/lib/reporters/improper-usage-messages.js43
-rw-r--r--node_modules/ava/lib/reporters/mini.js76
-rw-r--r--node_modules/ava/lib/reporters/verbose.js41
4 files changed, 117 insertions, 69 deletions
diff --git a/node_modules/ava/lib/reporters/format-serialized-error.js b/node_modules/ava/lib/reporters/format-serialized-error.js
new file mode 100644
index 000000000..6ab59e47c
--- /dev/null
+++ b/node_modules/ava/lib/reporters/format-serialized-error.js
@@ -0,0 +1,26 @@
+'use strict';
+const chalk = require('chalk');
+const trimOffNewlines = require('trim-off-newlines');
+
+function formatSerializedError(error) {
+ const printMessage = error.values.length === 0 ?
+ Boolean(error.message) :
+ !error.values[0].label.startsWith(error.message);
+
+ if (error.statements.length === 0 && error.values.length === 0) {
+ return {formatted: null, printMessage};
+ }
+
+ let formatted = '';
+ for (const value of error.values) {
+ formatted += `${value.label}\n\n${trimOffNewlines(value.formatted)}\n\n`;
+ }
+
+ for (const statement of error.statements) {
+ formatted += `${statement[0]}\n${chalk.grey('=>')} ${trimOffNewlines(statement[1])}\n\n`;
+ }
+
+ formatted = trimOffNewlines(formatted);
+ return {formatted, printMessage};
+}
+module.exports = formatSerializedError;
diff --git a/node_modules/ava/lib/reporters/improper-usage-messages.js b/node_modules/ava/lib/reporters/improper-usage-messages.js
index 0a2626638..298ef79a5 100644
--- a/node_modules/ava/lib/reporters/improper-usage-messages.js
+++ b/node_modules/ava/lib/reporters/improper-usage-messages.js
@@ -7,15 +7,48 @@ exports.forError = error => {
}
const assertion = error.assertion;
- if (assertion !== 'throws' || !assertion === 'notThrows') {
- return null;
- }
-
- return `Try wrapping the first argument to \`t.${assertion}()\` in a function:
+ if (assertion === 'throws' || assertion === 'notThrows') {
+ return `Try wrapping the first argument to \`t.${assertion}()\` in a function:
${chalk.cyan(`t.${assertion}(() => { `)}${chalk.grey('/* your code here */')}${chalk.cyan(' })')}
Visit the following URL for more details:
${chalk.blue.underline('https://github.com/avajs/ava#throwsfunctionpromise-error-message')}`;
+ } else if (assertion === 'snapshot') {
+ const name = error.improperUsage.name;
+ const snapPath = error.improperUsage.snapPath;
+
+ if (name === 'ChecksumError') {
+ return `The snapshot file is corrupted.
+
+File path: ${chalk.yellow(snapPath)}
+
+Please run AVA again with the ${chalk.cyan('--update-snapshots')} flag to recreate it.`;
+ }
+
+ if (name === 'LegacyError') {
+ return `The snapshot file was created with AVA 0.19. It's not supported by this AVA version.
+
+File path: ${chalk.yellow(snapPath)}
+
+Please run AVA again with the ${chalk.cyan('--update-snapshots')} flag to upgrade.`;
+ }
+
+ if (name === 'VersionMismatchError') {
+ const snapVersion = error.improperUsage.snapVersion;
+ const expectedVersion = error.improperUsage.expectedVersion;
+ const upgradeMessage = snapVersion < expectedVersion ?
+ `Please run AVA again with the ${chalk.cyan('--update-snapshots')} flag to upgrade.` :
+ 'You should upgrade AVA.';
+
+ return `The snapshot file is v${snapVersion}, but only v${expectedVersion} is supported.
+
+File path: ${chalk.yellow(snapPath)}
+
+${upgradeMessage}`;
+ }
+ }
+
+ return null;
};
diff --git a/node_modules/ava/lib/reporters/mini.js b/node_modules/ava/lib/reporters/mini.js
index df481a76a..8acfab8e7 100644
--- a/node_modules/ava/lib/reporters/mini.js
+++ b/node_modules/ava/lib/reporters/mini.js
@@ -8,33 +8,14 @@ const chalk = require('chalk');
const cliTruncate = require('cli-truncate');
const cross = require('figures').cross;
const indentString = require('indent-string');
-const formatAssertError = require('../format-assert-error');
+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');
const improperUsageMessages = require('./improper-usage-messages');
-// TODO(@jamestalamge): This should be fixed in log-update and ansi-escapes once we are confident it's a good solution.
-const CSI = '\u001B[';
-const ERASE_LINE = CSI + '2K';
-const CURSOR_TO_COLUMN_0 = CSI + '0G';
-const CURSOR_UP = CSI + '1A';
-
-// Returns a string that will erase `count` lines from the end of the terminal.
-function eraseLines(count) {
- let clear = '';
-
- for (let i = 0; i < count; i++) {
- clear += ERASE_LINE + (i < count - 1 ? CURSOR_UP : '');
- }
-
- if (count) {
- clear += CURSOR_TO_COLUMN_0;
- }
-
- return clear;
-}
-
class MiniReporter {
constructor(options) {
this.options = Object.assign({}, options);
@@ -151,38 +132,37 @@ class MiniReporter {
time = chalk.gray.dim('[' + new Date().toLocaleTimeString('en-US', {hour12: false}) + ']');
}
- let status = this.reportCounts(time);
+ let status = this.reportCounts(time) + '\n';
if (this.rejectionCount > 0) {
- status += '\n ' + colors.error(this.rejectionCount, plur('rejection', this.rejectionCount));
+ status += ' ' + colors.error(this.rejectionCount, plur('rejection', this.rejectionCount)) + '\n';
}
if (this.exceptionCount > 0) {
- status += '\n ' + colors.error(this.exceptionCount, plur('exception', this.exceptionCount));
+ status += ' ' + colors.error(this.exceptionCount, plur('exception', this.exceptionCount)) + '\n';
}
if (runStatus.previousFailCount > 0) {
- status += '\n ' + colors.error(runStatus.previousFailCount, 'previous', plur('failure', runStatus.previousFailCount), 'in test files that were not rerun');
+ status += ' ' + colors.error(runStatus.previousFailCount, 'previous', plur('failure', runStatus.previousFailCount), 'in test files that were not rerun') + '\n';
}
if (this.knownFailureCount > 0) {
for (const test of runStatus.knownFailures) {
const title = test.title;
- status += '\n\n ' + colors.title(title);
+ status += '\n ' + colors.title(title) + '\n';
// TODO: Output description with link
// status += colors.stack(description);
}
}
+ status += '\n';
if (this.failCount > 0) {
- runStatus.errors.forEach((test, index) => {
+ runStatus.errors.forEach(test => {
if (!test.error) {
return;
}
- const beforeSpacing = index === 0 ? '\n\n' : '\n\n\n\n';
-
- status += beforeSpacing + ' ' + colors.title(test.title) + '\n';
+ status += ' ' + colors.title(test.title) + '\n';
if (test.error.source) {
status += ' ' + colors.errorSource(test.error.source.file + ':' + test.error.source.line) + '\n';
@@ -192,28 +172,32 @@ class MiniReporter {
}
}
- if (test.error.message) {
- status += '\n' + indentString(test.error.message, 2) + '\n';
- }
-
if (test.error.avaAssertionError) {
- const formatted = formatAssertError.formatSerializedError(test.error);
- if (formatted) {
- status += '\n' + indentString(formatted, 2);
+ const result = formatSerializedError(test.error);
+ if (result.printMessage) {
+ status += '\n' + indentString(test.error.message, 2) + '\n';
+ }
+
+ if (result.formatted) {
+ status += '\n' + indentString(result.formatted, 2) + '\n';
}
const message = improperUsageMessages.forError(test.error);
if (message) {
status += '\n' + indentString(message, 2) + '\n';
}
+ } else if (test.error.message) {
+ status += '\n' + indentString(test.error.message, 2) + '\n';
}
if (test.error.stack) {
const extracted = extractStack(test.error.stack);
if (extracted.includes('\n')) {
- status += '\n' + indentString(colors.errorStack(extracted), 2);
+ status += '\n' + indentString(colors.errorStack(extracted), 2) + '\n';
}
}
+
+ status += '\n\n\n';
});
}
@@ -225,7 +209,7 @@ class MiniReporter {
}
if (err.type === 'exception' && err.name === 'AvaError') {
- status += '\n\n ' + colors.error(cross + ' ' + err.message);
+ 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);
@@ -233,23 +217,23 @@ class MiniReporter {
const errorTitle = err.name ? description[0] : 'Threw non-error: ' + description[0];
const errorStack = description.slice(1).join('\n');
- status += '\n\n ' + colors.title(title) + '\n';
+ status += ' ' + colors.title(title) + '\n';
status += ' ' + colors.stack(errorTitle) + '\n';
- status += colors.errorStack(errorStack);
+ status += colors.errorStack(errorStack) + '\n\n';
}
});
}
if (runStatus.failFastEnabled === true && runStatus.remainingCount > 0 && runStatus.failCount > 0) {
const remaining = 'At least ' + runStatus.remainingCount + ' ' + plur('test was', 'tests were', runStatus.remainingCount) + ' skipped.';
- status += '\n\n ' + colors.information('`--fail-fast` is on. ' + remaining);
+ status += ' ' + colors.information('`--fail-fast` is on. ' + remaining) + '\n\n';
}
if (runStatus.hasExclusive === true && runStatus.remainingCount > 0) {
- status += '\n\n ' + colors.information('The .only() modifier is used in some tests.', runStatus.remainingCount, plur('test', runStatus.remainingCount), plur('was', 'were', runStatus.remainingCount), 'not run');
+ status += ' ' + colors.information('The .only() modifier is used in some tests.', runStatus.remainingCount, plur('test', runStatus.remainingCount), plur('was', 'were', runStatus.remainingCount), 'not run');
}
- return status + '\n\n';
+ return '\n' + trimOffNewlines(status) + '\n';
}
section() {
return '\n' + chalk.gray.dim('\u2500'.repeat(process.stdout.columns || 80));
@@ -284,7 +268,7 @@ class MiniReporter {
}
// Erase the existing status message, plus the last log line.
- str += eraseLines(ct);
+ str += ansiEscapes.eraseLines(ct);
// Rewrite the last log line.
str += lastLine;
diff --git a/node_modules/ava/lib/reporters/verbose.js b/node_modules/ava/lib/reporters/verbose.js
index 1be43ce5e..cd47683e8 100644
--- a/node_modules/ava/lib/reporters/verbose.js
+++ b/node_modules/ava/lib/reporters/verbose.js
@@ -4,10 +4,11 @@ const prettyMs = require('pretty-ms');
const figures = require('figures');
const chalk = require('chalk');
const plur = require('plur');
-const formatAssertError = require('../format-assert-error');
+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');
const improperUsageMessages = require('./improper-usage-messages');
class VerboseReporter {
@@ -70,7 +71,7 @@ class VerboseReporter {
return output;
}
finish(runStatus) {
- let output = '\n';
+ let output = '';
const lines = [
runStatus.failCount > 0 ?
@@ -86,23 +87,23 @@ class VerboseReporter {
if (lines.length > 0) {
lines[0] += ' ' + chalk.gray.dim('[' + new Date().toLocaleTimeString('en-US', {hour12: false}) + ']');
- output += lines.join('\n');
+ output += lines.join('\n') + '\n';
}
if (runStatus.knownFailureCount > 0) {
runStatus.knownFailures.forEach(test => {
- output += '\n\n\n ' + colors.error(test.title);
+ output += '\n\n ' + colors.error(test.title) + '\n';
});
}
+ output += '\n';
if (runStatus.failCount > 0) {
- runStatus.tests.forEach((test, index) => {
+ runStatus.tests.forEach(test => {
if (!test.error) {
return;
}
- const beforeSpacing = index === 0 ? '\n\n' : '\n\n\n\n';
- output += beforeSpacing + ' ' + colors.title(test.title) + '\n';
+ output += ' ' + colors.title(test.title) + '\n';
if (test.error.source) {
output += ' ' + colors.errorSource(test.error.source.file + ':' + test.error.source.line) + '\n';
@@ -112,41 +113,45 @@ class VerboseReporter {
}
}
- if (test.error.message) {
- output += '\n' + indentString(test.error.message, 2) + '\n';
- }
-
if (test.error.avaAssertionError) {
- const formatted = formatAssertError.formatSerializedError(test.error);
- if (formatted) {
- output += '\n' + indentString(formatted, 2);
+ const result = formatSerializedError(test.error);
+ if (result.printMessage) {
+ output += '\n' + indentString(test.error.message, 2) + '\n';
+ }
+
+ if (result.formatted) {
+ output += '\n' + indentString(result.formatted, 2) + '\n';
}
const message = improperUsageMessages.forError(test.error);
if (message) {
output += '\n' + indentString(message, 2) + '\n';
}
+ } else if (test.error.message) {
+ output += '\n' + indentString(test.error.message, 2) + '\n';
}
if (test.error.stack) {
const extracted = extractStack(test.error.stack);
if (extracted.includes('\n')) {
- output += '\n' + indentString(colors.errorStack(extracted), 2);
+ output += '\n' + indentString(colors.errorStack(extracted), 2) + '\n';
}
}
+
+ output += '\n\n\n';
});
}
if (runStatus.failFastEnabled === true && runStatus.remainingCount > 0 && runStatus.failCount > 0) {
const remaining = 'At least ' + runStatus.remainingCount + ' ' + plur('test was', 'tests were', runStatus.remainingCount) + ' skipped.';
- output += '\n\n\n ' + colors.information('`--fail-fast` is on. ' + remaining);
+ output += ' ' + colors.information('`--fail-fast` is on. ' + remaining) + '\n\n';
}
if (runStatus.hasExclusive === true && runStatus.remainingCount > 0) {
- output += '\n\n\n ' + colors.information('The .only() modifier is used in some tests.', runStatus.remainingCount, plur('test', runStatus.remainingCount), plur('was', 'were', runStatus.remainingCount), 'not run');
+ output += ' ' + colors.information('The .only() modifier is used in some tests.', runStatus.remainingCount, plur('test', runStatus.remainingCount), plur('was', 'were', runStatus.remainingCount), 'not run');
}
- return output + '\n';
+ return '\n' + trimOffNewlines(output) + '\n';
}
section() {
return chalk.gray.dim('\u2500'.repeat(process.stdout.columns || 80));