e2ed
Version:
E2E testing framework over Playwright
38 lines (37 loc) • 1.39 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getImgCspHosts = void 0;
const node_url_1 = require("node:url");
/**
* Get string with images hosts using in HTML report, for CSP `img-src` rule.
* @internal
*/
const getImgCspHosts = (reportData) => {
const hosts = Object.create(null);
const { retries } = reportData;
const processMaybeUrl = (maybeUrl) => {
if (typeof maybeUrl === 'string' && maybeUrl.startsWith('https://')) {
try {
const { origin } = new node_url_1.URL(maybeUrl);
hosts[origin] = true;
}
catch { }
}
};
for (const { fullTestRuns } of retries) {
for (const { logEvents } of fullTestRuns) {
for (const { payload, type } of logEvents) {
// eslint-disable-next-line max-depth
if (type !== 6 /* LogEventType.InternalAssert */ || payload === undefined) {
continue;
}
const { actualScreenshotUrl, diffScreenshotUrl, expectedScreenshotUrl } = payload;
processMaybeUrl(actualScreenshotUrl);
processMaybeUrl(diffScreenshotUrl);
processMaybeUrl(expectedScreenshotUrl);
}
}
}
return Object.keys(hosts).join(' ');
};
exports.getImgCspHosts = getImgCspHosts;