From 7f7dfe87df09c54d7f3ebe8eb9c69c2ddd1df43c Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Fri, 31 Jan 2025 15:06:00 -0800 Subject: [PATCH] address comments --- docs/src/test-api/class-teststepinfo.md | 4 ++-- docs/src/test-reporter-api/class-teststep.md | 2 +- packages/playwright/src/common/ipc.ts | 2 +- packages/playwright/src/isomorphic/teleReceiver.ts | 2 +- packages/playwright/src/reporters/teleEmitter.ts | 2 +- packages/playwright/src/runner/dispatcher.ts | 1 + packages/playwright/src/worker/testInfo.ts | 11 +++-------- packages/playwright/types/test.d.ts | 4 ++-- packages/playwright/types/testReporter.d.ts | 2 +- 9 files changed, 13 insertions(+), 17 deletions(-) diff --git a/docs/src/test-api/class-teststepinfo.md b/docs/src/test-api/class-teststepinfo.md index c02434644c..d611b49e6c 100644 --- a/docs/src/test-api/class-teststepinfo.md +++ b/docs/src/test-api/class-teststepinfo.md @@ -2,14 +2,14 @@ * since: v1.51 * langs: js -`TestStepInfo` contains information about currently running test step. It is pass as an argument to the step function. `TestStepInfo` provides utilities to control test step execution. +`TestStepInfo` contains information about currently running test step. It is passed as an argument to the step function. `TestStepInfo` provides utilities to control test step execution. ```js import { test, expect } from '@playwright/test'; test('basic test', async ({ page, browserName }, TestStepInfo) => { await test.step('check some behavior', async step => { - await step.skip(browserName === 'webkit, 'The feature is not available in WebKit'); + await step.skip(browserName === 'webkit', 'The feature is not available in WebKit'); //... rest of the step code await page.check('input'); }); diff --git a/docs/src/test-reporter-api/class-teststep.md b/docs/src/test-reporter-api/class-teststep.md index ed7325b1fc..1272eb546f 100644 --- a/docs/src/test-reporter-api/class-teststep.md +++ b/docs/src/test-reporter-api/class-teststep.md @@ -52,7 +52,7 @@ List of steps inside this step. ## property: TestStep.annotations * since: v1.51 -- type: ?<[Array]<[Object]>> +- type: <[Array]<[Object]>> - `type` <[string]> Annotation type, for example `'skip'`. - `description` ?<[string]> Optional description. diff --git a/packages/playwright/src/common/ipc.ts b/packages/playwright/src/common/ipc.ts index 9080a2d891..2e085f5b78 100644 --- a/packages/playwright/src/common/ipc.ts +++ b/packages/playwright/src/common/ipc.ts @@ -109,7 +109,7 @@ export type StepEndPayload = { wallTime: number; // milliseconds since unix epoch error?: TestInfoErrorImpl; suggestedRebaseline?: string; - annotations?: { type: string, description?: string }[]; + annotations: { type: string, description?: string }[]; }; export type TestEntry = { diff --git a/packages/playwright/src/isomorphic/teleReceiver.ts b/packages/playwright/src/isomorphic/teleReceiver.ts index dabfdf83fc..1eb83df623 100644 --- a/packages/playwright/src/isomorphic/teleReceiver.ts +++ b/packages/playwright/src/isomorphic/teleReceiver.ts @@ -549,7 +549,7 @@ class TeleTestStep implements reporterTypes.TestStep { } get annotations() { - return this._endPayload?.annotations; + return this._endPayload?.annotations ?? []; } } diff --git a/packages/playwright/src/reporters/teleEmitter.ts b/packages/playwright/src/reporters/teleEmitter.ts index 98cd49d593..eadd2b05a5 100644 --- a/packages/playwright/src/reporters/teleEmitter.ts +++ b/packages/playwright/src/reporters/teleEmitter.ts @@ -257,7 +257,7 @@ export class TeleReporterEmitter implements ReporterV2 { duration: step.duration, error: step.error, attachments: step.attachments.map(a => result.attachments.indexOf(a)), - annotations: step.annotations, + annotations: step.annotations.length ? step.annotations : undefined, }; } diff --git a/packages/playwright/src/runner/dispatcher.ts b/packages/playwright/src/runner/dispatcher.ts index 9adf0a434c..9f6367c106 100644 --- a/packages/playwright/src/runner/dispatcher.ts +++ b/packages/playwright/src/runner/dispatcher.ts @@ -321,6 +321,7 @@ class JobDispatcher { duration: -1, steps: [], attachments: [], + annotations: [], location: params.location, }; steps.set(params.stepId, step); diff --git a/packages/playwright/src/worker/testInfo.ts b/packages/playwright/src/worker/testInfo.ts index 8a832dd647..09ce7a0ddd 100644 --- a/packages/playwright/src/worker/testInfo.ts +++ b/packages/playwright/src/worker/testInfo.ts @@ -508,16 +508,11 @@ export class TestInfoImpl implements TestInfo { } export class TestStepInfoImpl implements TestStepInfo { - annotations?: Annotation[]; - - private _addAnnotation(type: string, description?: string) { - this.annotations ??= []; - this.annotations.push({ type, description }); - } + annotations: Annotation[] = []; async _runStepBody(skip: boolean, body: (step: TestStepInfo) => T | Promise) { if (skip) { - this._addAnnotation('skip'); + this.annotations.push({ type: 'skip' }); return undefined as T; } try { @@ -535,7 +530,7 @@ export class TestStepInfoImpl implements TestStepInfo { if (args.length > 0 && !args[0]) return; const description = args[1] as (string|undefined); - this._addAnnotation('skip', description); + this.annotations.push({ type: 'skip', description }); throw new SkipError(description); } } diff --git a/packages/playwright/types/test.d.ts b/packages/playwright/types/test.d.ts index 05c5187e2d..65870365b9 100644 --- a/packages/playwright/types/test.d.ts +++ b/packages/playwright/types/test.d.ts @@ -9554,7 +9554,7 @@ export interface TestInfoError { } /** - * `TestStepInfo` contains information about currently running test step. It is pass as an argument to the step + * `TestStepInfo` contains information about currently running test step. It is passed as an argument to the step * function. `TestStepInfo` provides utilities to control test step execution. * * ```js @@ -9562,7 +9562,7 @@ export interface TestInfoError { * * test('basic test', async ({ page, browserName }, TestStepInfo) => { * await test.step('check some behavior', async step => { - * await step.skip(browserName === 'webkit, 'The feature is not available in WebKit'); + * await step.skip(browserName === 'webkit', 'The feature is not available in WebKit'); * //... rest of the step code * await page.check('input'); * }); diff --git a/packages/playwright/types/testReporter.d.ts b/packages/playwright/types/testReporter.d.ts index 1ef084865a..9662faee73 100644 --- a/packages/playwright/types/testReporter.d.ts +++ b/packages/playwright/types/testReporter.d.ts @@ -694,7 +694,7 @@ export interface TestStep { /** * The list of annotations applicable to the current test step. */ - annotations?: Array<{ + annotations: Array<{ /** * Annotation type, for example `'skip'`. */