Skip to content

Commit 246da7f

Browse files
acamposruizcpojer
authored andcommitted
Print errors after test structure in verbose mode (#4504)
* Issue 4264: print errors after test structure in verbose mode * Fix lint (#4504)) * Skip test on windows
1 parent afb69f7 commit 246da7f

File tree

4 files changed

+89
-60
lines changed

4 files changed

+89
-60
lines changed

integration_tests/__tests__/__snapshots__/failures.test.js.snap

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ exports[`not throwing Error objects 3`] = `
3030

3131
exports[`not throwing Error objects 4`] = `
3232
"FAIL __tests__/assertion_count.test.js
33+
.assertions()
34+
✕ throws
35+
✕ throws on redeclare of assertion count
36+
✕ throws on assertion
37+
.hasAssertions()
38+
✕ throws when there are not assertions
3339
● .assertions() › throws
3440
expect(received).toBeTruthy()
3541
Expected value to be truthy, instead received
@@ -49,17 +55,28 @@ exports[`not throwing Error objects 4`] = `
4955
● .hasAssertions() › throws when there are not assertions
5056
expect.hasAssertions()
5157
Expected at least one assertion to be called but received none.
52-
.assertions()
53-
✕ throws
54-
✕ throws on redeclare of assertion count
55-
✕ throws on assertion
56-
.hasAssertions()
57-
✕ throws when there are not assertions
5858
"
5959
`;
6060

6161
exports[`works with node assert 1`] = `
6262
"FAIL __tests__/node_assertion_error.test.js
63+
✕ assert
64+
✕ assert with a message
65+
✕ assert.ok
66+
✕ assert.ok with a message
67+
✕ assert.equal
68+
✕ assert.notEqual
69+
✕ assert.deepEqual
70+
✕ assert.deepEqual with a message
71+
✕ assert.notDeepEqual
72+
✕ assert.strictEqual
73+
✕ assert.notStrictEqual
74+
✕ assert.deepStrictEqual
75+
✕ assert.notDeepStrictEqual
76+
✕ assert.ifError
77+
✕ assert.doesNotThrow
78+
✕ assert.throws
79+
6380
● assert
6481
6582
assert.equal(received, expected) or assert(received)
@@ -299,22 +316,5 @@ exports[`works with node assert 1`] = `
299316
300317
at __tests__/node_assertion_error.test.js:78:10
301318
302-
✕ assert
303-
✕ assert with a message
304-
✕ assert.ok
305-
✕ assert.ok with a message
306-
✕ assert.equal
307-
✕ assert.notEqual
308-
✕ assert.deepEqual
309-
✕ assert.deepEqual with a message
310-
✕ assert.notDeepEqual
311-
✕ assert.strictEqual
312-
✕ assert.notStrictEqual
313-
✕ assert.deepStrictEqual
314-
✕ assert.notDeepStrictEqual
315-
✕ assert.ifError
316-
✕ assert.doesNotThrow
317-
✕ assert.throws
318-
319319
"
320320
`;

packages/expect/src/__tests__/assertion_counts.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

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

14+
const skipOnWindows = require('../../../../scripts/skip_on_windows');
15+
1416
describe('.assertions()', () => {
1517
it('does not throw', () => {
1618
jestExpect.assertions(2);
@@ -30,6 +32,7 @@ describe('.assertions()', () => {
3032
});
3133

3234
describe('.hasAssertions()', () => {
35+
skipOnWindows.suite();
3336
it('does not throw if there is an assertion', () => {
3437
jestExpect.hasAssertions();
3538
jestExpect('a').toBe('a');

packages/jest-cli/src/reporters/default_reporter.js

Lines changed: 47 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -155,48 +155,61 @@ export default class DefaultReporter extends BaseReporter {
155155
testResult: TestResult,
156156
aggregatedResults: AggregatedResult,
157157
) {
158-
this._status.testFinished(
159-
test.context.config,
160-
testResult,
161-
aggregatedResults,
162-
);
163-
this._printTestFileSummary(
164-
testResult.testFilePath,
165-
test.context.config,
166-
testResult,
167-
);
158+
this.testFinished(test.context.config, testResult, aggregatedResults);
159+
if (!testResult.skipped) {
160+
this.printTestFileHeader(
161+
testResult.testFilePath,
162+
test.context.config,
163+
testResult,
164+
);
165+
this.printTestFileFailureMessage(
166+
testResult.testFilePath,
167+
test.context.config,
168+
testResult,
169+
);
170+
}
168171
this.forceFlushBufferedOutput();
169172
}
170173

171-
_printTestFileSummary(
174+
testFinished(
175+
config: ProjectConfig,
176+
testResult: TestResult,
177+
aggregatedResults: AggregatedResult,
178+
) {
179+
this._status.testFinished(config, testResult, aggregatedResults);
180+
}
181+
182+
printTestFileHeader(
172183
testPath: Path,
173184
config: ProjectConfig,
174185
result: TestResult,
175186
) {
176-
if (!result.skipped) {
177-
this.log(getResultHeader(result, this._globalConfig, config));
178-
179-
const consoleBuffer = result.console;
180-
if (consoleBuffer && consoleBuffer.length) {
181-
this.log(
182-
' ' +
183-
TITLE_BULLET +
184-
'Console\n\n' +
185-
getConsoleOutput(
186-
config.cwd,
187-
!!this._globalConfig.verbose,
188-
consoleBuffer,
189-
),
190-
);
191-
}
192-
193-
if (result.failureMessage) {
194-
this.log(result.failureMessage);
195-
}
187+
this.log(getResultHeader(result, this._globalConfig, config));
188+
const consoleBuffer = result.console;
189+
if (consoleBuffer && consoleBuffer.length) {
190+
this.log(
191+
' ' +
192+
TITLE_BULLET +
193+
'Console\n\n' +
194+
getConsoleOutput(
195+
config.cwd,
196+
!!this._globalConfig.verbose,
197+
consoleBuffer,
198+
),
199+
);
200+
}
201+
}
196202

197-
const didUpdate = this._globalConfig.updateSnapshot === 'all';
198-
const snapshotStatuses = getSnapshotStatus(result.snapshot, didUpdate);
199-
snapshotStatuses.forEach(this.log);
203+
printTestFileFailureMessage(
204+
testPath: Path,
205+
config: ProjectConfig,
206+
result: TestResult,
207+
) {
208+
if (result.failureMessage) {
209+
this.log(result.failureMessage);
200210
}
211+
const didUpdate = this._globalConfig.updateSnapshot === 'all';
212+
const snapshotStatuses = getSnapshotStatus(result.snapshot, didUpdate);
213+
snapshotStatuses.forEach(this.log);
201214
}
202215
}

packages/jest-cli/src/reporters/verbose_reporter.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,23 @@ export default class VerboseReporter extends DefaultReporter {
5959
result: TestResult,
6060
aggregatedResults: AggregatedResult,
6161
) {
62-
super.onTestResult(test, result, aggregatedResults);
63-
if (!result.testExecError && !result.skipped) {
64-
this._logTestResults(result.testResults);
62+
super.testFinished(test.context.config, result, aggregatedResults);
63+
if (!result.skipped) {
64+
this.printTestFileHeader(
65+
result.testFilePath,
66+
test.context.config,
67+
result,
68+
);
69+
if (!result.testExecError && !result.skipped) {
70+
this._logTestResults(result.testResults);
71+
}
72+
this.printTestFileFailureMessage(
73+
result.testFilePath,
74+
test.context.config,
75+
result,
76+
);
6577
}
78+
super.forceFlushBufferedOutput();
6679
}
6780

6881
_logTestResults(testResults: Array<AssertionResult>) {

0 commit comments

Comments
 (0)