UNPKG

e2ed

Version:

E2E testing framework over Playwright

46 lines (45 loc) 1.68 kB
"use strict"; /* eslint-disable max-depth */ Object.defineProperty(exports, "__esModule", { value: true }); exports.getImgCspHosts = void 0; const node_url_1 = require("node:url"); const flatLogEvents_1 = require("../flatLogEvents"); const client_1 = require("./client"); /** * 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 (0, flatLogEvents_1.flatLogEvents)(logEvents)) { if (type !== 6 /* LogEventType.InternalAssert */ || payload === undefined) { continue; } const { actual, diff, expected } = payload; if ((0, client_1.isScreenshotLog)(actual)) { processMaybeUrl(actual.url); } if ((0, client_1.isScreenshotLog)(diff)) { processMaybeUrl(diff.url); } if ((0, client_1.isScreenshotLog)(expected)) { processMaybeUrl(expected.url); } } } } return Object.keys(hosts).join(' '); }; exports.getImgCspHosts = getImgCspHosts;