91 lines
13 KiB
JavaScript
91 lines
13 KiB
JavaScript
"use strict";
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.restore = exports.serialize = exports.flatten = exports.isFixture = exports.isTest = void 0;
|
|
const lodash_1 = require("lodash");
|
|
const protocol_1 = require("../compiler/protocol");
|
|
const unit_type_1 = __importDefault(require("../../api/structure/unit-type"));
|
|
const RECURSIVE_PROPERTIES = ['testFile', 'fixture', 'currentFixture', 'collectedTests'];
|
|
function isProperty(object, property) {
|
|
return object.hasOwnProperty(property);
|
|
}
|
|
function isTest(value) {
|
|
return value.unitType === unit_type_1.default.test;
|
|
}
|
|
exports.isTest = isTest;
|
|
function isFixture(value) {
|
|
return value.unitType === unit_type_1.default.fixture;
|
|
}
|
|
exports.isFixture = isFixture;
|
|
function mapProperties(object, properties, mapper) {
|
|
for (const property of properties) {
|
|
if (!isProperty(object, property))
|
|
continue;
|
|
const value = object[property];
|
|
if (Array.isArray(value))
|
|
object[property] = value.map(item => mapper({ item, property, object }));
|
|
else
|
|
object[property] = mapper({ item: object[property], property, object });
|
|
}
|
|
}
|
|
function replaceFunctionProperties(unit) {
|
|
mapProperties(unit, protocol_1.FUNCTION_PROPERTIES, ({ item }) => !!item);
|
|
}
|
|
function restoreFunctionProperties(unit, mapper) {
|
|
mapProperties(unit, protocol_1.FUNCTION_PROPERTIES, ({ item, object, property }) => item ? mapper(object.id, property) : item);
|
|
}
|
|
function flattenRecursiveProperties(unit) {
|
|
mapProperties(unit, RECURSIVE_PROPERTIES, ({ item }) => item.id);
|
|
}
|
|
function restoreRecursiveProperties(unit, units) {
|
|
mapProperties(unit, RECURSIVE_PROPERTIES, ({ item }) => units[item]);
|
|
}
|
|
function restorePredicateInRequestFilterRules(test, mapper) {
|
|
test.requestHooks.forEach(hook => {
|
|
for (let i = 0; i < hook._requestFilterRules.length; i++) {
|
|
const targetRule = hook._requestFilterRules[i];
|
|
if (!targetRule.isPredicate)
|
|
continue;
|
|
targetRule.options = mapper({
|
|
testId: test.id,
|
|
hookId: hook.id,
|
|
ruleId: targetRule.id,
|
|
});
|
|
}
|
|
});
|
|
}
|
|
function flatten(tests) {
|
|
const testFiles = (0, lodash_1.uniq)(tests.map(test => test.testFile));
|
|
const fixtures = (0, lodash_1.uniq)(tests.map(test => test.fixture));
|
|
return (0, lodash_1.keyBy)([...tests, ...fixtures, ...testFiles], unit => unit.id);
|
|
}
|
|
exports.flatten = flatten;
|
|
function serialize(units) {
|
|
const result = {};
|
|
for (const unit of Object.values(units)) {
|
|
// @ts-ignore
|
|
const copy = Object.assign({}, unit);
|
|
replaceFunctionProperties(copy);
|
|
flattenRecursiveProperties(copy);
|
|
result[copy.id] = copy;
|
|
}
|
|
return result;
|
|
}
|
|
exports.serialize = serialize;
|
|
function restore(units, testFunctionMapper, ruleMapper) {
|
|
const list = Object.values(units);
|
|
const result = [];
|
|
for (const unit of list) {
|
|
restoreRecursiveProperties(unit, units);
|
|
restoreFunctionProperties(unit, testFunctionMapper);
|
|
if (isTest(unit)) {
|
|
restorePredicateInRequestFilterRules(unit, ruleMapper);
|
|
result.push(unit);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
exports.restore = restore;
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC1zdHJ1Y3R1cmUuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvc2VydmljZXMvc2VyaWFsaXphdGlvbi90ZXN0LXN0cnVjdHVyZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7QUFBQSxtQ0FBcUM7QUFDckMsbURBQTJEO0FBSzNELDhFQUFxRDtBQUlyRCxNQUFNLG9CQUFvQixHQUFHLENBQUMsVUFBVSxFQUFFLFNBQVMsRUFBRSxnQkFBZ0IsRUFBRSxnQkFBZ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