From bbf2934879d40da1b05ced72fae428018d8e98f8 Mon Sep 17 00:00:00 2001 From: Kent Wang Date: Fri, 7 Mar 2025 10:44:02 +0800 Subject: [PATCH] chore: Try to improve smoke test tracing to figure failure/flaky case causes [INS-5056] (#8431) * improve the tracing --- .../insomnia-smoke-test/playwright/test.ts | 25 ++++++++++++++----- .../smoke/pre-request-script-features.test.ts | 4 +-- .../tests/smoke/runner.test.ts | 4 +-- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/packages/insomnia-smoke-test/playwright/test.ts b/packages/insomnia-smoke-test/playwright/test.ts index 30b2577341..c5d6b4f5d6 100644 --- a/packages/insomnia-smoke-test/playwright/test.ts +++ b/packages/insomnia-smoke-test/playwright/test.ts @@ -123,12 +123,25 @@ export const test = baseTest.extend<{ await appContext.tracing.start(traceOptions); } - await use(electronApp); - - if (captureTrace) { - await appContext.tracing.stop({ - path: path.join(testInfo.outputDir, 'trace.zip'), - }); + let testFailed = false; + try { + await use(electronApp); + } catch (error) { + testFailed = true; + throw error; + } finally { + // set testFailed to true if the test timed out or failed + testFailed = testFailed || testInfo.status === 'timedOut' || testInfo.status === 'failed'; + if (traceMode === 'on' || (traceMode === 'retain-on-failure' && testFailed) || (traceMode === 'on-first-retry' && testInfo.retry === 1)) { + // Use a different name rather than the default trace.zip to avoid overwriting the trace. + // Refer: https://github.com/microsoft/playwright/issues/35005 + await appContext.tracing.stop({ + path: path.join(testInfo.outputDir, `trace-${testInfo.title}-${testInfo.status}.zip`), + }); + } else { + // Discard the trace if not needed + await appContext.tracing.stop(); + } } await electronApp.close(); diff --git a/packages/insomnia-smoke-test/tests/smoke/pre-request-script-features.test.ts b/packages/insomnia-smoke-test/tests/smoke/pre-request-script-features.test.ts index 7674447d4e..cb0b111097 100644 --- a/packages/insomnia-smoke-test/tests/smoke/pre-request-script-features.test.ts +++ b/packages/insomnia-smoke-test/tests/smoke/pre-request-script-features.test.ts @@ -445,8 +445,8 @@ test.describe('pre-request features tests', async () => { await page.getByRole('tab', { name: 'Tests' }).click(); const responsePane = page.getByTestId('response-pane'); - expect(responsePane).toContainText('FAILunhappy tests | error: AssertionError: expected 199 to deeply equal 200 | ACTUAL: 199 | EXPECTED: 200Pre-request Test'); - expect(responsePane).toContainText('PASShappy tests'); + await expect(responsePane).toContainText('FAILunhappy tests | error: AssertionError: expected 199 to deeply equal 200 | ACTUAL: 199 | EXPECTED: 200Pre-request Test'); + await expect(responsePane).toContainText('PASShappy tests'); }); test('environment and baseEnvironment can be persisted', async ({ page }) => { diff --git a/packages/insomnia-smoke-test/tests/smoke/runner.test.ts b/packages/insomnia-smoke-test/tests/smoke/runner.test.ts index 0de96e4252..6468056d9f 100644 --- a/packages/insomnia-smoke-test/tests/smoke/runner.test.ts +++ b/packages/insomnia-smoke-test/tests/smoke/runner.test.ts @@ -291,9 +291,9 @@ test.describe('runner features tests', async () => { const consoleTabContent = page.locator('.pane-two'); if (expectToHaveLog) { - expect(consoleTabContent).toContainText("it won't print"); + await expect(consoleTabContent).toContainText("it won't print"); } else { - expect(consoleTabContent).not.toContainText("it won't print"); + await expect(consoleTabContent).not.toContainText("it won't print"); } } });