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 4 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- `[jest-config]` Print error information on preset normalization error ([#7935](https://github.com/facebook/jest/pull/7935))
- `[jest-haste-map]` Add `skipPackageJson` option ([#7778](https://github.com/facebook/jest/pull/7778))
- `[jest-get-type]` Add `isPrimitive` function ([#7708](https://github.com/facebook/jest/pull/7708))
- `[@jest/reporter]` Display todo description when verbose is true ([#8038](https://github.com/facebook/jest/pull/8038))

### Fixes

Expand Down
10 changes: 9 additions & 1 deletion 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
✎ 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');
});
30 changes: 21 additions & 9 deletions packages/jest-reporters/src/verbose_reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ export default class VerboseReporter extends DefaultReporter {
if (test.status === 'pending') {
result.pending += 1;
} else if (test.status === 'todo') {
result.todo += 1;
result.todo.push(test);
} else {
this._logTest(test, indentLevel);
}

return result;
},
{pending: 0, todo: 0},
{pending: 0, todo: [] as Array<TestResult.AssertionResult>},
natealcedo marked this conversation as resolved.
Show resolved Hide resolved
);

if (summedTests.pending > 0) {
Expand All @@ -137,17 +137,29 @@ export default class VerboseReporter extends DefaultReporter {
);
}

if (summedTests.todo > 0) {
this._logSummedTests(
'todo',
this._getIcon('todo'),
summedTests.todo,
indentLevel,
);
if (summedTests.todo.length > 0) {
summedTests.todo.forEach(todoTest => {
this._logTodoTest(
'todo',
this._getIcon('todo'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems silly to pass in the icons and title, but I see it's consistent

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. Didn't want to stray too far from what was being done. The same could be said for printing skipped tests

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think given that we are explicitly pulling this behaviour out into _logTodoTest we should just move the concrete data into the function definition.

 private _logTodoTest(
    todoTest: TestResult.AssertionResult,
    indentLevel: number,
  ) {
    const text = chalk.dim(`todo ${todoTest.title}`);
    this._logLine(`${this._getIcon('todo')} ${text}`, indentLevel);
  }

Then if you want to be fancy you could curry this to:

 private _logTodoTest = (indentLevel: number) => (todoTest: TestResult.AssertionResult) => {
    const text = chalk.dim(`todo ${todoTest.title}`);
    this._logLine(`${this._getIcon('todo')} ${text}`, indentLevel);
  }

and then you can just do the following in the forEach:

summedTests.todo.forEach(this._logTodoTest(indentLevel));

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this approach. Should we do a similar approach to skipped tests then since their functions are very similar?

todoTest,
indentLevel,
);
});
}
}
}

private _logTodoTest(
prefix: string,
icon: string,
todoTest: TestResult.AssertionResult,
indentLevel: number,
) {
const text = chalk.dim(`${prefix} ${todoTest.title}`);
this._logLine(`${icon} ${text}`, indentLevel);
}

private _logSummedTests(
prefix: string,
icon: string,
Expand Down