mocha-chai-jest-snapshot
Version:
provides snapshot testing like jest
104 lines • 5.35 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getSnapshotSummaryOutput = void 0;
const jest_util_1 = require("jest-util");
const node_path_1 = __importStar(require("node:path"));
const slash_1 = __importDefault(require("slash"));
const chalk = require("chalk");
const formatTestPath = (rootDir, testPath) => {
if ((0, node_path_1.isAbsolute)(testPath)) {
testPath = node_path_1.default.relative(rootDir, testPath);
}
const dirname = node_path_1.default.dirname(testPath);
const basename = node_path_1.default.basename(testPath);
return (0, slash_1.default)(chalk.dim(dirname + node_path_1.default.sep) + chalk.bold(basename));
};
const ARROW = " \u203A ";
const DOWN_ARROW = " \u21B3 ";
const DOT = " \u2022 ";
const FAIL_COLOR = chalk.bold.red;
const OBSOLETE_COLOR = chalk.bold.yellow;
const SNAPSHOT_ADDED = chalk.bold.green;
const SNAPSHOT_NOTE = chalk.dim;
const SNAPSHOT_REMOVED = chalk.bold.green;
const SNAPSHOT_SUMMARY = chalk.bold;
const SNAPSHOT_UPDATED = chalk.bold.green;
const updateCommand = "re-run mocha with `--update` to update them";
const getSnapshotSummaryOutput = (rootDir, snapshots) => {
const summary = [];
summary.push(SNAPSHOT_SUMMARY("Snapshot Summary"));
if (snapshots.added) {
summary.push(SNAPSHOT_ADDED(ARROW + (0, jest_util_1.pluralize)("snapshot", snapshots.added) + " written ") + `from ${(0, jest_util_1.pluralize)("test suite", snapshots.filesAdded)}.`);
}
if (snapshots.unmatched) {
summary.push(FAIL_COLOR(`${ARROW}${(0, jest_util_1.pluralize)("snapshot", snapshots.unmatched)} failed`) +
` from ${(0, jest_util_1.pluralize)("test suite", snapshots.filesUnmatched)}. ` +
SNAPSHOT_NOTE("Inspect your code changes or " + updateCommand + " to update them."));
}
if (snapshots.updated) {
summary.push(SNAPSHOT_UPDATED(ARROW + (0, jest_util_1.pluralize)("snapshot", snapshots.updated) + " updated ") + `from ${(0, jest_util_1.pluralize)("test suite", snapshots.filesUpdated)}.`);
}
if (snapshots.filesRemoved) {
if (snapshots.didUpdate) {
summary.push(SNAPSHOT_REMOVED(`${ARROW}${(0, jest_util_1.pluralize)("snapshot file", snapshots.filesRemoved)} removed `) + `from ${(0, jest_util_1.pluralize)("test suite", snapshots.filesRemoved)}.`);
}
else {
summary.push(OBSOLETE_COLOR(`${ARROW}${(0, jest_util_1.pluralize)("snapshot file", snapshots.filesRemoved)} obsolete `) +
`from ${(0, jest_util_1.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(rootDir, head)}`);
tail.forEach((key) => {
summary.push(` ${DOT}${formatTestPath(rootDir, key)}`);
});
}
if (snapshots.unchecked) {
if (snapshots.didUpdate) {
summary.push(SNAPSHOT_REMOVED(`${ARROW}${(0, jest_util_1.pluralize)("snapshot", snapshots.unchecked)} removed `) +
`from ${(0, jest_util_1.pluralize)("test suite", snapshots.uncheckedKeysByFile.length)}.`);
}
else {
summary.push(OBSOLETE_COLOR(`${ARROW}${(0, jest_util_1.pluralize)("snapshot", snapshots.unchecked)} obsolete `) +
`from ${(0, jest_util_1.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(rootDir, uncheckedFile.filePath)}`);
uncheckedFile.keys.forEach((key) => {
summary.push(` ${DOT}${key}`);
});
});
}
return summary;
};
exports.getSnapshotSummaryOutput = getSnapshotSummaryOutput;
//# sourceMappingURL=jest-reporters-lite.js.map