Skip to content
This repository has been archived by the owner on Jan 1, 2025. It is now read-only.

Commit

Permalink
test: add launch test in beforeAll
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsSim committed Sep 7, 2024
1 parent 20b8865 commit c490ca6
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion app/tests/e2e/util/setup-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { test } = require( '@playwright/test' );
const { findLatestBuild, parseElectronApp } = require( 'electron-playwright-helpers' );
const fs = require( 'fs-extra' );
const path = require( 'path' );
const { spawn } = require( 'child_process' );

module.exports = () => {
/** @type {import('playwright').Page} */
Expand All @@ -29,7 +30,7 @@ module.exports = () => {
/** @type {string[]} */
let logs = [];

test.beforeAll( () => {
test.beforeAll( async () => {

Check failure on line 33 in app/tests/e2e/util/setup-test.js

View workflow job for this annotation

GitHub Actions / build-launcher (macos-latest)

tests/e2e/01-main.spec.js:8:3 › main › starts the app

1) tests/e2e/01-main.spec.js:8:3 › main › starts the app ───────────────────────────────────────── "beforeAll" hook timeout of 30000ms exceeded. at tests/e2e/util/setup-test.js:33 31 | let logs = []; 32 | > 33 | test.beforeAll( async () => { | ^ 34 | latestBuild = findLatestBuild( '../release' ); 35 | console.log( '[beforeAll] latestBuild', latestBuild ); 36 | appInfo = parseElectronApp( latestBuild ); at /Users/runner/work/fsolauncher/fsolauncher/app/tests/e2e/util/setup-test.js:33:8
latestBuild = findLatestBuild( '../release' );
console.log( '[beforeAll] latestBuild', latestBuild );
appInfo = parseElectronApp( latestBuild );
Expand All @@ -49,6 +50,52 @@ module.exports = () => {
console.info( '[beforeAll] appInfo', appInfo );
console.info( '[beforeAll] appData', appData );
console.info( '[beforeAll] installDir', installDir );

// Wrap the Electron launch in a promise
await new Promise( ( resolve, reject ) => {
const electronProcess = spawn( appInfo.executable, [ appInfo.main, '--disable-http-cache', '--fl-test-mode' ], {
cwd: exeDir,
stdio: [ 'ignore', 'pipe', 'pipe' ]
} );

let isReady = false;

electronProcess.stdout.on( 'data', ( data ) => {
console.info( `[electron stdout] ${data}` );
// Check for a specific output to confirm readiness
if ( data.toString().includes( 'loaded userSettings' ) ) {
isReady = true;
resolve();
}
} );

electronProcess.stderr.on( 'data', ( data ) => {
console.error( `[electron stderr] ${data}` );
} );

electronProcess.on( 'error', ( err ) => {
console.error( '[electron error]', err );
reject( err );
} );

electronProcess.on( 'close', ( code ) => {
if ( isReady ) {
console.info( `[electron process exited with code ${code}]` );
} else {
console.warn( '[electron process did not signal readiness]' );
reject( new Error( 'Electron process did not signal readiness' ) );
}
} );

// Optionally set a timeout if you want to kill the process after a certain period
setTimeout( () => {
if ( ! isReady ) {
electronProcess.kill();
console.info( '[beforeAll] Electron process killed due to timeout.' );
reject( new Error( 'Electron process did not become ready in time' ) );
}
}, 30000 ); // Adjust timeout if needed
} );
} );

test.beforeEach( async () => {
Expand Down

0 comments on commit c490ca6

Please sign in to comment.