61 lines
9.3 KiB
JavaScript
61 lines
9.3 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.findProblematicScripts = exports.setUniqueUrls = void 0;
|
|
const lodash_1 = require("lodash");
|
|
const testcafe_hammerhead_1 = require("testcafe-hammerhead");
|
|
const client_script_1 = __importDefault(require("./client-script"));
|
|
function getScriptGroupValues(collection, groupByPredicate, pickByPredicate) {
|
|
return (0, lodash_1.chain)(collection)
|
|
.groupBy(groupByPredicate)
|
|
.pickBy(pickByPredicate)
|
|
.values()
|
|
.value();
|
|
}
|
|
function getDuplicatedScripts(collection) {
|
|
const contentGroups = getScriptGroupValues(collection, (s) => s.hash, (g) => g.length > 1);
|
|
const duplicatedScripts = [];
|
|
contentGroups.forEach(contentGroup => {
|
|
const pageGroups = getScriptGroupValues(contentGroup, (s) => s.page.toString());
|
|
if (pageGroups.length === 1 && testcafe_hammerhead_1.RequestFilterRule.isANY(pageGroups[0][0].page)) { /*eslint-disable-line no-extra-parens*/
|
|
duplicatedScripts.push(pageGroups[0][0]);
|
|
return;
|
|
}
|
|
const forAllPagesGroup = pageGroups.find(pg => testcafe_hammerhead_1.RequestFilterRule.isANY(pg[0].page)); /*eslint-disable-line no-extra-parens*/
|
|
if (forAllPagesGroup) {
|
|
pageGroups
|
|
.filter(pg => !testcafe_hammerhead_1.RequestFilterRule.isANY(pg[0].page)) /*eslint-disable-line no-extra-parens*/
|
|
.forEach(pg => {
|
|
duplicatedScripts.push(pg[0]);
|
|
});
|
|
}
|
|
else {
|
|
pageGroups
|
|
.filter(pg => pg.length > 1)
|
|
.forEach(pg => {
|
|
duplicatedScripts.push(pg[0]);
|
|
});
|
|
}
|
|
});
|
|
return duplicatedScripts;
|
|
}
|
|
function setUniqueUrls(collection) {
|
|
const scriptsWithDuplicatedUrls = getDuplicatedScripts(collection);
|
|
for (let i = 0; i < scriptsWithDuplicatedUrls.length; i++)
|
|
scriptsWithDuplicatedUrls[i].url = scriptsWithDuplicatedUrls[i].url + '-' + (0, testcafe_hammerhead_1.generateUniqueId)(client_script_1.default.URL_UNIQUE_PART_LENGTH);
|
|
return collection;
|
|
}
|
|
exports.setUniqueUrls = setUniqueUrls;
|
|
function findProblematicScripts(collection) {
|
|
const nonEmptyScripts = collection.filter(s => !!s.content);
|
|
const duplicatedContent = getDuplicatedScripts(nonEmptyScripts);
|
|
const empty = collection.filter(s => !s.content);
|
|
return {
|
|
duplicatedContent,
|
|
empty,
|
|
};
|
|
}
|
|
exports.findProblematicScripts = findProblematicScripts;
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbHMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvY3VzdG9tLWNsaWVudC1zY3JpcHRzL3V0aWxzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7OztBQUFBLG1DQUErQjtBQUMvQiw2REFBMEU7QUFDMUUsb0VBQTJDO0FBRzNDLFNBQVMsb0JBQW9CLENBQUUsVUFBMEIsRUFBRSxnQkFBMEIsRUFBRSxlQUFtRTtJQUN0SixPQUFPLElBQUEsY0FBSyxFQUFDLFVBQVUsQ0FBQztTQUNuQixPQUFPLENBQUMsZ0JBQWdCLENBQUM7U0FDekIsTUFBTSxDQUFDLGVBQWUsQ0FBQztTQUN2QixNQUFNLEVBQUU7U0FDUixLQUFLLEVBQXNCLENBQUM7QUFDckMsQ0FBQztBQUVELFNBQVMsb0JBQW9CLENBQUUsVUFBMEI7SUFDckQsTUFBTSxhQUFhLEdBQXVCLG9CQUFvQixDQUFDLFVBQVUsRUFBRSxDQUFDLENBQWUsRUFBRSxFQUFFLENBQUMsQ0FBQyxDQUFDLElBQUksRUFBRSxDQUFDLENBQWlCLEVBQUUsRUFBRSxDQUFDLENBQUMsQ0FBQyx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