Innovenergy_trunk/frontend/node_modules/testcafe/lib/services/serialization/test-structure.js

91 lines
13 KiB
JavaScript
Raw Normal View History

"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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC1zdHJ1Y3R1cmUuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvc2VydmljZXMvc2VyaWFsaXphdGlvbi90ZXN0LXN0cnVjdHVyZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7QUFBQSxtQ0FBcUM7QUFDckMsbURBQTJEO0FBSzNELDhFQUFxRDtBQUlyRCxNQUFNLG9CQUFvQixHQUFHLENBQUMsVUFBVSxFQUFFLFNBQVMsRUFBRSxnQkFBZ0IsRUFBRSxnQkFBZ0IsQ0FBVSxDQUFDO0FBMEJsRyxTQUFTLFVBQVUsQ0FBb0IsTUFBUyxFQUFFLFFBQWdCO0lBQzlELE9BQU8sTUFBTSxDQUFDLGNBQWMsQ0FBQyxRQUFRLENBQUMsQ0FBQztBQUMzQyxDQUFDO0FBRUQsU0FBZ0IsTUFBTSxDQUFFLEtBQVc7SUFDL0IsT0FBTyxLQUFLLENBQUMsUUFBUSxLQUFLLG1CQUFRLENBQUMsSUFBSSxDQUFDO0FBQzVDLENBQUM7QUFGRCx3QkFFQztBQUVELFNBQWdCLFNBQVMsQ0FBRSxLQUFXO0lBQ2xDLE9BQU8s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