-
-
Notifications
You must be signed in to change notification settings - Fork 553
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: not to display obsoleted snapshots when test with
-t
(#8122)
- Loading branch information
1 parent
4ea491e
commit 5fe525b
Showing
4 changed files
with
95 additions
and
3 deletions.
There are no files selected for viewing
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,84 @@ | ||
const { DefaultReporter } = require("@jest/reporters"); | ||
const chalk = require.cache[require.resolve('@jest/reporters')].require("chalk"); | ||
const jestUtil = require.cache[require.resolve('@jest/reporters')].require("jest-util"); | ||
|
||
const ARROW = ' \u203A '; | ||
const DOT = ' \u2022 '; | ||
const FAIL_COLOR = chalk.bold.red; | ||
const SNAPSHOT_ADDED = chalk.bold.green; | ||
const SNAPSHOT_UPDATED = chalk.bold.green; | ||
const SNAPSHOT_OUTDATED = chalk.bold.yellow; | ||
function getSnapshotStatus(snapshot, afterUpdate) { | ||
const statuses = []; | ||
if (snapshot.added) { | ||
statuses.push( | ||
SNAPSHOT_ADDED( | ||
`${ARROW + jestUtil().pluralize('snapshot', snapshot.added) | ||
} written.` | ||
) | ||
); | ||
} | ||
if (snapshot.updated) { | ||
statuses.push( | ||
SNAPSHOT_UPDATED( | ||
`${ARROW + jestUtil().pluralize('snapshot', snapshot.updated) | ||
} updated.` | ||
) | ||
); | ||
} | ||
if (snapshot.unmatched) { | ||
statuses.push( | ||
FAIL_COLOR( | ||
`${ARROW + jestUtil().pluralize('snapshot', snapshot.unmatched) | ||
} failed.` | ||
) | ||
); | ||
} | ||
if (snapshot.unchecked) { | ||
if (afterUpdate) { | ||
statuses.push( | ||
SNAPSHOT_UPDATED( | ||
`${ARROW + jestUtil().pluralize('snapshot', snapshot.unchecked) | ||
} removed.` | ||
) | ||
); | ||
for (const key of snapshot.uncheckedKeys) { | ||
statuses.push(` ${DOT}${key}`); | ||
} | ||
} else { | ||
statuses.push( | ||
`${SNAPSHOT_OUTDATED( | ||
`${ARROW + jestUtil().pluralize('snapshot', snapshot.unchecked) | ||
} obsolete` | ||
)}.` | ||
); | ||
} | ||
} | ||
if (snapshot.fileDeleted) { | ||
statuses.push(SNAPSHOT_UPDATED(`${ARROW}snapshot file removed.`)); | ||
} | ||
return statuses; | ||
} | ||
|
||
const isUpdate = process.argv.includes("-u") || process.argv.includes("--updateSnapshot"); | ||
const isFiltering = process.argv.includes("-t") || process.argv.includes("--testNamePattern"); | ||
const isVerbose = process.argv.includes("--verbose"); | ||
|
||
if (!isVerbose && !isUpdate && isFiltering) { | ||
class IgnoreSnapshotDefaultReporter extends DefaultReporter { | ||
printTestFileFailureMessage(_testPath, _config, result) { | ||
if (result.failureMessage) { | ||
this.log(result.failureMessage); | ||
} | ||
const didUpdate = this._globalConfig.updateSnapshot === 'all'; | ||
const snapshotStatuses = getSnapshotStatus( | ||
result.snapshot, | ||
didUpdate | ||
); | ||
snapshotStatuses.forEach(this.log); | ||
} | ||
} | ||
module.exports = IgnoreSnapshotDefaultReporter; | ||
} else { | ||
module.exports = DefaultReporter; | ||
} |
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
5fe525b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 Benchmark detail: Open
5fe525b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 Ran ecosystem CI: Open