From afe90d648e94f37dc0c4b7945c029214a0bee741 Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Wed, 13 Dec 2023 09:06:02 -0800 Subject: [PATCH] fix: do not generate api call steps inside named expects (#28609) Fixes: https://github.com/microsoft/playwright/issues/28528 --- .../src/client/channelOwner.ts | 4 +- packages/playwright/src/index.ts | 2 +- tests/playwright-test/test-step.spec.ts | 92 +++++++++++++++++++ 3 files changed, 96 insertions(+), 2 deletions(-) diff --git a/packages/playwright-core/src/client/channelOwner.ts b/packages/playwright-core/src/client/channelOwner.ts index c41be351bd501..b493e7d5d5514 100644 --- a/packages/playwright-core/src/client/channelOwner.ts +++ b/packages/playwright-core/src/client/channelOwner.ts @@ -180,7 +180,9 @@ export abstract class ChannelOwner = ({ const csiListener: ClientInstrumentationListener = { onApiCallBegin: (apiName: string, params: Record, frames: StackFrame[], wallTime: number, userData: any) => { const testInfo = currentTestInfo(); - if (!testInfo || apiName.startsWith('expect.') || apiName.includes('setTestIdAttribute')) + if (!testInfo || apiName.includes('setTestIdAttribute')) return { userObject: null }; const step = testInfo._addStep({ location: frames[0] as any, diff --git a/tests/playwright-test/test-step.spec.ts b/tests/playwright-test/test-step.spec.ts index c22270277e60d..c8590b7e4faf3 100644 --- a/tests/playwright-test/test-step.spec.ts +++ b/tests/playwright-test/test-step.spec.ts @@ -1385,3 +1385,95 @@ test('should step w/ box', async ({ runInlineTest }) => { }, ]); }); + +test('should not generate dupes for named expects', async ({ runInlineTest }) => { + const result = await runInlineTest({ + 'reporter.ts': stepHierarchyReporter, + 'playwright.config.ts': ` + module.exports = { + reporter: './reporter', + }; + `, + 'a.test.ts': ` + import { test, expect } from '@playwright/test'; + test('timeout', async ({ page }) => { + await page.setContent('
hi
'); + await expect(page.locator('div'), 'Checking color') + .toHaveCSS('background-color', 'rgb(1, 2, 3)'); + }); + ` + }, { reporter: '', workers: 1, timeout: 2000 }); + + expect(result.exitCode).toBe(0); + const objects = result.outputLines.map(line => JSON.parse(line)); + expect(objects).toEqual([ + { + category: 'hook', + title: 'Before Hooks', + steps: [ + { + category: 'fixture', + title: 'fixture: browser', + steps: [ + { + category: 'pw:api', + title: 'browserType.launch', + }, + ] + }, + { + category: 'fixture', + title: 'fixture: context', + steps: [ + { + category: 'pw:api', + title: 'browser.newContext', + }, + ] + }, + { + category: 'fixture', + title: 'fixture: page', + steps: [ + { + category: 'pw:api', + title: 'browserContext.newPage', + }, + ] + }, + ], + }, + { + category: 'pw:api', + title: 'page.setContent', + location: { + column: expect.any(Number), + file: 'a.test.ts', + line: expect.any(Number), + }, + }, + { + category: 'expect', + title: 'Checking color', + location: { + column: expect.any(Number), + file: 'a.test.ts', + line: expect.any(Number), + }, + }, + { + category: 'hook', + title: 'After Hooks', + steps: [ + { + category: 'fixture', + title: 'fixture: page', + }, + { + category: 'fixture', + title: 'fixture: context', + }, + ], + }, + ]); +}); \ No newline at end of file