UNPKG

mocha-chai-jest-snapshot

Version:
76 lines 2.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.addSnapshotResult = exports.packSnapshotState = exports.makeEmptySnapshotSummary = void 0; /** * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ const test_result_1 = require("@jest/test-result"); const makeEmptySnapshotSummary = (options) => { const summary = (0, test_result_1.makeEmptyAggregatedTestResult)().snapshot; summary.didUpdate = options.updateSnapshot === "all"; return summary; }; exports.makeEmptySnapshotSummary = makeEmptySnapshotSummary; const packSnapshotState = (snapshotState) => { const snapshot = { added: 0, fileDeleted: false, matched: 0, unchecked: 0, uncheckedKeys: [], unmatched: 0, updated: 0, }; const uncheckedCount = snapshotState.getUncheckedCount(); const uncheckedKeys = snapshotState.getUncheckedKeys(); if (uncheckedCount) { snapshotState.removeUncheckedKeys(); } const status = snapshotState.save(); snapshot.fileDeleted = status.deleted; snapshot.added = snapshotState.added; snapshot.matched = snapshotState.matched; snapshot.unmatched = snapshotState.unmatched; snapshot.updated = snapshotState.updated; snapshot.unchecked = !status.deleted ? uncheckedCount : 0; // Copy the array to prevent memory leaks snapshot.uncheckedKeys = Array.from(uncheckedKeys); return snapshot; }; exports.packSnapshotState = packSnapshotState; const addSnapshotResult = (snapshotSummary, snapshotResult, testFilePath) => { // Snapshot data if (snapshotResult.added) { snapshotSummary.filesAdded++; } if (snapshotResult.fileDeleted) { snapshotSummary.filesRemoved++; } if (snapshotResult.unmatched) { snapshotSummary.filesUnmatched++; } if (snapshotResult.updated) { snapshotSummary.filesUpdated++; } snapshotSummary.added += snapshotResult.added; snapshotSummary.matched += snapshotResult.matched; snapshotSummary.unchecked += snapshotResult.unchecked; if (snapshotResult.uncheckedKeys && snapshotResult.uncheckedKeys.length > 0) { snapshotSummary.uncheckedKeysByFile.push({ filePath: testFilePath, keys: snapshotResult.uncheckedKeys, }); } snapshotSummary.unmatched += snapshotResult.unmatched; snapshotSummary.updated += snapshotResult.updated; snapshotSummary.total += snapshotResult.added + snapshotResult.matched + snapshotResult.unmatched + snapshotResult.updated; }; exports.addSnapshotResult = addSnapshotResult; //# sourceMappingURL=jest-test-result-helper.js.map