snapshot of https://github.com/jitsi/jitsi-meet.git @ fd1749dd28f4138aa80234fc7f311b19aaffa0e7 (2026-09-15)
This commit is contained in:
83
tests/helpers/browserLogger.ts
Normal file
83
tests/helpers/browserLogger.ts
Normal file
@@ -0,0 +1,83 @@
|
||||
import fs from 'node:fs';
|
||||
|
||||
/**
|
||||
* A prefix to use for all messages we add to the console log.
|
||||
*/
|
||||
export const LOG_PREFIX = '[MeetTest] ';
|
||||
|
||||
/**
|
||||
* Initialize logger for a driver.
|
||||
*
|
||||
* @param {WebdriverIO.Browser} driver - The driver.
|
||||
* @param {string} fileName - The name of the file.
|
||||
* @param {string} folder - The folder to save the file.
|
||||
* @returns {void}
|
||||
*/
|
||||
export function initLogger(driver: WebdriverIO.Browser, fileName: string, folder: string) {
|
||||
// @ts-ignore
|
||||
driver.logFile = `${folder}/${fileName}.log`;
|
||||
driver.sessionSubscribe({ events: [ 'log.entryAdded' ] });
|
||||
|
||||
driver.on('log.entryAdded', (entry: any) => {
|
||||
try {
|
||||
// @ts-ignore
|
||||
fs.appendFileSync(driver.logFile, `${entry.text}\n`);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the content of the log file.
|
||||
*
|
||||
* @param {WebdriverIO.Browser} driver - The driver which log file is requested.
|
||||
* @returns {string} The content of the log file.
|
||||
*/
|
||||
export function getLogs(driver: WebdriverIO.Browser) {
|
||||
// @ts-ignore
|
||||
if (!driver.logFile) {
|
||||
return;
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
return fs.readFileSync(driver.logFile, 'utf8');
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends value to the log file.
|
||||
* @param {WebdriverIO.Browser} driver - The driver which log file is requested.
|
||||
* @param {string} value - The content to add to the file.
|
||||
*/
|
||||
export function saveLogs(driver: WebdriverIO.Browser, value: string) {
|
||||
// @ts-ignore
|
||||
if (!driver.logFile) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// @ts-ignore
|
||||
fs.appendFileSync(driver.logFile, value);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs a message in the logfile.
|
||||
*
|
||||
* @param {WebdriverIO.Browser} driver - The participant in which log file to write.
|
||||
* @param {string} message - The message to add.
|
||||
* @returns {void}
|
||||
*/
|
||||
export async function logInfo(driver: WebdriverIO.Browser, message: string) {
|
||||
// @ts-ignore
|
||||
if (!driver.logFile) {
|
||||
return;
|
||||
}
|
||||
|
||||
return driver.execute((prefix, msg) =>
|
||||
console.log(`${new Date().toISOString()} ${prefix} ${msg}\n`),
|
||||
LOG_PREFIX, message);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user