Skip to content

Commit bee11cb

Browse files
authored
fix(expect): report expect.poll and expect.toPass as "expect" steps (#37356)
1 parent ca0e7c8 commit bee11cb

3 files changed

Lines changed: 12 additions & 12 deletions

File tree

packages/playwright/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,8 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures> = ({
265265
if (!testInfo || data.apiName.includes('setTestIdAttribute') || data.apiName === 'tracing.groupEnd')
266266
return;
267267
const zone = currentZone().data<TestStepInternal>('stepZone');
268-
if (zone && zone.category === 'expect') {
268+
const isExpectCall = data.apiName === 'locator._expect' || data.apiName === 'frame._expect' || data.apiName === 'page._expectScreenshot';
269+
if (zone && zone.category === 'expect' && isExpectCall) {
269270
// Display the internal locator._expect call under the name of the enclosing expect call,
270271
// and connect it to the existing expect step.
271272
if (zone.apiName)

packages/playwright/src/matchers/expect.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ import { TestInfoImpl } from '../worker/testInfo';
6868

6969
import type { ExpectMatcherStateInternal } from './matchers';
7070
import type { Expect } from '../../types/test';
71-
import type { TestStepCategory, TestStepInfoImpl } from '../worker/testInfo';
71+
import type { TestStepInfoImpl } from '../worker/testInfo';
7272

7373

7474
// #region
@@ -351,12 +351,11 @@ class ExpectMetaInfoProxyHandler implements ProxyHandler<any> {
351351
// This looks like it is unnecessary, but it isn't - we need to filter
352352
// out all the frames that belong to the test runner from caught runtime errors.
353353
const stackFrames = filteredStackTrace(captureRawStack());
354-
const category = matcherName === 'toPass' || this._info.poll ? 'test.step' : 'expect' as TestStepCategory;
355354

356355
// toPass and poll matchers can contain other steps, expects and API calls,
357356
// so they behave like a retriable step.
358357
const stepInfo = {
359-
category,
358+
category: 'expect' as const,
360359
apiName,
361360
title,
362361
params: args[0] ? { expected: args[0] } : undefined,

tests/playwright-test/test-step.spec.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ test('should not propagate errors from within toPass', async ({ runInlineTest })
640640
expect(result.exitCode).toBe(0);
641641
expect(result.output).toBe(`
642642
hook |Before Hooks
643-
test.step |Expect "toPass" @ a.test.ts:7
643+
expect |Expect "toPass" @ a.test.ts:7
644644
expect | Expect "toBe" @ a.test.ts:6
645645
expect | ↪ error: Error: expect(received).toBe(expected) // Object.is equality
646646
expect | Expect "toBe" @ a.test.ts:6
@@ -667,8 +667,8 @@ test('should show final toPass error', async ({ runInlineTest }) => {
667667
expect(result.exitCode).toBe(1);
668668
expect(stripAnsi(result.output)).toBe(`
669669
hook |Before Hooks
670-
test.step |Expect "toPass" @ a.test.ts:6
671-
test.step |↪ error: Error: expect(received).toBe(expected) // Object.is equality
670+
expect |Expect "toPass" @ a.test.ts:6
671+
expect |↪ error: Error: expect(received).toBe(expected) // Object.is equality
672672
expect | Expect "toBe" @ a.test.ts:5
673673
expect | ↪ error: Error: expect(received).toBe(expected) // Object.is equality
674674
hook |After Hooks
@@ -934,7 +934,7 @@ test('step inside toPass', async ({ runInlineTest }) => {
934934
expect(stripAnsi(result.output)).toBe(`
935935
hook |Before Hooks
936936
test.step |step 1 @ a.test.ts:4
937-
test.step | Expect "toPass" @ a.test.ts:11
937+
expect | Expect "toPass" @ a.test.ts:11
938938
test.step | step 2, attempt: 0 @ a.test.ts:7
939939
test.step | ↪ error: Error: expect(received).toBe(expected) // Object.is equality
940940
expect | Expect "toBe" @ a.test.ts:9
@@ -981,7 +981,7 @@ fixture | Fixture "context"
981981
pw:api | Create context
982982
fixture | Fixture "page"
983983
pw:api | Create page
984-
test.step |Expect "toPass" @ a.test.ts:11
984+
expect |Expect "toPass" @ a.test.ts:11
985985
pw:api | Navigate to "about:blank" @ a.test.ts:6
986986
test.step | inner step attempt: 0 @ a.test.ts:7
987987
test.step | ↪ error: Error: expect(received).toBe(expected) // Object.is equality
@@ -1033,7 +1033,7 @@ fixture | Fixture "context"
10331033
pw:api | Create context
10341034
fixture | Fixture "page"
10351035
pw:api | Create page
1036-
test.step |Expect "poll toHaveLength" @ a.test.ts:14
1036+
expect |Expect "poll toHaveLength" @ a.test.ts:14
10371037
pw:api | Navigate to "about:blank" @ a.test.ts:7
10381038
test.step | inner step attempt: 0 @ a.test.ts:8
10391039
expect | Expect "toBe" @ a.test.ts:10
@@ -1086,7 +1086,7 @@ pw:api | Create context
10861086
fixture | Fixture "page"
10871087
pw:api | Create page
10881088
pw:api |Set content @ a.test.ts:4
1089-
test.step |Expect "poll toBe" @ a.test.ts:13
1089+
expect |Expect "poll toBe" @ a.test.ts:13
10901090
expect | Expect "toHaveText" @ a.test.ts:7
10911091
test.step | iteration 1 @ a.test.ts:9
10921092
expect | Expect "toBeVisible" @ a.test.ts:10
@@ -1746,7 +1746,7 @@ fixture | Fixture "page"
17461746
pw:api | Create page
17471747
pw:api |Set content @ a.test.ts:16
17481748
expect |Expect "toBeInvisible" @ a.test.ts:17
1749-
test.step | Expect "poll toBe" @ a.test.ts:7
1749+
expect | Expect "poll toBe" @ a.test.ts:7
17501750
pw:api | Query count locator('div').filter({ visible: true }) @ a.test.ts:7
17511751
expect | Expect "toBe" @ a.test.ts:7
17521752
expect | ↪ error: Error: expect(received).toBe(expected) // Object.is equality

0 commit comments

Comments
 (0)