Skip to content

Commit 307a1a9

Browse files
Sid200026mxschmitt
andauthored
chore(playwrighttesting): use playwright OSS types (Azure#32319)
### Packages impacted by this PR @azure/microsoft-playwright-testing ### Issues associated with this PR Type changes by playwright OSS will impact @azure/microsoft-playwright-testing SDK if relevant types are hardcoded. Also fixes Azure#32394 ### Describe the problem that is addressed by this PR Instead of having playwright OSS types hardcoded in the package, we will use the types provided by the playwright OSS package itself (Playwright OSS is added as a peer dependency). This also changes peer dependency version of playwright OSS to v1.47, which is the minimum supported version of playwright OSS for this SDK. ### What are the possible designs available to address the problem? If there are more than one possible design, why was the one in this PR chosen? ### Are there test cases added in this PR? _(If not, why?)_ ### Provide a list of related PRs _(if any)_ ### Command used to generate this PR:**_(Applicable only to SDK release request PRs)_ ### Checklists - [ ] Added impacted package name to the issue description - [ ] Does this PR needs any fixes in the SDK Generator?** _(If so, create an Issue in the [Autorest/typescript](https://github.com/Azure/autorest.typescript) repository and link it here)_ - [ ] Added a changelog (if necessary) --------- Co-authored-by: Max Schmitt <[email protected]>
1 parent 4fe0ab5 commit 307a1a9

File tree

15 files changed

+71
-128
lines changed

15 files changed

+71
-128
lines changed

sdk/playwrighttesting/microsoft-playwright-testing/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
"typescript": "~5.7.2"
9090
},
9191
"peerDependencies": {
92-
"@playwright/test": "^1.43.1"
92+
"@playwright/test": "^1.47.0"
9393
},
9494
"prettier": "@azure/eslint-plugin-azure-sdk/prettier.json",
9595
"//sampleConfiguration": {

sdk/playwrighttesting/microsoft-playwright-testing/review/microsoft-playwright-testing-reporter.api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type { TestResult } from '@playwright/test/reporter';
1313

1414
// @public
1515
class MPTReporter implements Reporter {
16-
constructor(config: Partial<MPTReporterConfig>);
16+
constructor(config: Partial<ReporterConfiguration>);
1717
onBegin(config: FullConfig, suite: Suite): void;
1818
onEnd(result: FullResult): Promise<void>;
1919
onTestEnd(test: TestCase, result: TestResult): void;

sdk/playwrighttesting/microsoft-playwright-testing/review/microsoft-playwright-testing.api.md

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
```ts
66

7+
import type { ConnectOptions } from '@playwright/test';
78
import type { PlaywrightTestConfig } from '@playwright/test';
89
import type { TokenCredential } from '@azure/identity';
910

@@ -15,16 +16,6 @@ export type BrowserConnectOptions = EndpointOptions & {
1516
options: ConnectOptions;
1617
};
1718

18-
// @public
19-
export type ConnectOptions = {
20-
headers?: {
21-
[key: string]: string;
22-
};
23-
exposeNetwork?: string;
24-
timeout?: number;
25-
slowMo?: number;
26-
};
27-
2819
// @public
2920
export type EndpointOptions = {
3021
wsEndpoint: string;
@@ -36,12 +27,6 @@ export const getConnectOptions: (options?: Omit<PlaywrightServiceAdditionalOptio
3627
// @public
3728
export const getServiceConfig: (config: PlaywrightTestConfig, options?: PlaywrightServiceAdditionalOptions) => PlaywrightTestConfig;
3829

39-
// @public
40-
export interface MPTReporterConfig {
41-
enableGitHubSummary?: boolean;
42-
enableResultPublish?: boolean;
43-
}
44-
4530
// @public
4631
export type OsType = (typeof ServiceOS)[keyof typeof ServiceOS];
4732

@@ -58,6 +43,12 @@ export type PlaywrightServiceAdditionalOptions = {
5843
runName?: string;
5944
};
6045

46+
// @public
47+
export type ReporterConfiguration = {
48+
enableGitHubSummary?: boolean;
49+
enableResultPublish?: boolean;
50+
};
51+
6152
// @public
6253
export const ServiceAuth: {
6354
readonly ENTRA_ID: "ENTRA_ID";
@@ -66,11 +57,8 @@ export const ServiceAuth: {
6657

6758
// @public
6859
export const ServiceEnvironmentVariable: {
69-
PLAYWRIGHT_SERVICE_OS: string;
70-
PLAYWRIGHT_SERVICE_EXPOSE_NETWORK_ENVIRONMENT_VARIABLE: string;
7160
PLAYWRIGHT_SERVICE_ACCESS_TOKEN: string;
7261
PLAYWRIGHT_SERVICE_URL: string;
73-
PLAYWRIGHT_SERVICE_REPORTING_URL: string;
7462
};
7563

7664
// @public

sdk/playwrighttesting/microsoft-playwright-testing/samples/v1/typescript/customising-service-parameters/playwright.service.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
ServiceAuth,
66
AuthenticationType,
77
OsType,
8-
MPTReporterConfig,
8+
ReporterConfiguration,
99
} from "@azure/microsoft-playwright-testing";
1010
import { defineConfig } from "@playwright/test";
1111
import config from "./playwright.config";
@@ -28,7 +28,7 @@ const playwrightServiceAdditionalOptions: PlaywrightServiceAdditionalOptions = {
2828
runName: "Typescript V1 - Sample Run", // Run name for the test run
2929
};
3030

31-
const reporterConfiguration: MPTReporterConfig = {
31+
const reporterConfiguration: ReporterConfiguration = {
3232
enableGitHubSummary: true, // Enable GitHub Actions annotations to diagnose test failures and deep link to MPT Portal
3333
enableResultPublish: true, // Enable result publishing for the test run. This will upload the test result and artifacts to the MPT Portal
3434
};

sdk/playwrighttesting/microsoft-playwright-testing/src/common/constants.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,8 @@ export const ServiceAuth = {
3131
* Environment variables used by Microsoft Playwright Testing
3232
*/
3333
export const ServiceEnvironmentVariable = {
34-
PLAYWRIGHT_SERVICE_OS: "PLAYWRIGHT_SERVICE_OS",
35-
PLAYWRIGHT_SERVICE_EXPOSE_NETWORK_ENVIRONMENT_VARIABLE: "PLAYWRIGHT_SERVICE_EXPOSE_NETWORK",
3634
PLAYWRIGHT_SERVICE_ACCESS_TOKEN: "PLAYWRIGHT_SERVICE_ACCESS_TOKEN",
3735
PLAYWRIGHT_SERVICE_URL: "PLAYWRIGHT_SERVICE_URL",
38-
PLAYWRIGHT_SERVICE_REPORTING_URL: "PLAYWRIGHT_SERVICE_REPORTING_URL",
3936
};
4037

4138
export const DefaultConnectOptionsConstants = {
@@ -247,6 +244,8 @@ export const InternalEnvironmentVariables = {
247244
MPT_SERVICE_RUN_NAME: "_MPT_SERVICE_RUN_NAME",
248245
MPT_SERVICE_RUN_ID: "_MPT_SERVICE_RUN_ID",
249246
MPT_CLOUD_HOSTED_BROWSER_USED: "_MPT_CLOUD_HOSTED_BROWSER_USED",
247+
MPT_SERVICE_OS: "_MPT_SERVICE_OS",
248+
MPT_SERVICE_REPORTING_URL: "_MPT_SERVICE_REPORTING_URL",
250249
ONE_TIME_OPERATION_FLAG: "_ONE_TIME_OPERATION_FLAG",
251250
};
252251

sdk/playwrighttesting/microsoft-playwright-testing/src/common/playwrightServiceConfig.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
import {
5-
DefaultConnectOptionsConstants,
6-
InternalEnvironmentVariables,
7-
ServiceEnvironmentVariable,
8-
} from "./constants";
4+
import { DefaultConnectOptionsConstants, InternalEnvironmentVariables } from "./constants";
95
import type { PlaywrightServiceAdditionalOptions, OsType } from "./types";
106
import { getAndSetRunId } from "../utils/utils";
117

@@ -17,7 +13,7 @@ class PlaywrightServiceConfig {
1713
public exposeNetwork: string;
1814
public runName: string;
1915
constructor() {
20-
this.serviceOs = (process.env[ServiceEnvironmentVariable.PLAYWRIGHT_SERVICE_OS] ||
16+
this.serviceOs = (process.env[InternalEnvironmentVariables.MPT_SERVICE_OS] ||
2117
DefaultConnectOptionsConstants.DEFAULT_SERVICE_OS) as OsType;
2218
this.runName = process.env[InternalEnvironmentVariables.MPT_SERVICE_RUN_NAME] || "";
2319
this.runId = process.env[InternalEnvironmentVariables.MPT_SERVICE_RUN_ID] || "";
@@ -44,7 +40,7 @@ class PlaywrightServiceConfig {
4440
}
4541
if (options?.os) {
4642
this.serviceOs = options.os;
47-
process.env[ServiceEnvironmentVariable.PLAYWRIGHT_SERVICE_OS] = this.serviceOs;
43+
process.env[InternalEnvironmentVariables.MPT_SERVICE_OS] = this.serviceOs;
4844
}
4945
if (options?.slowMo) {
5046
this.slowMo = options.slowMo;

sdk/playwrighttesting/microsoft-playwright-testing/src/common/types.ts

Lines changed: 34 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,11 @@
22
// Licensed under the MIT License.
33

44
import type { Location, TestStep } from "@playwright/test/reporter";
5+
import type { ConnectOptions } from "@playwright/test";
56
import type { ServiceAuth, ServiceOS } from "./constants";
67
import type { TokenCredential } from "@azure/identity";
78

8-
export type JwtPayload = {
9-
aid?: string;
10-
iss?: string;
11-
sub?: string;
12-
aud?: string[] | string;
13-
exp?: number;
14-
nbf?: number;
15-
iat?: number;
16-
jti?: string;
17-
};
18-
19-
export type AccessTokenClaims = JwtPayload & {
20-
aid?: string;
21-
accountId?: string;
22-
};
9+
// Public APIs
2310

2411
/**
2512
* @public
@@ -35,47 +22,6 @@ export type EndpointOptions = {
3522
wsEndpoint: string;
3623
};
3724

38-
/**
39-
* @public
40-
*
41-
* Connect options for the service.
42-
*/
43-
export type ConnectOptions = {
44-
/**
45-
* @public
46-
*
47-
* Additional HTTP headers to be sent with web socket connect request.
48-
*/
49-
headers?: { [key: string]: string };
50-
51-
/**
52-
* @public
53-
*
54-
* Exposes network available on the connecting client to the browser being connected to.
55-
*
56-
* @defaultValue `<loopback>`
57-
*/
58-
exposeNetwork?: string;
59-
60-
/**
61-
* @public
62-
*
63-
* Maximum time in milliseconds to wait for the connection to be established.
64-
*
65-
* @defaultValue `30000`
66-
*/
67-
timeout?: number;
68-
69-
/**
70-
* @public
71-
*
72-
* Slows down Playwright operations by the specified amount of milliseconds.
73-
*
74-
* @defaultValue `0`
75-
*/
76-
slowMo?: number;
77-
};
78-
7925
/**
8026
* @public
8127
*
@@ -206,15 +152,6 @@ export type OsType = (typeof ServiceOS)[keyof typeof ServiceOS];
206152
*/
207153
export type AuthenticationType = (typeof ServiceAuth)[keyof typeof ServiceAuth];
208154

209-
export type ErrorDetails = {
210-
message: string;
211-
location?: Location;
212-
};
213-
export type ApiErrorMessage = {
214-
[key: string]: {
215-
[key: number]: string;
216-
};
217-
};
218155
/**
219156
* @public
220157
*
@@ -232,7 +169,7 @@ export type ApiErrorMessage = {
232169
* });
233170
* ```
234171
*/
235-
export interface MPTReporterConfig {
172+
export type ReporterConfiguration = {
236173
/**
237174
* @public
238175
*
@@ -250,7 +187,37 @@ export interface MPTReporterConfig {
250187
* @defaultValue `true`
251188
*/
252189
enableResultPublish?: boolean;
253-
}
190+
};
191+
192+
// Internal APIs
193+
194+
export type JwtPayload = {
195+
aid?: string;
196+
iss?: string;
197+
sub?: string;
198+
aud?: string[] | string;
199+
exp?: number;
200+
nbf?: number;
201+
iat?: number;
202+
jti?: string;
203+
};
204+
205+
export type AccessTokenClaims = JwtPayload & {
206+
aid?: string;
207+
accountId?: string;
208+
};
209+
210+
export type ErrorDetails = {
211+
message: string;
212+
location?: Location;
213+
};
214+
215+
export type ApiErrorMessage = {
216+
[key: string]: {
217+
[key: number]: string;
218+
};
219+
};
220+
254221
export type DedupedStep = { step: TestStep; count: number; duration: number };
255222

256223
export type RawTestStep = {
@@ -283,9 +250,3 @@ export type PackageManager = {
283250
runCommand: (command: string, args: string) => string;
284251
getVersionFromStdout: (stdout: string) => string;
285252
};
286-
287-
// Playwright OSS Types
288-
289-
export interface FullConfig {
290-
configFile?: string;
291-
}

sdk/playwrighttesting/microsoft-playwright-testing/src/core/global/playwright-service-global-setup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Licensed under the MIT License.
33

44
import { dirname } from "path";
5-
import type { FullConfig } from "../../common/types";
5+
import type { FullConfig } from "@playwright/test";
66
import playwrightServiceEntra from "../playwrightServiceEntra";
77
import { loadCustomerGlobalFunction } from "../../common/executor";
88
import customerConfig from "../../common/customerConfig";

sdk/playwrighttesting/microsoft-playwright-testing/src/core/global/playwright-service-global-teardown.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Licensed under the MIT License.
33

44
import { dirname } from "path";
5-
import type { FullConfig } from "../../common/types";
5+
import type { FullConfig } from "@playwright/test";
66
import playwrightServiceEntra from "../playwrightServiceEntra";
77
import { loadCustomerGlobalFunction } from "../../common/executor";
88
import customerConfig from "../../common/customerConfig";

sdk/playwrighttesting/microsoft-playwright-testing/src/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ import type {
1212
OsType,
1313
AuthenticationType,
1414
BrowserConnectOptions,
15-
MPTReporterConfig,
15+
ReporterConfiguration,
1616
EndpointOptions,
17-
ConnectOptions,
1817
PlaywrightServiceAdditionalOptions,
1918
} from "./common/types";
2019
import { getServiceConfig, getConnectOptions } from "./core/playwrightService";
@@ -29,7 +28,6 @@ export {
2928
AuthenticationType,
3029
BrowserConnectOptions,
3130
EndpointOptions,
32-
ConnectOptions,
33-
MPTReporterConfig,
31+
ReporterConfiguration,
3432
PlaywrightServiceAdditionalOptions,
3533
};

0 commit comments

Comments
 (0)