e2ed
Version:
E2E testing framework over Playwright
99 lines (98 loc) • 5.35 kB
JavaScript
"use strict";
/**
* @file Full pack configuration for running tests.
* Don't import this module. Instead, use `getFullPackConfig` from `utils/config`.
*/
Object.defineProperty(exports, "__esModule", { value: true });
const node_path_1 = require("node:path");
const internal_1 = require("./constants/internal");
const asserts_1 = require("./utils/asserts");
// eslint-disable-next-line import/no-internal-modules
const assertUserlandPack_1 = require("./utils/config/assertUserlandPack");
// eslint-disable-next-line import/no-internal-modules
const updateConfig_1 = require("./utils/config/updateConfig");
const environment_1 = require("./utils/environment");
const fn_1 = require("./utils/fn");
// eslint-disable-next-line import/no-internal-modules
const readStartInfoSync_1 = require("./utils/fs/readStartInfoSync");
const object_1 = require("./utils/object");
const uiMode_1 = require("./utils/uiMode");
const configurator_1 = require("./configurator");
const test_1 = require("@playwright/test");
const pathToPack = (0, environment_1.getPathToPack)();
const relativePathFromInstalledE2edToRoot = (0, node_path_1.relative)(internal_1.ABSOLUTE_PATH_TO_INSTALLED_E2ED_DIRECTORY, internal_1.ABSOLUTE_PATH_TO_PROJECT_ROOT_DIRECTORY);
const tsExtension = '.ts';
(0, asserts_1.assertValueIsTrue)(pathToPack.endsWith(tsExtension), `pathToPack ends with "${tsExtension}"`, {
pathToPack,
});
const pathFromCompiledConfigDirectoryToCompiledPack = `${pathToPack.slice(0, -tsExtension.length)}.js`;
const absoluteCompiledUserlandPackPath = (0, node_path_1.join)(internal_1.ABSOLUTE_PATH_TO_PROJECT_ROOT_DIRECTORY, internal_1.COMPILED_USERLAND_CONFIG_DIRECTORY, pathFromCompiledConfigDirectoryToCompiledPack);
// eslint-disable-next-line @typescript-eslint/no-var-requires, import/no-dynamic-require
const userlandPack = require(absoluteCompiledUserlandPackPath).pack;
const pathToTestFile = internal_1.e2edEnvironment[internal_1.PATH_TO_TEST_FILE_VARIABLE_NAME];
if (pathToTestFile !== undefined) {
(0, object_1.setReadonlyProperty)(userlandPack, 'testFileGlobs', [(0, node_path_1.join)('**', pathToTestFile)]);
}
(0, assertUserlandPack_1.assertUserlandPack)(userlandPack);
const { doAfterPack, doBeforePack, filterTestsIntoPack, mapBackendResponseErrorToLog, mapBackendResponseToLog, mapLogPayloadInConsole, mapLogPayloadInLogFile, mapLogPayloadInReport, } = userlandPack;
for (const fn of doAfterPack) {
(0, fn_1.setCustomInspectOnFunction)(fn);
}
for (const fn of doBeforePack) {
(0, fn_1.setCustomInspectOnFunction)(fn);
}
(0, fn_1.setCustomInspectOnFunction)(filterTestsIntoPack);
(0, fn_1.setCustomInspectOnFunction)(mapBackendResponseErrorToLog);
(0, fn_1.setCustomInspectOnFunction)(mapBackendResponseToLog);
(0, fn_1.setCustomInspectOnFunction)(mapLogPayloadInConsole);
(0, fn_1.setCustomInspectOnFunction)(mapLogPayloadInLogFile);
(0, fn_1.setCustomInspectOnFunction)(mapLogPayloadInReport);
if (internal_1.IS_DEBUG || uiMode_1.isUiMode) {
(0, object_1.setReadonlyProperty)(userlandPack, 'packTimeout', internal_1.MAX_TIMEOUT_IN_MS);
(0, object_1.setReadonlyProperty)(userlandPack, 'testIdleTimeout', internal_1.MAX_TIMEOUT_IN_MS);
(0, object_1.setReadonlyProperty)(userlandPack, 'testTimeout', internal_1.MAX_TIMEOUT_IN_MS);
}
const useOptions = {
actionTimeout: Math.round(userlandPack.testIdleTimeout / 2),
browserName: userlandPack.browserName,
// eslint-disable-next-line @typescript-eslint/naming-convention
bypassCSP: !userlandPack.enableCsp,
deviceScaleFactor: userlandPack.deviceScaleFactor,
hasTouch: userlandPack.enableTouchEventEmulation,
headless: configurator_1.isLocalRun ? userlandPack.enableHeadlessMode : true,
isMobile: userlandPack.enableMobileDeviceMode,
launchOptions: { args: [...userlandPack.browserFlags] },
navigationTimeout: userlandPack.navigationTimeout,
trace: 'retain-on-failure',
userAgent: userlandPack.userAgent,
viewport: { height: userlandPack.viewportHeight, width: userlandPack.viewportWidth },
...userlandPack.overriddenConfigFields?.use,
};
const playwrightConfig = (0, test_1.defineConfig)({
expect: {
timeout: userlandPack.assertionTimeout,
toHaveScreenshot: {
pathTemplate: `${internal_1.ABSOLUTE_PATH_TO_PROJECT_ROOT_DIRECTORY}/${internal_1.EXPECTED_SCREENSHOTS_DIRECTORY_PATH}/{arg}.png`,
},
},
fullyParallel: true,
globalTimeout: userlandPack.packTimeout,
outputDir: (0, node_path_1.join)(relativePathFromInstalledE2edToRoot, internal_1.INTERNAL_REPORTS_DIRECTORY_PATH),
projects: [{ name: userlandPack.browserName, use: useOptions }],
retries: configurator_1.isLocalRun ? 0 : userlandPack.maxRetriesCountInDocker - 1,
testDir: (0, node_path_1.join)(relativePathFromInstalledE2edToRoot, internal_1.TESTS_DIRECTORY_PATH),
testIgnore: ['**/node_modules/**', '**/*.skip.ts'],
testMatch: userlandPack.testFileGlobs,
timeout: userlandPack.testTimeout,
workers: userlandPack.concurrency,
...userlandPack.overriddenConfigFields,
use: useOptions,
});
const config = Object.assign(playwrightConfig, userlandPack);
try {
const startInfo = (0, readStartInfoSync_1.readStartInfoSync)();
(0, updateConfig_1.updateConfig)(config, startInfo);
}
catch { }
// eslint-disable-next-line import/no-default-export
exports.default = config;