Skip to content

Commit

Permalink
Add custom logging output for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
muffinista committed Feb 2, 2024
1 parent 9848996 commit e2a4ac9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1881,6 +1881,11 @@ const windowMethods = {
log.transports.file.level = "debug";
log.transports.file.maxSize = 1 * 1024 * 1024;

if (process.env.LOG_FILE) {
log.transports.file.resolvePathFn = () => process.env.LOG_FILE;
}


log.info(`Hello from version: ${global.APP_VERSION_BASE} running in ${isDev ? "development" : "production"}`);

if ( isDev ) {
Expand Down
Binary file modified test/fixtures/test-savers.zip
Binary file not shown.
19 changes: 16 additions & 3 deletions test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import * as path from "path";
import fs from 'fs-extra';
import * as tmp from "tmp";
import temp from "temp";

import Conf from "conf";

Expand Down Expand Up @@ -158,14 +159,15 @@ export function removeLocalSource(workingDir) {
* @param {boolean} quietMode
* @returns application
*/
export async function application(workingDir, quietMode=false) {
export async function application(workingDir, quietMode=false, logFile=undefined) {
let env = {
BEFORE_DAWN_DIR: workingDir,
CONFIG_DIR: workingDir,
SAVERS_DIR: workingDir,
TEST_MODE: true,
QUIET_MODE: quietMode,
ELECTRON_ENABLE_LOGGING: true
ELECTRON_ENABLE_LOGGING: true,
LOG_FILE: logFile
};

let a = await playwright.launch({
Expand All @@ -185,14 +187,18 @@ export async function application(workingDir, quietMode=false) {
// wait for the first window (our test shim) to open, and
// hang onto it for later use
shim = await a.firstWindow();

app = a;

return a;
}

export async function dumpOutput(app) {
console.log(app.logData);
app.logData = [];

if (path.existsSync(logPath)) {
console.log(fs.readFileSync(logPath));
}
}

/**
Expand Down Expand Up @@ -331,10 +337,17 @@ export async function callIpc(_app, method, opts={}) {
await window.click("text=go");
}

let logPath;

export function setupTest(test) {
test.timeout(testTimeout);
test.retries(testRetryCount);

// eslint-disable-next-line mocha/no-top-level-hooks
beforeEach(function () {
logPath = temp.path();
});

// eslint-disable-next-line mocha/no-top-level-hooks
afterEach(async function () {
if (this.currentTest.state !== "passed") {
Expand Down

0 comments on commit e2a4ac9

Please sign in to comment.