Skip to content

Commit

Permalink
Print todo and skip descriptions when in verbose mode (#8038)
Browse files Browse the repository at this point in the history
  • Loading branch information
natealcedo authored and SimenB committed Mar 19, 2019
1 parent 923bc50 commit 809ab98
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 37 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,8 @@

### Features

- `[@jest/reporter]` Display todo and skip test descriptions when verbose is true ([#8038](https://github.com/facebook/jest/pull/8038))

### Fixes

- `[jest-each]` Fix test function type ([#8145](https://github.com/facebook/jest/pull/8145))
Expand Down
15 changes: 11 additions & 4 deletions e2e/__tests__/__snapshots__/each.test.ts.snap
Expand Up @@ -38,7 +38,7 @@ PASS __tests__/describeOnly.test.js
✓ passes
✓ passes
fails all rows expected false == true
○ skipped 1 test
○ skipped fails
`;

exports[`shows error message when not enough arguments are supplied to tests 1`] = `
Expand Down Expand Up @@ -100,7 +100,10 @@ PASS __tests__/eachOnly.test.js
✓ passes one row expected true == true
✓ passes one row expected true == true
✓ passes one row expected true == true
○ skipped 4 tests
○ skipped Should not be ran: fails all rows expected true == false
○ skipped Should not be ran: fails all rows expected true == true
○ skipped Should not be ran: fails all rows expected true == false
○ skipped Should not be ran: fails all rows expected true == false
`;
exports[`shows only the tests without .skip as being ran 1`] = `
Expand All @@ -109,9 +112,13 @@ PASS __tests__/eachSkip.test.js
✓ passes one row expected true == true
✓ passes one row expected true == true
✓ passes one row expected true == true
○ skipped 4 tests
○ skipped Should not be ran: fails all rows expected true == false
○ skipped Should not be ran: fails all rows expected true == true
○ skipped Should not be ran: fails all rows expected true == false
○ skipped Should not be ran: fails all rows expected true == false
passes all rows expected true == true
○ skipped 2 tests
○ skipped passes
○ skipped passes
`;
exports[`shows the correct errors in stderr when failing tests 1`] = `
Expand Down
14 changes: 9 additions & 5 deletions e2e/__tests__/__snapshots__/globals.test.ts.snap
Expand Up @@ -106,7 +106,7 @@ PASS __tests__/onlyConstructs.test.js
✓ test.only
✓ it.only
✓ fit
○ skipped 1 test
○ skipped it
fdescribe
✓ it
✓ test
Expand Down Expand Up @@ -150,13 +150,17 @@ Ran all test suites.
exports[`skips 1`] = `
PASS __tests__/skipsConstructs.test.js
✓ it
○ skipped 4 tests
○ skipped xtest
○ skipped xit
○ skipped it.skip
○ skipped test.skip
xdescribe
○ skipped 2 tests
○ skipped it
○ skipped test
describe.skip
○ skipped 1 test
○ skipped test
describe
○ skipped 1 test
○ skipped test
`;
exports[`skips 2`] = `
Expand Down
12 changes: 10 additions & 2 deletions e2e/__tests__/__snapshots__/testTodo.test.ts.snap
Expand Up @@ -45,12 +45,20 @@ FAIL __tests__/todoNoArgs.test.js
at Object.todo (__tests__/todoNoArgs.test.js:8:4)
`;

exports[`shows todo messages when in verbose mode 1`] = `
PASS __tests__/verbose.test.js
todos in verbose reporter
✎ todo this
✎ todo should
✎ todo work
`;

exports[`works with all statuses 1`] = `
FAIL __tests__/statuses.test.js
✓ passes
✕ fails
○ skipped 1 test
✎ todo 1 test
○ skipped skips
✎ todo todo
● fails
Expand Down
7 changes: 7 additions & 0 deletions e2e/__tests__/testTodo.test.ts
Expand Up @@ -38,3 +38,10 @@ test('shows error messages when called with invalid argument', () => {
const {rest} = extractSummary(result.stderr);
expect(wrap(rest)).toMatchSnapshot();
});

test('shows todo messages when in verbose mode', () => {
const result = runJest(dir, ['verbose.test.js', '--verbose']);
expect(result.status).toBe(0);
const {rest} = extractSummary(result.stderr);
expect(wrap(rest)).toMatchSnapshot();
});
13 changes: 13 additions & 0 deletions e2e/test-todo/__tests__/verbose.test.js
@@ -0,0 +1,13 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';

describe('todos in verbose reporter', () => {
test.todo('this');
test.todo('should');
test.todo('work');
});
45 changes: 19 additions & 26 deletions packages/jest-reporters/src/verbose_reporter.ts
Expand Up @@ -115,49 +115,42 @@ export default class VerboseReporter extends DefaultReporter {
if (this._globalConfig.expand) {
tests.forEach(test => this._logTest(test, indentLevel));
} else {
const summedTests = tests.reduce(
const summedTests = tests.reduce<{
pending: Array<AssertionResult>;
todo: Array<AssertionResult>;
}>(
(result, test) => {
if (test.status === 'pending') {
result.pending += 1;
result.pending.push(test);
} else if (test.status === 'todo') {
result.todo += 1;
result.todo.push(test);
} else {
this._logTest(test, indentLevel);
}

return result;
},
{pending: 0, todo: 0},
{pending: [], todo: []},
);

if (summedTests.pending > 0) {
this._logSummedTests(
'skipped',
this._getIcon('pending'),
summedTests.pending,
indentLevel,
);
if (summedTests.pending.length > 0) {
summedTests.pending.forEach(this._logTodoOrPendingTest(indentLevel));
}

if (summedTests.todo > 0) {
this._logSummedTests(
'todo',
this._getIcon('todo'),
summedTests.todo,
indentLevel,
);
if (summedTests.todo.length > 0) {
summedTests.todo.forEach(this._logTodoOrPendingTest(indentLevel));
}
}
}

private _logSummedTests(
prefix: string,
icon: string,
count: number,
indentLevel: number,
) {
const text = chalk.dim(`${prefix} ${count} test${count === 1 ? '' : 's'}`);
this._logLine(`${icon} ${text}`, indentLevel);
private _logTodoOrPendingTest(indentLevel: number) {
return (test: AssertionResult) => {
const printedTestStatus =
test.status === 'pending' ? 'skipped' : test.status;
const icon = this._getIcon(test.status);
const text = chalk.dim(`${printedTestStatus} ${test.title}`);
this._logLine(`${icon} ${text}`, indentLevel);
};
}

private _logLine(str?: string, indentLevel?: number) {
Expand Down

0 comments on commit 809ab98

Please sign in to comment.