From 755a85f26542a52f0d81eaae8a29ec1e1f33d557 Mon Sep 17 00:00:00 2001 From: Mark Yen Date: Tue, 27 Jun 2023 14:38:24 -0700 Subject: [PATCH] E2E: start-in-background: Force shut down when restarting. Signed-off-by: Mark Yen --- e2e/start-in-background.e2e.spec.ts | 6 +++--- e2e/utils/TestUtils.ts | 20 ++++++++++++++++---- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/e2e/start-in-background.e2e.spec.ts b/e2e/start-in-background.e2e.spec.ts index b4999175c72..afb8bd0a0ce 100644 --- a/e2e/start-in-background.e2e.spec.ts +++ b/e2e/start-in-background.e2e.spec.ts @@ -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 @@ -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() => { @@ -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); }); }); diff --git a/e2e/utils/TestUtils.ts b/e2e/utils/TestUtils.ts index 303f2a91855..aa4d0e7b107 100644 --- a/e2e/utils/TestUtils.ts +++ b/e2e/utils/TestUtils.ts @@ -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(), @@ -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;