Skip to content

Commit

Permalink
Print errors after test structure in verbose mode (#4504)
Browse files Browse the repository at this point in the history
* Issue 4264: print errors after test structure in verbose mode

* Fix lint (#4504))

* Skip test on windows
  • Loading branch information
acamposruiz authored and cpojer committed Sep 19, 2017
1 parent afb69f7 commit 246da7f
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 60 deletions.
46 changes: 23 additions & 23 deletions integration_tests/__tests__/__snapshots__/failures.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ exports[`not throwing Error objects 3`] = `

exports[`not throwing Error objects 4`] = `
"FAIL __tests__/assertion_count.test.js
.assertions()
✕ throws
✕ throws on redeclare of assertion count
✕ throws on assertion
.hasAssertions()
✕ throws when there are not assertions
● .assertions() › throws
expect(received).toBeTruthy()
Expected value to be truthy, instead received
Expand All @@ -49,17 +55,28 @@ exports[`not throwing Error objects 4`] = `
● .hasAssertions() › throws when there are not assertions
expect.hasAssertions()
Expected at least one assertion to be called but received none.
.assertions()
✕ throws
✕ throws on redeclare of assertion count
✕ throws on assertion
.hasAssertions()
✕ throws when there are not assertions
"
`;

exports[`works with node assert 1`] = `
"FAIL __tests__/node_assertion_error.test.js
✕ assert
✕ assert with a message
✕ assert.ok
✕ assert.ok with a message
✕ assert.equal
✕ assert.notEqual
✕ assert.deepEqual
✕ assert.deepEqual with a message
✕ assert.notDeepEqual
✕ assert.strictEqual
✕ assert.notStrictEqual
✕ assert.deepStrictEqual
✕ assert.notDeepStrictEqual
✕ assert.ifError
✕ assert.doesNotThrow
✕ assert.throws
● assert
assert.equal(received, expected) or assert(received)
Expand Down Expand Up @@ -299,22 +316,5 @@ exports[`works with node assert 1`] = `
at __tests__/node_assertion_error.test.js:78:10
✕ assert
✕ assert with a message
✕ assert.ok
✕ assert.ok with a message
✕ assert.equal
✕ assert.notEqual
✕ assert.deepEqual
✕ assert.deepEqual with a message
✕ assert.notDeepEqual
✕ assert.strictEqual
✕ assert.notStrictEqual
✕ assert.deepStrictEqual
✕ assert.notDeepStrictEqual
✕ assert.ifError
✕ assert.doesNotThrow
✕ assert.throws
"
`;
3 changes: 3 additions & 0 deletions packages/expect/src/__tests__/assertion_counts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

const jestExpect = require('../');

const skipOnWindows = require('../../../../scripts/skip_on_windows');

describe('.assertions()', () => {
it('does not throw', () => {
jestExpect.assertions(2);
Expand All @@ -30,6 +32,7 @@ describe('.assertions()', () => {
});

describe('.hasAssertions()', () => {
skipOnWindows.suite();
it('does not throw if there is an assertion', () => {
jestExpect.hasAssertions();
jestExpect('a').toBe('a');
Expand Down
81 changes: 47 additions & 34 deletions packages/jest-cli/src/reporters/default_reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,48 +155,61 @@ export default class DefaultReporter extends BaseReporter {
testResult: TestResult,
aggregatedResults: AggregatedResult,
) {
this._status.testFinished(
test.context.config,
testResult,
aggregatedResults,
);
this._printTestFileSummary(
testResult.testFilePath,
test.context.config,
testResult,
);
this.testFinished(test.context.config, testResult, aggregatedResults);
if (!testResult.skipped) {
this.printTestFileHeader(
testResult.testFilePath,
test.context.config,
testResult,
);
this.printTestFileFailureMessage(
testResult.testFilePath,
test.context.config,
testResult,
);
}
this.forceFlushBufferedOutput();
}

_printTestFileSummary(
testFinished(
config: ProjectConfig,
testResult: TestResult,
aggregatedResults: AggregatedResult,
) {
this._status.testFinished(config, testResult, aggregatedResults);
}

printTestFileHeader(
testPath: Path,
config: ProjectConfig,
result: TestResult,
) {
if (!result.skipped) {
this.log(getResultHeader(result, this._globalConfig, config));

const consoleBuffer = result.console;
if (consoleBuffer && consoleBuffer.length) {
this.log(
' ' +
TITLE_BULLET +
'Console\n\n' +
getConsoleOutput(
config.cwd,
!!this._globalConfig.verbose,
consoleBuffer,
),
);
}

if (result.failureMessage) {
this.log(result.failureMessage);
}
this.log(getResultHeader(result, this._globalConfig, config));
const consoleBuffer = result.console;
if (consoleBuffer && consoleBuffer.length) {
this.log(
' ' +
TITLE_BULLET +
'Console\n\n' +
getConsoleOutput(
config.cwd,
!!this._globalConfig.verbose,
consoleBuffer,
),
);
}
}

const didUpdate = this._globalConfig.updateSnapshot === 'all';
const snapshotStatuses = getSnapshotStatus(result.snapshot, didUpdate);
snapshotStatuses.forEach(this.log);
printTestFileFailureMessage(
testPath: Path,
config: ProjectConfig,
result: TestResult,
) {
if (result.failureMessage) {
this.log(result.failureMessage);
}
const didUpdate = this._globalConfig.updateSnapshot === 'all';
const snapshotStatuses = getSnapshotStatus(result.snapshot, didUpdate);
snapshotStatuses.forEach(this.log);
}
}
19 changes: 16 additions & 3 deletions packages/jest-cli/src/reporters/verbose_reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,23 @@ export default class VerboseReporter extends DefaultReporter {
result: TestResult,
aggregatedResults: AggregatedResult,
) {
super.onTestResult(test, result, aggregatedResults);
if (!result.testExecError && !result.skipped) {
this._logTestResults(result.testResults);
super.testFinished(test.context.config, result, aggregatedResults);
if (!result.skipped) {
this.printTestFileHeader(
result.testFilePath,
test.context.config,
result,
);
if (!result.testExecError && !result.skipped) {
this._logTestResults(result.testResults);
}
this.printTestFileFailureMessage(
result.testFilePath,
test.context.config,
result,
);
}
super.forceFlushBufferedOutput();
}

_logTestResults(testResults: Array<AssertionResult>) {
Expand Down

0 comments on commit 246da7f

Please sign in to comment.