e2ed
Version:
E2E testing framework over Playwright
38 lines (37 loc) • 2.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getScreenshotFileNames = void 0;
const promises_1 = require("node:fs/promises");
const node_path_1 = require("node:path");
const internal_1 = require("../../constants/internal");
const asserts_1 = require("../asserts");
const fullPageSuffix = '.fullPage.png';
const viewportSuffix = '.viewport.png';
/**
* Get filenames with page screenshots taken on test error.
* @internal
*/
const getScreenshotFileNames = async (directoryName, testStaticOptions) => {
const directoryPath = (0, node_path_1.join)(internal_1.SCREENSHOTS_DIRECTORY_PATH, directoryName);
const alreadyExistingScreenshots = await (0, promises_1.readdir)(directoryPath).catch(() => []);
const fileNamePrefix = `${testStaticOptions.name}.`.replace(/"/g, '');
const currentFullPageScreenshotsIndex = Math.max(0, ...alreadyExistingScreenshots.map((fileName) => {
if (!fileName.startsWith(fileNamePrefix) || !fileName.endsWith(fullPageSuffix)) {
return 0;
}
return Number(fileName.slice(fileNamePrefix.length, -fullPageSuffix.length));
}));
(0, asserts_1.assertValueIsTrue)(Number.isInteger(currentFullPageScreenshotsIndex), 'currentFullPageScreenshotsIndex is integer', { alreadyExistingScreenshots, directoryName, testStaticOptions });
const currentViewportScreenshotsIndex = Math.max(0, ...alreadyExistingScreenshots.map((fileName) => {
if (!fileName.startsWith(fileNamePrefix) || !fileName.endsWith(viewportSuffix)) {
return 0;
}
return Number(fileName.slice(fileNamePrefix.length, -viewportSuffix.length));
}));
(0, asserts_1.assertValueIsTrue)(Number.isInteger(currentViewportScreenshotsIndex), 'currentViewportScreenshotsIndex is integer', { alreadyExistingScreenshots, directoryName, testStaticOptions });
return {
fullPage: `${fileNamePrefix}${currentFullPageScreenshotsIndex + 1}${fullPageSuffix}`,
viewport: `${fileNamePrefix}${currentViewportScreenshotsIndex + 1}${viewportSuffix}`,
};
};
exports.getScreenshotFileNames = getScreenshotFileNames;