From 809ab9836491b247933101646253ba791b896dea Mon Sep 17 00:00:00 2001 From: Alcedo Nathaniel De Guzman Jr Date: Tue, 19 Mar 2019 19:46:47 +0800 Subject: [PATCH] Print todo and skip descriptions when in verbose mode (#8038) --- CHANGELOG.md | 2 + e2e/__tests__/__snapshots__/each.test.ts.snap | 15 +++++-- .../__snapshots__/globals.test.ts.snap | 14 +++--- .../__snapshots__/testTodo.test.ts.snap | 12 ++++- e2e/__tests__/testTodo.test.ts | 7 +++ e2e/test-todo/__tests__/verbose.test.js | 13 ++++++ .../jest-reporters/src/verbose_reporter.ts | 45 ++++++++----------- 7 files changed, 71 insertions(+), 37 deletions(-) create mode 100644 e2e/test-todo/__tests__/verbose.test.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 40d8f961af31..d2ac5ce1d9a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/e2e/__tests__/__snapshots__/each.test.ts.snap b/e2e/__tests__/__snapshots__/each.test.ts.snap index 20e373ef77d5..89d30dd34dba 100644 --- a/e2e/__tests__/__snapshots__/each.test.ts.snap +++ b/e2e/__tests__/__snapshots__/each.test.ts.snap @@ -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`] = ` @@ -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`] = ` @@ -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`] = ` diff --git a/e2e/__tests__/__snapshots__/globals.test.ts.snap b/e2e/__tests__/__snapshots__/globals.test.ts.snap index e284281a7e69..91985be3cfba 100644 --- a/e2e/__tests__/__snapshots__/globals.test.ts.snap +++ b/e2e/__tests__/__snapshots__/globals.test.ts.snap @@ -106,7 +106,7 @@ PASS __tests__/onlyConstructs.test.js ✓ test.only ✓ it.only ✓ fit - ○ skipped 1 test + ○ skipped it fdescribe ✓ it ✓ test @@ -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`] = ` diff --git a/e2e/__tests__/__snapshots__/testTodo.test.ts.snap b/e2e/__tests__/__snapshots__/testTodo.test.ts.snap index 29e820705f40..5ae29dea7ce8 100644 --- a/e2e/__tests__/__snapshots__/testTodo.test.ts.snap +++ b/e2e/__tests__/__snapshots__/testTodo.test.ts.snap @@ -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 diff --git a/e2e/__tests__/testTodo.test.ts b/e2e/__tests__/testTodo.test.ts index 3f9bc15bd28d..71f43d535ec3 100644 --- a/e2e/__tests__/testTodo.test.ts +++ b/e2e/__tests__/testTodo.test.ts @@ -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(); +}); diff --git a/e2e/test-todo/__tests__/verbose.test.js b/e2e/test-todo/__tests__/verbose.test.js new file mode 100644 index 000000000000..93f0166e306f --- /dev/null +++ b/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'); +}); diff --git a/packages/jest-reporters/src/verbose_reporter.ts b/packages/jest-reporters/src/verbose_reporter.ts index bc1a22dfa876..b34b69f2121e 100644 --- a/packages/jest-reporters/src/verbose_reporter.ts +++ b/packages/jest-reporters/src/verbose_reporter.ts @@ -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; + todo: Array; + }>( (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) {