This repository has been archived by the owner on Jan 1, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
142 additions
and
246 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,15 @@ | ||
const { _electron: electron } = require( 'playwright' ); | ||
const { test, expect } = require( '@playwright/test' ); | ||
const { findLatestBuild, parseElectronApp } = require( 'electron-playwright-helpers' ); | ||
const fs = require( 'fs-extra' ); | ||
const setupTest = require( './setup-test' ); | ||
|
||
test.describe( 'main', () => { | ||
/** @type {import('playwright').Page} */ | ||
let window; | ||
|
||
/** @type {import('playwright').ElectronApplication} */ | ||
let electronApp; | ||
|
||
/** @type {string} */ | ||
let latestBuild; | ||
|
||
/** @type {import('electron-playwright-helpers').ElectronAppInfo} */ | ||
let appInfo; | ||
|
||
/** @type {string} */ | ||
let exeDir; | ||
|
||
/** @type {string} */ | ||
let appData; | ||
|
||
test.beforeAll( () => { | ||
latestBuild = findLatestBuild( '../release' ); | ||
appInfo = parseElectronApp( latestBuild ); | ||
exeDir = require( 'path' ).dirname( appInfo.executable ); | ||
appData = process.platform == 'win32' ? exeDir : | ||
require( 'os' ).homedir() + '/Library/Application Support/FreeSO Launcher'; | ||
|
||
// Delete config file if it exists before testing | ||
fs.existsSync( `${appData}/FSOLauncher.ini` ) && fs.unlinkSync( `${appData}/FSOLauncher.ini` ); | ||
} ); | ||
|
||
test.beforeEach( async () => { | ||
// Pass in --test-mode for headless testing | ||
electronApp = await electron.launch( { | ||
timeout: 60000, | ||
cwd: exeDir, | ||
args: [ appInfo.main, '--test-mode=true' ], // Main file from package.json | ||
executablePath: appInfo.executable // Path to the Electron executable | ||
} ); | ||
console.info( '[beforeEach] launched electronApp' ); | ||
|
||
// Log main process | ||
electronApp.process().stdout.on( 'data', data => console.info( `[main] ${data}` ) ); | ||
electronApp.process().stderr.on( 'data', error => console.info( `[main] ${error}` ) ); | ||
|
||
window = await electronApp.firstWindow(); | ||
console.info( '[beforeEach] waited for firstWindow' ); | ||
|
||
// Log renderer process | ||
window.on( 'console', log => console.info( `[renderer] ${log.text()}` ) ); | ||
|
||
await window.waitForLoadState( 'load' ); // Waits for the page to be completely loaded | ||
console.info( '[beforeEach] achieved loadState' ); | ||
await window.locator( '[data-insprog="true"]' ).waitFor(); | ||
console.info( '[beforeEach] INS_PROG was received by renderer' ); | ||
} ); | ||
|
||
test.afterEach( async () => { | ||
try { | ||
console.info( '[afterEach] setting global.willQuit to true...' ); | ||
await electronApp.evaluate( async () => global.willQuit = true ); | ||
console.info( '[afterEach] global.willQuit has been set to true - attempting to close the app...' ); | ||
await electronApp.close(); | ||
console.info( '[afterEach] the app has been closed.' ); | ||
} catch ( err ) { | ||
console.error( '[afterEach] an error occurred:', err ); | ||
} | ||
} ); | ||
const T = setupTest( test ); | ||
|
||
test( 'starts the app', () => { | ||
// Setup and teardown | ||
} ); | ||
|
||
test( 'config file is present', async () => { | ||
expect( await fs.exists( appData + '/FSOLauncher.ini' ) ).toBeTruthy(); | ||
expect( await fs.exists( T.getAppData() + '/FSOLauncher.ini' ) ).toBeTruthy(); | ||
} ); | ||
} ); |
Oops, something went wrong.