e2ed
Version:
E2E testing framework over Playwright
70 lines (69 loc) • 3.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.registerStartE2edRunEvent = void 0;
const internal_1 = require("../../constants/internal");
const config_1 = require("../config");
const environment_1 = require("../environment");
const error_1 = require("../error");
const exit_1 = require("../exit");
const fs_1 = require("../fs");
const generalLog_1 = require("../generalLog");
const packCompiler_1 = require("../packCompiler");
const startInfo_1 = require("../startInfo");
const runBeforePackFunctions_1 = require("./runBeforePackFunctions");
/**
* Registers start e2ed run event (for report) before running any test.
* @internal
*/
// eslint-disable-next-line max-statements
const registerStartE2edRunEvent = async () => {
await (0, fs_1.removeDirectory)(internal_1.TMP_DIRECTORY_PATH);
await (0, fs_1.createDirectory)(internal_1.EVENTS_DIRECTORY_PATH);
let errorSettingDotEnv;
await (0, environment_1.setDotEnvValuesToEnvironment)().catch((error) => {
errorSettingDotEnv = error;
});
const pathToTestFile = process.argv[2];
if (pathToTestFile !== undefined) {
internal_1.e2edEnvironment[internal_1.PATH_TO_TEST_FILE_VARIABLE_NAME] = pathToTestFile;
}
let compileErrors = [];
let configCompileTimeWithUnits = '';
try {
({ compileErrors, configCompileTimeWithUnits } = (0, packCompiler_1.compilePack)());
}
catch (cause) {
(0, exit_1.setGlobalExitCode)(5 /* ExitCode.HasErrorsInCompilingConfig */);
throw new error_1.E2edError('Caught an error on compiling config', { cause });
}
const startInfo = (0, startInfo_1.getStartInfo)({ configCompileTimeWithUnits });
try {
try {
await (0, runBeforePackFunctions_1.runBeforePackFunctions)(startInfo);
}
catch (cause) {
(0, exit_1.setGlobalExitCode)(7 /* ExitCode.HasErrorsInDoBeforePackFunctions */);
throw new error_1.E2edError('Caught an error on running "before pack" functions', { cause });
}
const fullPackConfig = (0, config_1.getFullPackConfig)();
(0, config_1.updateConfig)(fullPackConfig, startInfo);
if (errorSettingDotEnv !== undefined) {
(0, generalLog_1.generalLog)('Caught an error on setting environment variables from `variables.env` file', {
errorSettingDotEnv,
});
}
if (compileErrors.length !== 0) {
const pathToPack = (0, environment_1.getPathToPack)();
(0, generalLog_1.generalLog)(`Caught errors on compiling pack ${pathToPack}`, { compileErrors });
}
const { e2ed, runEnvironment } = startInfo;
const isLocalRun = runEnvironment !== "docker" /* RunEnvironment.Docker */;
const startMessage = `Run tests ${isLocalRun ? 'local' : 'in docker'} with e2ed@${e2ed.version}`;
(0, generalLog_1.generalLog)(startMessage, startInfo);
}
finally {
await (0, fs_1.writeStartInfo)(startInfo);
await (0, generalLog_1.writeLogsToFile)();
}
};
exports.registerStartE2edRunEvent = registerStartE2edRunEvent;