Skip to content

Commit

Permalink
feat: display error in test suite itself
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Nov 13, 2017
1 parent 3f81383 commit d921d73
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
1 change: 1 addition & 0 deletions demo/broken.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
throw new Error('Error in test suite itself, reporter should report it properly.');
4 changes: 2 additions & 2 deletions src/LineWriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class LineWriter {
};
const pushTraceLine = (line) => push(chalk` {grey ${line}}`);
const pushTraceLineDim = (line) => pushTraceLine(chalk`{dim ${line}}`);
const pushCodeFrameLine = (line) => push(' ' + line);
const pushCodeFrameLine = (line) => push(' ' + line);

let firstLineFormatted = firstLine;

Expand Down Expand Up @@ -256,7 +256,7 @@ class LineWriter {
push(' ' + line);
break;
case 'difference':
push(' ' + line);
push(' ' + line.trim());
break;
default:
push(line);
Expand Down
23 changes: 13 additions & 10 deletions src/TapReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,23 @@ class TapReporter {
}
}

onTestResult (contexts, suite) {
const {testResults, testFilePath, numFailingTests} = suite;
onTestResult (test, testResult) {
const {testExecError, testResults, testFilePath, numFailingTests} = testResult;
const {dir, base} = path.parse(testFilePath);
const suiteFailed = Boolean(testExecError);

if (testFilePath) {
const {dir, base} = path.parse(testFilePath);

if (!this.globalConfig.watch) {
this.writer.blank();
}
this.writer.suite(numFailingTests > 0, dir, base);
if (!this.globalConfig.watch) {
this.writer.blank();
}
this.writer.suite(numFailingTests > 0 || suiteFailed, dir, base);
this.writer.blank();

testResults.forEach(this.onAssertionResult);
// If error in test suite itself.
if (suiteFailed) {
this.writer.errors([testExecError.stack]);
} else {
testResults.forEach(this.onAssertionResult);
}
}

onRunStart (results, options) {
Expand Down

0 comments on commit d921d73

Please sign in to comment.