in packages/jest-reporters/src/getSnapshotSummary.ts [25:138]
export default function getSnapshotSummary(
snapshots: SnapshotSummary,
globalConfig: Config.GlobalConfig,
updateCommand: string,
): Array<string> {
const summary = [];
summary.push(SNAPSHOT_SUMMARY('Snapshot Summary'));
if (snapshots.added) {
summary.push(
`${SNAPSHOT_ADDED(
`${ARROW + pluralize('snapshot', snapshots.added)} written `,
)}from ${pluralize('test suite', snapshots.filesAdded)}.`,
);
}
if (snapshots.unmatched) {
summary.push(
`${FAIL_COLOR(
`${ARROW}${pluralize('snapshot', snapshots.unmatched)} failed`,
)} from ${pluralize(
'test suite',
snapshots.filesUnmatched,
)}. ${SNAPSHOT_NOTE(
`Inspect your code changes or ${updateCommand} to update them.`,
)}`,
);
}
if (snapshots.updated) {
summary.push(
`${SNAPSHOT_UPDATED(
`${ARROW + pluralize('snapshot', snapshots.updated)} updated `,
)}from ${pluralize('test suite', snapshots.filesUpdated)}.`,
);
}
if (snapshots.filesRemoved) {
if (snapshots.didUpdate) {
summary.push(
`${SNAPSHOT_REMOVED(
`${ARROW}${pluralize(
'snapshot file',
snapshots.filesRemoved,
)} removed `,
)}from ${pluralize('test suite', snapshots.filesRemoved)}.`,
);
} else {
summary.push(
`${OBSOLETE_COLOR(
`${ARROW}${pluralize(
'snapshot file',
snapshots.filesRemoved,
)} obsolete `,
)}from ${pluralize(
'test suite',
snapshots.filesRemoved,
)}. ${SNAPSHOT_NOTE(
`To remove ${
snapshots.filesRemoved === 1 ? 'it' : 'them all'
}, ${updateCommand}.`,
)}`,
);
}
}
if (snapshots.filesRemovedList && snapshots.filesRemovedList.length) {
const [head, ...tail] = snapshots.filesRemovedList;
summary.push(` ${DOWN_ARROW} ${DOT}${formatTestPath(globalConfig, head)}`);
tail.forEach(key => {
summary.push(` ${DOT}${formatTestPath(globalConfig, key)}`);
});
}
if (snapshots.unchecked) {
if (snapshots.didUpdate) {
summary.push(
`${SNAPSHOT_REMOVED(
`${ARROW}${pluralize('snapshot', snapshots.unchecked)} removed `,
)}from ${pluralize(
'test suite',
snapshots.uncheckedKeysByFile.length,
)}.`,
);
} else {
summary.push(
`${OBSOLETE_COLOR(
`${ARROW}${pluralize('snapshot', snapshots.unchecked)} obsolete `,
)}from ${pluralize(
'test suite',
snapshots.uncheckedKeysByFile.length,
)}. ${SNAPSHOT_NOTE(
`To remove ${
snapshots.unchecked === 1 ? 'it' : 'them all'
}, ${updateCommand}.`,
)}`,
);
}
snapshots.uncheckedKeysByFile.forEach(uncheckedFile => {
summary.push(
` ${DOWN_ARROW}${formatTestPath(
globalConfig,
uncheckedFile.filePath,
)}`,
);
uncheckedFile.keys.forEach(key => {
summary.push(` ${DOT}${key}`);
});
});
}
return summary;
}