e2ed
Version:
E2E testing framework over Playwright
35 lines (34 loc) • 1.67 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.readJsonReportData = readJsonReportData;
const onFirstJsonReportDataLoad_1 = require("./onFirstJsonReportDataLoad");
const readPartOfJsonReportData_1 = require("./readPartOfJsonReportData");
const onFirstJsonReportDataLoad = onFirstJsonReportDataLoad_1.onFirstJsonReportDataLoad;
const readPartOfJsonReportData = readPartOfJsonReportData_1.readPartOfJsonReportData;
/**
* Reads JSON report data from script tags.
* Not all tags can be loaded and inserted into the DOM by the time the function is called,
* so it must be called several times until the DOM is loaded.
* This client function should not use scope variables (except global functions).
* @internal
*/
function readJsonReportData(areAllScriptsLoaded = false) {
const { lengthOfReadedJsonReportDataParts } = reportClientState;
const scripts = document.querySelectorAll('body > script.e2edJsonReportData');
const { length } = scripts;
if (length <= lengthOfReadedJsonReportDataParts) {
return;
}
let isLastReadSuccessful = true;
for (let index = lengthOfReadedJsonReportDataParts; index < length; index += 1) {
isLastReadSuccessful = readPartOfJsonReportData({
scriptToRead: scripts[index],
shouldLogError: index < length - 1 || areAllScriptsLoaded,
});
}
const newLength = areAllScriptsLoaded || isLastReadSuccessful ? length : length - 1;
if (reportClientState.lengthOfReadedJsonReportDataParts === 0 && newLength > 0) {
onFirstJsonReportDataLoad();
}
reportClientState.lengthOfReadedJsonReportDataParts = newLength;
}