-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved the jest reporter with snapshot info per test. (#3660)
- Loading branch information
1 parent
e4278b3
commit cb8e760
Showing
5 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
packages/jest-cli/src/reporters/__tests__/__snapshots__/get_snapshot_status.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Retrieves the snapshot status 1`] = ` | ||
Array [ | ||
"<bold><green> › 1 snapshot</> written.", | ||
"<bold><green> › 1 snapshot</> updated.", | ||
"<bold><red> › 1 obsolete snapshot</> found.", | ||
"<bold><red> › 1 snapshot test</> failed.", | ||
] | ||
`; | ||
exports[`Retrieves the snapshot status after a snapshot update 1`] = ` | ||
Array [ | ||
"<bold><green> › 2 snapshots</> written.", | ||
"<bold><green> › 2 snapshots</> updated.", | ||
"<bold><red> › 2 obsolete snapshots</> removed.", | ||
"<bold><red> › Obsolete snapshot file</> removed.", | ||
"<bold><red> › 2 snapshot tests</> failed.", | ||
] | ||
`; | ||
exports[`Shows no snapshot updates if all snapshots matched 1`] = `Array []`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
packages/jest-cli/src/reporters/__tests__/get_snapshot_status.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const getSnapshotStatus = require('../get_snapshot_status'); | ||
|
||
test('Retrieves the snapshot status', () => { | ||
const snapshotResult = { | ||
added: 1, | ||
fileDeleted: false, | ||
matched: 1, | ||
unchecked: 1, | ||
unmatched: 1, | ||
updated: 1, | ||
}; | ||
|
||
expect(getSnapshotStatus(snapshotResult, false)).toMatchSnapshot(); | ||
}); | ||
|
||
test('Shows no snapshot updates if all snapshots matched', () => { | ||
const snapshotResult = { | ||
added: 0, | ||
fileDeleted: false, | ||
matched: 1, | ||
unchecked: 0, | ||
unmatched: 0, | ||
updated: 0, | ||
}; | ||
|
||
expect(getSnapshotStatus(snapshotResult, true)).toMatchSnapshot(); | ||
}); | ||
|
||
test('Retrieves the snapshot status after a snapshot update', () => { | ||
const snapshotResult = { | ||
added: 2, | ||
fileDeleted: true, | ||
matched: 2, | ||
unchecked: 2, | ||
unmatched: 2, | ||
updated: 2, | ||
}; | ||
|
||
expect(getSnapshotStatus(snapshotResult, true)).toMatchSnapshot(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @flow | ||
*/ | ||
|
||
import type {TestResult} from 'types/TestResult'; | ||
|
||
const chalk = require('chalk'); | ||
|
||
const {pluralize} = require('./utils'); | ||
|
||
const ARROW = ' \u203A '; | ||
const FAIL_COLOR = chalk.bold.red; | ||
const SNAPSHOT_ADDED = chalk.bold.green; | ||
const SNAPSHOT_REMOVED = chalk.bold.red; | ||
const SNAPSHOT_UPDATED = chalk.bold.green; | ||
|
||
module.exports = ( | ||
snapshot: $PropertyType<TestResult, 'snapshot'>, | ||
afterUpdate: boolean, | ||
): Array<string> => { | ||
const statuses = []; | ||
|
||
if (snapshot.added) { | ||
statuses.push( | ||
SNAPSHOT_ADDED(ARROW + pluralize('snapshot', snapshot.added)) + | ||
' written.', | ||
); | ||
} | ||
|
||
if (snapshot.updated) { | ||
statuses.push( | ||
SNAPSHOT_UPDATED(ARROW + pluralize('snapshot', snapshot.updated)) + | ||
` updated.`, | ||
); | ||
} | ||
|
||
if (snapshot.unchecked) { | ||
statuses.push( | ||
FAIL_COLOR(ARROW + pluralize('obsolete snapshot', snapshot.unchecked)) + | ||
(afterUpdate ? ' removed' : ' found') + | ||
'.', | ||
); | ||
} | ||
|
||
if (snapshot.fileDeleted) { | ||
statuses.push( | ||
SNAPSHOT_REMOVED(ARROW + 'Obsolete snapshot file') + ` removed.`, | ||
); | ||
} | ||
|
||
if (snapshot.unmatched) { | ||
statuses.push( | ||
FAIL_COLOR(ARROW + pluralize('snapshot test', snapshot.unmatched)) + | ||
' failed.', | ||
); | ||
} | ||
return statuses; | ||
}; |