From b6108e05ad71a099f78f189170bc95dafe59bcca Mon Sep 17 00:00:00 2001 From: Rui Figueira Date: Tue, 2 Jul 2024 16:32:45 +0100 Subject: [PATCH] test(trace-viewer): more trace viewer tests --- ...on.spec.ts => trace-viewer-legacy.spec.ts} | 22 ++--- tests/trace-viewer.spec.ts | 92 ++++++++++++++++++- 2 files changed, 99 insertions(+), 15 deletions(-) rename tests/{trace-viewer-old-pw-version.spec.ts => trace-viewer-legacy.spec.ts} (59%) diff --git a/tests/trace-viewer-old-pw-version.spec.ts b/tests/trace-viewer-legacy.spec.ts similarity index 59% rename from tests/trace-viewer-old-pw-version.spec.ts rename to tests/trace-viewer-legacy.spec.ts index 9a0e86976..fa6fa6f1e 100644 --- a/tests/trace-viewer-old-pw-version.spec.ts +++ b/tests/trace-viewer-legacy.spec.ts @@ -16,9 +16,15 @@ import { test, expect } from './utils'; -test.use({ showTrace: true, embedTraceViewer: true, overridePlaywrightVersion: 1.44 }); +test.beforeEach(({ showBrowser, overridePlaywrightVersion }) => { + test.skip(!overridePlaywrightVersion || showBrowser); + // prevents spawn trace viewer process from opening in browser + process.env.PWTEST_UNDER_TEST = '1'; +}); + +test.use({ showTrace: true, embedTraceViewer: true, envRemoteName: 'ssh-remote' }); -test('should hide embedded in older @playwright/test projects', async ({ activate }) => { +test('should fallback to spawn trace viewer in older @playwright/test projects', async ({ activate }) => { const { vscode, testController } = await activate({ 'playwright.config.js': `module.exports = { testDir: 'tests' }`, 'tests/test.spec.ts': ` @@ -27,18 +33,10 @@ test('should hide embedded in older @playwright/test projects', async ({ activat `, }); - const configuration = vscode.workspace.getConfiguration('playwright'); - - const settingsView = vscode.webViews.get('pw.extension.settingsView')!; - expect(configuration.get('showTrace')).toBe(true); - expect(configuration.get('embedTraceViewer')).toBe(true); - await expect(settingsView.getByLabel('Show trace viewer')).toBeVisible(); - await expect(settingsView.getByLabel('Embedded')).not.toBeVisible(); - await testController.expandTestItems(/test.spec/); const testItems = testController.findTestItems(/pass/); await testController.run(testItems); - const webview = await vscode.singleWebViewByPanelType('playwright.traceviewer.view'); - expect(webview).toBeUndefined(); + await expect.poll(() => vscode.warnings).toContain('Playwright v1.46+ is required for embedded trace viewer to work, v1.43 found'); + // TODO intercept /Listening on http:\/\/[^:]+:\d+/ }); diff --git a/tests/trace-viewer.spec.ts b/tests/trace-viewer.spec.ts index 4b025927a..1c15405c5 100644 --- a/tests/trace-viewer.spec.ts +++ b/tests/trace-viewer.spec.ts @@ -16,7 +16,13 @@ import { enableConfigs, expect, test } from './utils'; -test.use({ showTrace: true, embedTraceViewer: true }); +test.beforeEach(({ showBrowser, overridePlaywrightVersion }) => { + test.skip(!!overridePlaywrightVersion || showBrowser); + // prevents spawn trace viewer process from opening in browser + process.env.PWTEST_UNDER_TEST = '1'; +}); + +test.use({ showTrace: true, embedTraceViewer: true, envRemoteName: 'ssh-remote' }); test('should show tracer when test runs', async ({ activate }) => { const { vscode, testController } = await activate({ @@ -87,7 +93,7 @@ test('should toggle between dark and light themes', async ({ activate }) => { await expect(webview.frameLocator('iframe').locator('body')).toHaveClass('dark-mode'); - await configuration.update('colorTheme', 'Light Modern',true); + await configuration.update('colorTheme', 'Light Modern', true); await expect(webview.frameLocator('iframe').locator('body')).toHaveClass('light-mode'); await configuration.update('colorTheme', 'Dark Modern', true); @@ -181,7 +187,6 @@ test('should not change trace viewer when running tests from different test conf expect(serverUrl1).toEqual(serverUrl2); }); - test('should change trace viewer when test config changes', async ({ activate }) => { const { vscode, testController } = await activate({ 'playwright1.config.js': `module.exports = { testDir: 'tests1' }`, @@ -237,3 +242,84 @@ test('should change trace viewer when test config changes', async ({ activate }) expect(serverUrl1).not.toEqual(serverUrl2); }); + +test('should not open trace viewer if selected test item did not run', async ({ activate }) => { + const { vscode, testController } = await activate({ + 'playwright.config.js': `module.exports = { testDir: 'tests' }`, + 'tests/test.spec.ts': ` + import { test } from '@playwright/test'; + test('should pass', async () => {}); + `, + }); + + await testController.expandTestItems(/test.spec/); + const testItems = testController.findTestItems(/pass/); + + testItems[0].selected(); + + // wait to ensure no async webview is opened + await new Promise(f => setTimeout(f, 1000)); + await expect.poll(() => vscode.webViewsByPanelType('playwright.traceviewer.view')).toHaveLength(0); + expect(vscode.warnings).toHaveLength(0); +}); + +test('should not open trace viewer if selected test item has no trace', async ({ activate }) => { + const { vscode, testController } = await activate({ + 'playwright.config.js': `module.exports = { testDir: 'tests' }`, + 'tests/test.spec.ts': ` + import { test } from '@playwright/test'; + test('should pass', async () => {}); + `, + }); + + const configuration = vscode.workspace.getConfiguration('playwright'); + await configuration.update('showTrace', false, true); + + await testController.expandTestItems(/test.spec/); + const testItems = testController.findTestItems(/pass/); + await testController.run(testItems); + + await expect(testController).toHaveTestTree(` + - tests + - test.spec.ts + - ✅ should pass [2:0] + `); + + await configuration.update('showTrace', true, true); + testItems[0].selected(); + + // wait to ensure no async webview is opened + await new Promise(f => setTimeout(f, 1000)); + await expect.poll(() => vscode.webViewsByPanelType('playwright.traceviewer.view')).toHaveLength(0); + expect(vscode.warnings).toHaveLength(0); +}); + +test('should fallback to spawn trace viewer if embedded not enabled', async ({ activate }) => { + const { vscode, testController } = await activate({ + 'playwright.config.js': `module.exports = { testDir: 'tests' }`, + 'tests/test.spec.ts': ` + import { test } from '@playwright/test'; + test('should pass', async () => {}); + `, + }); + + const configuration = vscode.workspace.getConfiguration('playwright'); + configuration.update('embedTraceViewer', false, true); + + await testController.expandTestItems(/test.spec/); + const testItems = testController.findTestItems(/pass/); + await testController.run(testItems); + + await expect(testController).toHaveTestTree(` + - tests + - test.spec.ts + - ✅ should pass [2:0] + `); + + // wait to ensure no async webview is opened + await new Promise(f => setTimeout(f, 1000)); + await expect.poll(() => vscode.webViewsByPanelType('playwright.traceviewer.view')).toHaveLength(0); + expect(vscode.warnings).toHaveLength(0); + + // TODO intercept /Listening on http:\/\/[^:]+:\d+/ +});