diff --git a/packages/html-reporter/src/testCaseView.tsx b/packages/html-reporter/src/testCaseView.tsx index 16d4900725a11..874b7b2fdd4ba 100644 --- a/packages/html-reporter/src/testCaseView.tsx +++ b/packages/html-reporter/src/testCaseView.tsx @@ -14,7 +14,8 @@ limitations under the License. */ -import type { TestCase, TestAnnotation, TestCaseSummary } from './types'; +import type { TestAnnotation } from '@playwright/test'; +import type { TestCase, TestCaseSummary } from './types'; import * as React from 'react'; import { TabbedPane } from './tabbedPane'; import { AutoChip } from './chip'; diff --git a/packages/html-reporter/src/types.d.ts b/packages/html-reporter/src/types.d.ts index 17c5a3b3730a4..4225cc050c5fe 100644 --- a/packages/html-reporter/src/types.d.ts +++ b/packages/html-reporter/src/types.d.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import type { Metadata } from '@playwright/test'; +import type { TestAnnotation, Metadata } from '@playwright/test'; export type Stats = { total: number; @@ -59,8 +59,6 @@ export type TestFileSummary = { stats: Stats; }; -export type TestAnnotation = { type: string, description?: string }; - export type TestCaseSummary = { testId: string, title: string; diff --git a/packages/playwright/src/common/config.ts b/packages/playwright/src/common/config.ts index bcf28d8df3867..d7c1854211ca0 100644 --- a/packages/playwright/src/common/config.ts +++ b/packages/playwright/src/common/config.ts @@ -36,7 +36,6 @@ export type FixturesWithLocation = { fixtures: Fixtures; location: Location; }; -export type Annotation = { type: string, description?: string }; export const defaultTimeout = 30000; diff --git a/packages/playwright/src/common/test.ts b/packages/playwright/src/common/test.ts index 2b6434a2efe52..7ef91d27c5dd5 100644 --- a/packages/playwright/src/common/test.ts +++ b/packages/playwright/src/common/test.ts @@ -17,9 +17,10 @@ import { rootTestType } from './testType'; import { computeTestCaseOutcome } from '../isomorphic/teleReceiver'; -import type { Annotation, FixturesWithLocation, FullProjectInternal } from './config'; +import type { FixturesWithLocation, FullProjectInternal } from './config'; import type { FixturePool } from './fixtures'; import type { TestTypeImpl } from './testType'; +import type { TestAnnotation } from '../../types/test'; import type * as reporterTypes from '../../types/testReporter'; import type { FullProject, Location } from '../../types/testReporter'; @@ -50,7 +51,7 @@ export class Suite extends Base { _timeout: number | undefined; _retries: number | undefined; // Annotations known statically before running the test, e.g. `test.describe.skip()` or `test.describe({ annotation }, body)`. - _staticAnnotations: Annotation[] = []; + _staticAnnotations: TestAnnotation[] = []; // Explicitly declared tags that are not a part of the title. _tags: string[] = []; _modifiers: Modifier[] = []; @@ -252,7 +253,7 @@ export class TestCase extends Base implements reporterTypes.TestCase { expectedStatus: reporterTypes.TestStatus = 'passed'; timeout = 0; - annotations: Annotation[] = []; + annotations: TestAnnotation[] = []; retries = 0; repeatEachIndex = 0; diff --git a/packages/playwright/src/isomorphic/teleReceiver.ts b/packages/playwright/src/isomorphic/teleReceiver.ts index 069ddb4a435e1..fa347cc72006c 100644 --- a/packages/playwright/src/isomorphic/teleReceiver.ts +++ b/packages/playwright/src/isomorphic/teleReceiver.ts @@ -14,9 +14,8 @@ * limitations under the License. */ -import type { Metadata } from '../../types/test'; +import type { Metadata, TestAnnotation } from '../../types/test'; import type * as reporterTypes from '../../types/testReporter'; -import type { Annotation } from '../common/config'; import type { ReporterV2 } from '../reporters/reporterV2'; export type StringIntern = (s: string) => string; @@ -68,7 +67,7 @@ export type JsonTestCase = { retries: number; tags?: string[]; repeatEachIndex: number; - annotations?: Annotation[]; + annotations?: TestAnnotation[]; }; export type JsonTestEnd = { @@ -96,7 +95,7 @@ export type JsonTestResultEnd = { errors: reporterTypes.TestError[]; /** No longer emitted, but kept for backwards compatibility */ attachments?: JsonAttachment[]; - annotations?: Annotation[]; + annotations?: TestAnnotation[]; }; export type JsonTestStepStart = { @@ -113,7 +112,7 @@ export type JsonTestStepEnd = { duration: number; error?: reporterTypes.TestError; attachments?: number[]; // index of JsonTestResultEnd.attachments - annotations?: Annotation[]; + annotations?: TestAnnotation[]; }; export type JsonTestResultOnAttach = { @@ -503,7 +502,7 @@ export class TeleTestCase implements reporterTypes.TestCase { expectedStatus: reporterTypes.TestStatus = 'passed'; timeout = 0; - annotations: Annotation[] = []; + annotations: TestAnnotation[] = []; retries = 0; tags: string[] = []; repeatEachIndex = 0; diff --git a/packages/playwright/src/reporters/html.ts b/packages/playwright/src/reporters/html.ts index 8e057d81931ff..c20ad0b48902a 100644 --- a/packages/playwright/src/reporters/html.ts +++ b/packages/playwright/src/reporters/html.ts @@ -29,9 +29,9 @@ import { codeFrameColumns } from '../transform/babelBundle'; import { resolveReporterOutputPath, stripAnsiEscapes } from '../util'; import type { ReporterV2 } from './reporterV2'; -import type { Metadata } from '../../types/test'; +import type { Metadata, TestAnnotation } from '../../types/test'; import type * as api from '../../types/testReporter'; -import type { HTMLReport, Stats, TestAttachment, TestCase, TestCaseSummary, TestFile, TestFileSummary, TestResult, TestStep, TestAnnotation } from '@html-reporter/types'; +import type { HTMLReport, Stats, TestAttachment, TestCase, TestCaseSummary, TestFile, TestFileSummary, TestResult, TestStep } from '@html-reporter/types'; import type { ZipFile } from 'playwright-core/lib/zipBundle'; import type { TransformCallback } from 'stream'; diff --git a/packages/playwright/src/worker/testInfo.ts b/packages/playwright/src/worker/testInfo.ts index b8e462339b396..c1d1bcb116453 100644 --- a/packages/playwright/src/worker/testInfo.ts +++ b/packages/playwright/src/worker/testInfo.ts @@ -25,9 +25,9 @@ import { TestTracing } from './testTracing'; import { testInfoError } from './util'; import type { RunnableDescription } from './timeoutManager'; -import type { FullProject, TestInfo, TestStatus, TestStepInfo } from '../../types/test'; +import type { FullProject, TestInfo, TestStatus, TestStepInfo, TestAnnotation } from '../../types/test'; import type { FullConfig, Location } from '../../types/testReporter'; -import type { Annotation, FullConfigInternal, FullProjectInternal } from '../common/config'; +import type { FullConfigInternal, FullProjectInternal } from '../common/config'; import type { AttachmentPayload, StepBeginPayload, StepEndPayload, TestInfoErrorImpl, WorkerInitParams } from '../common/ipc'; import type { TestCase } from '../common/test'; import type { StackFrame } from '@protocol/channels'; @@ -90,7 +90,7 @@ export class TestInfoImpl implements TestInfo { readonly fn: Function; expectedStatus: TestStatus; duration: number = 0; - readonly annotations: Annotation[] = []; + readonly annotations: TestAnnotation[] = []; readonly attachments: TestInfo['attachments'] = []; status: TestStatus = 'passed'; snapshotSuffix: string = ''; @@ -501,7 +501,7 @@ export class TestInfoImpl implements TestInfo { } export class TestStepInfoImpl implements TestStepInfo { - annotations: Annotation[] = []; + annotations: TestAnnotation[] = []; private _testInfo: TestInfoImpl; private _stepId: string; diff --git a/packages/playwright/src/worker/workerMain.ts b/packages/playwright/src/worker/workerMain.ts index 427cd68879057..59dbae0f4fdc8 100644 --- a/packages/playwright/src/worker/workerMain.ts +++ b/packages/playwright/src/worker/workerMain.ts @@ -32,9 +32,10 @@ import { loadTestFile } from '../common/testLoader'; import type { TimeSlot } from './timeoutManager'; import type { Location } from '../../types/testReporter'; -import type { Annotation, FullConfigInternal, FullProjectInternal } from '../common/config'; +import type { FullConfigInternal, FullProjectInternal } from '../common/config'; import type { DonePayload, RunPayload, TeardownErrorsPayload, TestBeginPayload, TestEndPayload, TestInfoErrorImpl, WorkerInitParams } from '../common/ipc'; import type { Suite, TestCase } from '../common/test'; +import type { TestAnnotation } from '../../types/test'; export class WorkerMain extends ProcessRunner { private _params: WorkerInitParams; @@ -60,7 +61,7 @@ export class WorkerMain extends ProcessRunner { // Suites that had their beforeAll hooks, but not afterAll hooks executed. // These suites still need afterAll hooks to be executed for the proper cleanup. // Contains dynamic annotations originated by modifiers with a callback, e.g. `test.skip(() => true)`. - private _activeSuites = new Map(); + private _activeSuites = new Map(); constructor(params: WorkerInitParams) { super(); @@ -264,7 +265,7 @@ export class WorkerMain extends ProcessRunner { stepEndPayload => this.dispatchEvent('stepEnd', stepEndPayload), attachment => this.dispatchEvent('attach', attachment)); - const processAnnotation = (annotation: Annotation) => { + const processAnnotation = (annotation: TestAnnotation) => { testInfo.annotations.push(annotation); switch (annotation.type) { case 'fixme': @@ -511,12 +512,12 @@ export class WorkerMain extends ProcessRunner { private async _runBeforeAllHooksForSuite(suite: Suite, testInfo: TestInfoImpl) { if (this._activeSuites.has(suite)) return; - const extraAnnotations: Annotation[] = []; + const extraAnnotations: TestAnnotation[] = []; this._activeSuites.set(suite, extraAnnotations); await this._runAllHooksForSuite(suite, testInfo, 'beforeAll', extraAnnotations); } - private async _runAllHooksForSuite(suite: Suite, testInfo: TestInfoImpl, type: 'beforeAll' | 'afterAll', extraAnnotations?: Annotation[]) { + private async _runAllHooksForSuite(suite: Suite, testInfo: TestInfoImpl, type: 'beforeAll' | 'afterAll', extraAnnotations?: TestAnnotation[]) { // Always run all the hooks, and capture the first error. let firstError: Error | undefined; for (const hook of this._collectHooksAndModifiers(suite, type, testInfo)) { diff --git a/packages/playwright/types/test.d.ts b/packages/playwright/types/test.d.ts index 71a2a162fd015..7e4ec8f2c8fc9 100644 --- a/packages/playwright/types/test.d.ts +++ b/packages/playwright/types/test.d.ts @@ -2049,6 +2049,8 @@ export type TestDetailsAnnotation = { description?: string; }; +export type TestAnnotation = TestDetailsAnnotation; + export type TestDetails = { tag?: string | string[]; annotation?: TestDetailsAnnotation | TestDetailsAnnotation[]; diff --git a/packages/trace-viewer/src/ui/annotationsTab.tsx b/packages/trace-viewer/src/ui/annotationsTab.tsx index 5a2a34c9f1e92..2a107c048c4b1 100644 --- a/packages/trace-viewer/src/ui/annotationsTab.tsx +++ b/packages/trace-viewer/src/ui/annotationsTab.tsx @@ -18,11 +18,10 @@ import * as React from 'react'; import './annotationsTab.css'; import { PlaceholderPanel } from './placeholderPanel'; import { linkifyText } from '@web/renderUtils'; - -type Annotation = { type: string; description?: string; }; +import type { TestAnnotation } from '@playwright/test'; export const AnnotationsTab: React.FunctionComponent<{ - annotations: Annotation[], + annotations: TestAnnotation[], }> = ({ annotations }) => { if (!annotations.length) diff --git a/packages/trace-viewer/src/ui/workbench.tsx b/packages/trace-viewer/src/ui/workbench.tsx index f9efcd7a98ab3..994945443475f 100644 --- a/packages/trace-viewer/src/ui/workbench.tsx +++ b/packages/trace-viewer/src/ui/workbench.tsx @@ -42,6 +42,7 @@ import { testStatusIcon, testStatusText } from './testUtils'; import type { UITestStatus } from './testUtils'; import type { AfterActionTraceEventAttachment } from '@trace/trace'; import type { HighlightedElement } from './snapshotTab'; +import type { TestAnnotation } from '@playwright/test'; export const Workbench: React.FunctionComponent<{ model?: modelUtil.MultiTraceModel, @@ -51,7 +52,7 @@ export const Workbench: React.FunctionComponent<{ isLive?: boolean, hideTimeline?: boolean, status?: UITestStatus, - annotations?: { type: string; description?: string; }[]; + annotations?: TestAnnotation[]; inert?: boolean, onOpenExternally?: (location: modelUtil.SourceLocation) => void, revealSource?: boolean, diff --git a/utils/generate_types/overrides-test.d.ts b/utils/generate_types/overrides-test.d.ts index 567b33e88fbb1..30a16a04d9220 100644 --- a/utils/generate_types/overrides-test.d.ts +++ b/utils/generate_types/overrides-test.d.ts @@ -70,6 +70,8 @@ export type TestDetailsAnnotation = { description?: string; }; +export type TestAnnotation = TestDetailsAnnotation; + export type TestDetails = { tag?: string | string[]; annotation?: TestDetailsAnnotation | TestDetailsAnnotation[];