UNPKG

e2ed

Version:

E2E testing framework over Playwright

44 lines (43 loc) 1.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.writeLogsToFile = exports.addLogToLogFile = void 0; const promises_1 = require("node:fs/promises"); const node_path_1 = require("node:path"); const internal_1 = require("../../constants/internal"); const config_1 = require("../config"); /** * Array of pack logs. Logs are stored in this array for further saving in the pack logs file. * @internal */ const logs = []; /** * Writes pack logs to logs file (if the pack config requires it and there are unwritten logs). * @internal */ const writeLogsToFile = async () => { if (logs.length === 0) { return; } const { logFileName } = (0, config_1.getFullPackConfig)(); if (logFileName === null) { return; } const logsFilePath = (0, node_path_1.join)(internal_1.REPORTS_DIRECTORY_PATH, logFileName); const logsText = logs.join(''); logs.length = 0; await (0, promises_1.appendFile)(logsFilePath, logsText); }; exports.writeLogsToFile = writeLogsToFile; const baseWritingInternal = 4_000; const deltaWritingInterval = 4_000; setInterval(() => { void writeLogsToFile(); }, baseWritingInternal + Math.random() * deltaWritingInterval); /** * Adds log message to pack logs (for later saving to the pack logs file). * @internal */ const addLogToLogFile = (logMessage) => { logs.push(logMessage); }; exports.addLogToLogFile = addLogToLogFile;