Skip to content

Commit

Permalink
E2E: start-in-background: Force shut down when restarting.
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Yen <mark.yen@suse.com>
  • Loading branch information
mook-as committed Jun 28, 2023
1 parent c261fd8 commit 755a85f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
6 changes: 3 additions & 3 deletions e2e/start-in-background.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import path from 'path';

import { test, expect, _electron, ElectronApplication } from '@playwright/test';

import { createDefaultSettings, packageLogs, startRancherDesktop } from './utils/TestUtils';
import { createDefaultSettings, packageLogs, startRancherDesktop, teardownApp } from './utils/TestUtils';

/**
* Using test.describe.serial make the test execute step by step, as described on each `test()` order
Expand All @@ -21,7 +21,7 @@ test.describe.serial('startInBackground setting', () => {
const tracePath = path.join(__dirname, 'reports', `${ path.basename(__filename) }-startInBackgroundFalse.zip`);

electronApp.context().tracing.stop({ path: tracePath });
await electronApp.close();
await teardownApp(electronApp);
});

test('window should not appear when startInBackground is true', async() => {
Expand All @@ -32,7 +32,7 @@ test.describe.serial('startInBackground setting', () => {
const tracePath = path.join(__dirname, 'reports', `${ path.basename(__filename) }-startInBackgroundTrue.zip`);

electronApp.context().tracing.stop({ path: tracePath });
await electronApp.close();
await teardownApp(electronApp);
});
});

Expand Down
20 changes: 16 additions & 4 deletions e2e/utils/TestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,18 @@ export async function packageLogs(testPath: string) {
await childProcess.spawnFile('tar', ['cfh', outputPath, '.'], { cwd: logDir, stdio: 'inherit' });
}

export async function teardown(app: ElectronApplication, filename: string) {
const context = app.context();
/**
* Tear down the application, without managing logging. This should only be
* used when doing atypical tests that need to restart the application within
* the test. This is normally used instead of `app.close()`.
*
* @note teardown() should be used where possible.
*/
export async function teardownApp(app: ElectronApplication) {
const proc = app.process();
const pid = proc.pid;

try {
await context.tracing.stop({ path: reportAsset(filename) });
await packageLogs(filename);
// Allow one minute for shutdown
await Promise.race([
app.close(),
Expand Down Expand Up @@ -183,6 +187,14 @@ export async function teardown(app: ElectronApplication, filename: string) {
}
}
}
}

export async function teardown(app: ElectronApplication, filename: string) {
const context = app.context();

await context.tracing.stop({ path: reportAsset(filename) });
await packageLogs(filename);
await teardownApp(app);

if (testInfo?.testPath === filename) {
const delta = (Date.now() - testInfo.startTime) / 1_000;
Expand Down

0 comments on commit 755a85f

Please sign in to comment.