Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print todo and skip descriptions when in verbose mode #8038

Merged
merged 12 commits into from
Mar 19, 2019
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
SimenB marked this conversation as resolved.
Show resolved Hide resolved

● fails

Expand Down
7 changes: 7 additions & 0 deletions e2e/__tests__/testTodo.test.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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<TestResult.AssertionResult>;
todo: Array<TestResult.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: TestResult.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