Skip to content

Commit 6da84b3

Browse files
authored
cherry-pick(#35373): Revert "chore: add location named property to annotations" (#35620) (#35622)
1 parent 2914d1b commit 6da84b3

26 files changed

Lines changed: 125 additions & 229 deletions

File tree

docs/src/test-api/class-testinfo.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ test('basic test', async ({ page }, testInfo) => {
1919
- type: <[Array]<[Object]>>
2020
- `type` <[string]> Annotation type, for example `'skip'` or `'fail'`.
2121
- `description` ?<[string]> Optional description.
22-
- `location` ?<[Location]> Optional location in the source where the annotation is added.
2322

2423
The list of annotations applicable to the current test. Includes annotations from the test, annotations from all [`method: Test.describe`] groups the test belongs to and file-level annotations for the test file.
2524

docs/src/test-reporter-api/class-testcase.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
- type: <[Array]<[Object]>>
1010
- `type` <[string]> Annotation type, for example `'skip'` or `'fail'`.
1111
- `description` ?<[string]> Optional description.
12-
- `location` ?<[Location]> Optional location in the source where the annotation is added.
1312

1413
[`property: TestResult.annotations`] of the last test run.
1514

docs/src/test-reporter-api/class-testresult.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ The list of files or buffers attached during the test execution through [`proper
1919
- type: <[Array]<[Object]>>
2020
- `type` <[string]> Annotation type, for example `'skip'` or `'fail'`.
2121
- `description` ?<[string]> Optional description.
22-
- `location` ?<[Location]> Optional location in the source where the annotation is added.
2322

2423
The list of annotations applicable to the current test. Includes:
2524
* annotations defined on the test or suite via [`method: Test.(call)`] and [`method: Test.describe`];

docs/src/test-reporter-api/class-teststep.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ List of steps inside this step.
5555
- type: <[Array]<[Object]>>
5656
- `type` <[string]> Annotation type, for example `'skip'`.
5757
- `description` ?<[string]> Optional description.
58-
- `location` ?<[Location]> Optional location in the source where the annotation is added.
5958

6059
The list of annotations applicable to the current test step.
6160

packages/html-reporter/src/testCaseView.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
limitations under the License.
1515
*/
1616

17-
import type { TestAnnotation } from '@playwright/test';
18-
import type { TestCase, TestCaseSummary } from './types';
17+
import type { TestCase, TestAnnotation, TestCaseSummary } from './types';
1918
import * as React from 'react';
2019
import { TabbedPane } from './tabbedPane';
2120
import { AutoChip } from './chip';

packages/html-reporter/src/types.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import type { TestAnnotation, Metadata } from '@playwright/test';
17+
import type { Metadata } from '@playwright/test';
1818

1919
export type Stats = {
2020
total: number;
@@ -59,6 +59,8 @@ export type TestFileSummary = {
5959
stats: Stats;
6060
};
6161

62+
export type TestAnnotation = { type: string, description?: string };
63+
6264
export type TestCaseSummary = {
6365
testId: string,
6466
title: string;

packages/playwright/src/common/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export type FixturesWithLocation = {
3636
fixtures: Fixtures;
3737
location: Location;
3838
};
39+
export type Annotation = { type: string, description?: string };
3940

4041
export const defaultTimeout = 30000;
4142

packages/playwright/src/common/test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
import { rootTestType } from './testType';
1818
import { computeTestCaseOutcome } from '../isomorphic/teleReceiver';
1919

20-
import type { FixturesWithLocation, FullProjectInternal } from './config';
20+
import type { Annotation, FixturesWithLocation, FullProjectInternal } from './config';
2121
import type { FixturePool } from './fixtures';
2222
import type { TestTypeImpl } from './testType';
23-
import type { TestAnnotation } from '../../types/test';
2423
import type * as reporterTypes from '../../types/testReporter';
2524
import type { FullProject, Location } from '../../types/testReporter';
2625

@@ -51,7 +50,7 @@ export class Suite extends Base {
5150
_timeout: number | undefined;
5251
_retries: number | undefined;
5352
// Annotations known statically before running the test, e.g. `test.describe.skip()` or `test.describe({ annotation }, body)`.
54-
_staticAnnotations: TestAnnotation[] = [];
53+
_staticAnnotations: Annotation[] = [];
5554
// Explicitly declared tags that are not a part of the title.
5655
_tags: string[] = [];
5756
_modifiers: Modifier[] = [];
@@ -253,7 +252,7 @@ export class TestCase extends Base implements reporterTypes.TestCase {
253252

254253
expectedStatus: reporterTypes.TestStatus = 'passed';
255254
timeout = 0;
256-
annotations: TestAnnotation[] = [];
255+
annotations: Annotation[] = [];
257256
retries = 0;
258257
repeatEachIndex = 0;
259258

packages/playwright/src/common/testType.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export class TestTypeImpl {
104104
details = fnOrDetails;
105105
}
106106

107-
const validatedDetails = validateTestDetails(details, location);
107+
const validatedDetails = validateTestDetails(details);
108108
const test = new TestCase(title, body, this, location);
109109
test._requireFile = suite._requireFile;
110110
test.annotations.push(...validatedDetails.annotations);
@@ -114,9 +114,9 @@ export class TestTypeImpl {
114114
if (type === 'only' || type === 'fail.only')
115115
test._only = true;
116116
if (type === 'skip' || type === 'fixme' || type === 'fail')
117-
test.annotations.push({ type, location });
117+
test.annotations.push({ type });
118118
else if (type === 'fail.only')
119-
test.annotations.push({ type: 'fail', location });
119+
test.annotations.push({ type: 'fail' });
120120
}
121121

122122
private _describe(type: 'default' | 'only' | 'serial' | 'serial.only' | 'parallel' | 'parallel.only' | 'skip' | 'fixme', location: Location, titleOrFn: string | Function, fnOrDetails?: TestDetails | Function, fn?: Function) {
@@ -143,7 +143,7 @@ export class TestTypeImpl {
143143
body = fn!;
144144
}
145145

146-
const validatedDetails = validateTestDetails(details, location);
146+
const validatedDetails = validateTestDetails(details);
147147
const child = new Suite(title, 'describe');
148148
child._requireFile = suite._requireFile;
149149
child.location = location;
@@ -158,7 +158,7 @@ export class TestTypeImpl {
158158
if (type === 'parallel' || type === 'parallel.only')
159159
child._parallelMode = 'parallel';
160160
if (type === 'skip' || type === 'fixme')
161-
child._staticAnnotations.push({ type, location });
161+
child._staticAnnotations.push({ type });
162162

163163
for (let parent: Suite | undefined = suite; parent; parent = parent.parent) {
164164
if (parent._parallelMode === 'serial' && child._parallelMode === 'parallel')
@@ -229,7 +229,7 @@ export class TestTypeImpl {
229229
if (modifierArgs.length >= 1 && !modifierArgs[0])
230230
return;
231231
const description = modifierArgs[1];
232-
suite._staticAnnotations.push({ type, description, location });
232+
suite._staticAnnotations.push({ type, description });
233233
}
234234
return;
235235
}
@@ -239,7 +239,7 @@ export class TestTypeImpl {
239239
throw new Error(`test.${type}() can only be called inside test, describe block or fixture`);
240240
if (typeof modifierArgs[0] === 'function')
241241
throw new Error(`test.${type}() with a function can only be called inside describe block`);
242-
testInfo._modifier(type, location, modifierArgs as [any, any]);
242+
testInfo[type](...modifierArgs as [any, any]);
243243
}
244244

245245
private _setTimeout(location: Location, timeout: number) {
@@ -276,7 +276,7 @@ export class TestTypeImpl {
276276
let result: Awaited<ReturnType<typeof raceAgainstDeadline<T>>> | undefined = undefined;
277277
result = await raceAgainstDeadline(async () => {
278278
try {
279-
return await step.info._runStepBody(expectation === 'skip', body, step.location);
279+
return await step.info._runStepBody(expectation === 'skip', body);
280280
} catch (e) {
281281
// If the step timed out, the test fixtures will tear down, which in turn
282282
// will abort unfinished actions in the step body. Record such errors here.
@@ -315,9 +315,8 @@ function throwIfRunningInsideJest() {
315315
}
316316
}
317317

318-
function validateTestDetails(details: TestDetails, location: Location) {
319-
const originalAnnotations = Array.isArray(details.annotation) ? details.annotation : (details.annotation ? [details.annotation] : []);
320-
const annotations = originalAnnotations.map(annotation => ({ ...annotation, location }));
318+
function validateTestDetails(details: TestDetails) {
319+
const annotations = Array.isArray(details.annotation) ? details.annotation : (details.annotation ? [details.annotation] : []);
321320
const tags = Array.isArray(details.tag) ? details.tag : (details.tag ? [details.tag] : []);
322321
for (const tag of tags) {
323322
if (tag[0] !== '@')

packages/playwright/src/isomorphic/teleReceiver.ts

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
* limitations under the License.
1515
*/
1616

17-
import type { Metadata, TestAnnotation } from '../../types/test';
17+
import type { Metadata } from '../../types/test';
1818
import type * as reporterTypes from '../../types/testReporter';
19+
import type { Annotation } from '../common/config';
1920
import type { ReporterV2 } from '../reporters/reporterV2';
2021

2122
export type StringIntern = (s: string) => string;
@@ -67,7 +68,7 @@ export type JsonTestCase = {
6768
retries: number;
6869
tags?: string[];
6970
repeatEachIndex: number;
70-
annotations?: TestAnnotation[];
71+
annotations?: Annotation[];
7172
};
7273

7374
export type JsonTestEnd = {
@@ -94,7 +95,7 @@ export type JsonTestResultEnd = {
9495
status: reporterTypes.TestStatus;
9596
errors: reporterTypes.TestError[];
9697
attachments: JsonAttachment[];
97-
annotations?: TestAnnotation[];
98+
annotations?: Annotation[];
9899
};
99100

100101
export type JsonTestStepStart = {
@@ -111,7 +112,7 @@ export type JsonTestStepEnd = {
111112
duration: number;
112113
error?: reporterTypes.TestError;
113114
attachments?: number[]; // index of JsonTestResultEnd.attachments
114-
annotations?: TestAnnotation[];
115+
annotations?: Annotation[];
115116
};
116117

117118
export type JsonFullResult = {
@@ -242,7 +243,7 @@ export class TeleReporterReceiver {
242243
result.error = result.errors?.[0];
243244
result.attachments = this._parseAttachments(payload.attachments);
244245
if (payload.annotations) {
245-
result.annotations = this._absoluteAnnotationLocations(payload.annotations);
246+
result.annotations = payload.annotations;
246247
test.annotations = result.annotations;
247248
}
248249
this._reporter.onTestEnd?.(test, result);
@@ -374,18 +375,10 @@ export class TeleReporterReceiver {
374375
test.location = this._absoluteLocation(payload.location);
375376
test.retries = payload.retries;
376377
test.tags = payload.tags ?? [];
377-
test.annotations = this._absoluteAnnotationLocations(payload.annotations ?? []);
378+
test.annotations = payload.annotations ?? [];
378379
return test;
379380
}
380381

381-
private _absoluteAnnotationLocations(annotations: TestAnnotation[]): TestAnnotation[] {
382-
return annotations.map(annotation => {
383-
if (annotation.location)
384-
annotation.location = this._absoluteLocation(annotation.location);
385-
return annotation;
386-
});
387-
}
388-
389382
private _absoluteLocation(location: reporterTypes.Location): reporterTypes.Location;
390383
private _absoluteLocation(location?: reporterTypes.Location): reporterTypes.Location | undefined;
391384
private _absoluteLocation(location: reporterTypes.Location | undefined): reporterTypes.Location | undefined {
@@ -486,7 +479,7 @@ export class TeleTestCase implements reporterTypes.TestCase {
486479

487480
expectedStatus: reporterTypes.TestStatus = 'passed';
488481
timeout = 0;
489-
annotations: TestAnnotation[] = [];
482+
annotations: Annotation[] = [];
490483
retries = 0;
491484
tags: string[] = [];
492485
repeatEachIndex = 0;

0 commit comments

Comments
 (0)