earljs
Version:
Ergonomic, modern and type-safe assertion library
39 lines (38 loc) • 1.54 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.toMatchSnapshot = void 0;
const errors_1 = require("../../errors");
const helpers_1 = require("./helpers");
const jestCompareSnapshot_1 = require("./jestCompareSnapshot");
function toMatchSnapshot(ctrl, { compareSnapshot, env } = {
compareSnapshot: jestCompareSnapshot_1.compareSnapshotUsingJest,
env: process.env,
}) {
if (ctrl.isNegated) {
throw new errors_1.EarlConfigurationError("toMatchSnapshot can't be negated");
}
if (!ctrl.testRunnerCtx) {
throw new errors_1.EarlConfigurationError('Test runner integration is required for snapshot support. Read more: https://earljs.dev/docs/guides/test-runner-integration');
}
const snapshotFilePath = (0, helpers_1.getSnapshotFilePath)(ctrl.testRunnerCtx.testInfo.testFilePath);
const fullName = (0, helpers_1.getSnapshotFullName)(ctrl.testRunnerCtx.testInfo);
const result = compareSnapshot({
actual: ctrl.actual,
name: fullName,
snapshotFilePath: snapshotFilePath,
updateSnapshotMode: (0, helpers_1.getUpdateSnapshotMode)(env),
});
if (result.success) {
ctrl.assert({ success: true, reason: '-', negatedReason: '-' });
}
else {
ctrl.assert({
success: result.success,
reason: "Snapshot doesn't match",
negatedReason: '-',
actual: result.actual,
expected: result.expected,
});
}
}
exports.toMatchSnapshot = toMatchSnapshot;
;