unmock-jest
Version:
Jest reporter for [Unmock](https://unmock.io).
43 lines • 2.33 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const lodash_1 = require("lodash");
const path = require("path");
exports.sortTestSuites = (testSuites) => {
return lodash_1.reverse(lodash_1.sortBy(testSuites, [
testSuite => testSuite.suiteResults.numFailingTests,
testSuite => testSuite.snapshots.length,
]));
};
const largestCommonArray2 = (arr1, arr2) => {
const [shorter, longer] = arr1.length >= arr2.length ? [arr2, arr1] : [arr1, arr2];
return lodash_1.takeWhile(shorter, (item1, index) => item1 === longer[index]);
};
exports.largestCommonArray = (arrays) => {
return arrays.reduce((acc, val) => largestCommonArray2(acc, val));
};
exports.REDACTED = "-- redacted --";
exports.authRedactor = (snapshot) => {
const req = snapshot.data.req;
const redactedReq = Object.assign(Object.assign({}, req), { headers: Object.assign(Object.assign(Object.assign({}, req.headers), (req.headers.Authorization ? { Authorization: exports.REDACTED } : {})), (req.headers.authorization ? { authorization: exports.REDACTED } : {})) });
return Object.assign(Object.assign({}, snapshot), { data: Object.assign(Object.assign({}, snapshot.data), { req: redactedReq }) });
};
exports.toTestSuites = (input) => {
const groupedResultsByFilePath = lodash_1.groupBy(input.jestData.aggregatedResult.testResults, testResult => testResult.testFilePath);
const testResultByFilePath = lodash_1.mapValues(groupedResultsByFilePath, results => {
if (results.length > 1) {
throw Error("Did not expect to get multiple test results for a single file");
}
return results[0];
});
const snapshotsByFilePath = lodash_1.groupBy(input.snapshots, snapshot => snapshot.testPath);
const paths = input.jestData.aggregatedResult.testResults.map(testResult => path.dirname(testResult.testFilePath).split(path.sep));
const longestPath = exports.largestCommonArray(paths).join(path.sep) + path.sep;
const combined = lodash_1.map(testResultByFilePath, (value, filepath) => ({
shortFilePath: value.testFilePath.replace(longestPath, ""),
testFilePath: value.testFilePath,
suiteResults: value,
snapshots: snapshotsByFilePath[filepath] || [],
}));
return combined;
};
//# sourceMappingURL=utils.js.map