@azure/microsoft-playwright-testing 1.0.0-alpha.20240911.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/LICENSE +21 -0
  3. package/README.md +151 -0
  4. package/dist/common/constants.d.ts +92 -0
  5. package/dist/common/constants.d.ts.map +1 -0
  6. package/dist/common/constants.js +222 -0
  7. package/dist/common/constants.js.map +1 -0
  8. package/dist/common/customerConfig.d.ts +9 -0
  9. package/dist/common/customerConfig.d.ts.map +1 -0
  10. package/dist/common/customerConfig.js +15 -0
  11. package/dist/common/customerConfig.js.map +1 -0
  12. package/dist/common/entraIdAccessToken.d.ts +12 -0
  13. package/dist/common/entraIdAccessToken.d.ts.map +1 -0
  14. package/dist/common/entraIdAccessToken.js +72 -0
  15. package/dist/common/entraIdAccessToken.js.map +1 -0
  16. package/dist/common/environmentVariables.d.ts +12 -0
  17. package/dist/common/environmentVariables.d.ts.map +1 -0
  18. package/dist/common/environmentVariables.js +17 -0
  19. package/dist/common/environmentVariables.js.map +1 -0
  20. package/dist/common/executor.d.ts +2 -0
  21. package/dist/common/executor.d.ts.map +1 -0
  22. package/dist/common/executor.js +79 -0
  23. package/dist/common/executor.js.map +1 -0
  24. package/dist/common/httpService.d.ts +5 -0
  25. package/dist/common/httpService.d.ts.map +1 -0
  26. package/dist/common/httpService.js +37 -0
  27. package/dist/common/httpService.js.map +1 -0
  28. package/dist/common/logger.d.ts +3 -0
  29. package/dist/common/logger.d.ts.map +1 -0
  30. package/dist/common/logger.js +9 -0
  31. package/dist/common/logger.js.map +1 -0
  32. package/dist/common/messages.d.ts +9 -0
  33. package/dist/common/messages.d.ts.map +1 -0
  34. package/dist/common/messages.js +14 -0
  35. package/dist/common/messages.js.map +1 -0
  36. package/dist/common/multimap.d.ts +16 -0
  37. package/dist/common/multimap.d.ts.map +1 -0
  38. package/dist/common/multimap.js +64 -0
  39. package/dist/common/multimap.js.map +1 -0
  40. package/dist/common/playwrightServiceConfig.d.ts +12 -0
  41. package/dist/common/playwrightServiceConfig.d.ts.map +1 -0
  42. package/dist/common/playwrightServiceConfig.js +39 -0
  43. package/dist/common/playwrightServiceConfig.js.map +1 -0
  44. package/dist/common/types.d.ts +301 -0
  45. package/dist/common/types.d.ts.map +1 -0
  46. package/dist/common/types.js +5 -0
  47. package/dist/common/types.js.map +1 -0
  48. package/dist/core/global/playwright-service-global-setup.d.ts +4 -0
  49. package/dist/core/global/playwright-service-global-setup.d.ts.map +1 -0
  50. package/dist/core/global/playwright-service-global-setup.js +19 -0
  51. package/dist/core/global/playwright-service-global-setup.js.map +1 -0
  52. package/dist/core/global/playwright-service-global-teardown.d.ts +4 -0
  53. package/dist/core/global/playwright-service-global-teardown.d.ts.map +1 -0
  54. package/dist/core/global/playwright-service-global-teardown.js +19 -0
  55. package/dist/core/global/playwright-service-global-teardown.js.map +1 -0
  56. package/dist/core/playwrightService.d.ts +63 -0
  57. package/dist/core/playwrightService.d.ts.map +1 -0
  58. package/dist/core/playwrightService.js +131 -0
  59. package/dist/core/playwrightService.js.map +1 -0
  60. package/dist/core/playwrightServiceEntra.d.ts +16 -0
  61. package/dist/core/playwrightServiceEntra.d.ts.map +1 -0
  62. package/dist/core/playwrightServiceEntra.js +51 -0
  63. package/dist/core/playwrightServiceEntra.js.map +1 -0
  64. package/dist/index.d.ts +10 -0
  65. package/dist/index.d.ts.map +1 -0
  66. package/dist/index.js +19 -0
  67. package/dist/index.js.map +1 -0
  68. package/dist/model/entraTokenDetails.d.ts +5 -0
  69. package/dist/model/entraTokenDetails.d.ts.map +1 -0
  70. package/dist/model/entraTokenDetails.js +9 -0
  71. package/dist/model/entraTokenDetails.js.map +1 -0
  72. package/dist/model/mptTokenDetails.d.ts +11 -0
  73. package/dist/model/mptTokenDetails.d.ts.map +1 -0
  74. package/dist/model/mptTokenDetails.js +14 -0
  75. package/dist/model/mptTokenDetails.js.map +1 -0
  76. package/dist/model/shard.d.ts +41 -0
  77. package/dist/model/shard.d.ts.map +1 -0
  78. package/dist/model/shard.js +24 -0
  79. package/dist/model/shard.js.map +1 -0
  80. package/dist/model/storageUri.d.ts +14 -0
  81. package/dist/model/storageUri.d.ts.map +1 -0
  82. package/dist/model/storageUri.js +22 -0
  83. package/dist/model/storageUri.js.map +1 -0
  84. package/dist/model/testResult.d.ts +40 -0
  85. package/dist/model/testResult.d.ts.map +1 -0
  86. package/dist/model/testResult.js +9 -0
  87. package/dist/model/testResult.js.map +1 -0
  88. package/dist/model/testRun.d.ts +36 -0
  89. package/dist/model/testRun.d.ts.map +1 -0
  90. package/dist/model/testRun.js +12 -0
  91. package/dist/model/testRun.js.map +1 -0
  92. package/dist/reporter/index.d.ts +10 -0
  93. package/dist/reporter/index.d.ts.map +1 -0
  94. package/dist/reporter/index.js +15 -0
  95. package/dist/reporter/index.js.map +1 -0
  96. package/dist/reporter/mptReporter.d.ts +96 -0
  97. package/dist/reporter/mptReporter.d.ts.map +1 -0
  98. package/dist/reporter/mptReporter.js +350 -0
  99. package/dist/reporter/mptReporter.js.map +1 -0
  100. package/dist/tsdoc-metadata.json +11 -0
  101. package/dist/utils/cIInfoProvider.d.ts +25 -0
  102. package/dist/utils/cIInfoProvider.d.ts.map +1 -0
  103. package/dist/utils/cIInfoProvider.js +107 -0
  104. package/dist/utils/cIInfoProvider.js.map +1 -0
  105. package/dist/utils/packageManager.d.ts +15 -0
  106. package/dist/utils/packageManager.d.ts.map +1 -0
  107. package/dist/utils/packageManager.js +54 -0
  108. package/dist/utils/packageManager.js.map +1 -0
  109. package/dist/utils/reporterUtils.d.ts +57 -0
  110. package/dist/utils/reporterUtils.d.ts.map +1 -0
  111. package/dist/utils/reporterUtils.js +547 -0
  112. package/dist/utils/reporterUtils.js.map +1 -0
  113. package/dist/utils/serviceClient.d.ts +23 -0
  114. package/dist/utils/serviceClient.d.ts.map +1 -0
  115. package/dist/utils/serviceClient.js +91 -0
  116. package/dist/utils/serviceClient.js.map +1 -0
  117. package/dist/utils/storageClient.d.ts +6 -0
  118. package/dist/utils/storageClient.d.ts.map +1 -0
  119. package/dist/utils/storageClient.js +41 -0
  120. package/dist/utils/storageClient.js.map +1 -0
  121. package/dist/utils/utils.d.ts +17 -0
  122. package/dist/utils/utils.d.ts.map +1 -0
  123. package/dist/utils/utils.js +143 -0
  124. package/dist/utils/utils.js.map +1 -0
  125. package/package.json +104 -0
  126. package/types/microsoft-playwright-testing.d.ts +352 -0
  127. package/types/reporter/microsoft-playwright-testing.d.ts +146 -0
@@ -0,0 +1,301 @@
1
+ import type { Location, TestStep } from "@playwright/test/reporter";
2
+ import { ServiceAuth, ServiceOS } from "./constants";
3
+ import type { TokenCredential } from "@azure/identity";
4
+ export type JwtPayload = {
5
+ iss?: string;
6
+ sub?: string;
7
+ aud?: string[] | string;
8
+ exp?: number;
9
+ nbf?: number;
10
+ iat?: number;
11
+ jti?: string;
12
+ };
13
+ export type AccessTokenClaims = JwtPayload & {
14
+ aid?: string;
15
+ accountId?: string;
16
+ };
17
+ /**
18
+ * @public
19
+ *
20
+ * Endpoint options for the service.
21
+ */
22
+ export type EndpointOptions = {
23
+ /**
24
+ * @public
25
+ *
26
+ * A browser websocket endpoint to connect to.
27
+ */
28
+ wsEndpoint: string;
29
+ };
30
+ /**
31
+ * @public
32
+ *
33
+ * Connect options for the service.
34
+ */
35
+ export type ConnectOptions = {
36
+ /**
37
+ * @public
38
+ *
39
+ * Additional HTTP headers to be sent with web socket connect request.
40
+ */
41
+ headers?: {
42
+ [key: string]: string;
43
+ };
44
+ /**
45
+ * @public
46
+ *
47
+ * Exposes network available on the connecting client to the browser being connected to.
48
+ *
49
+ * @defaultValue `<loopback>`
50
+ */
51
+ exposeNetwork?: string;
52
+ /**
53
+ * @public
54
+ *
55
+ * Maximum time in milliseconds to wait for the connection to be established.
56
+ *
57
+ * @defaultValue `30000`
58
+ */
59
+ timeout?: number;
60
+ /**
61
+ * @public
62
+ *
63
+ * Slows down Playwright operations by the specified amount of milliseconds.
64
+ *
65
+ * @defaultValue `0`
66
+ */
67
+ slowMo?: number;
68
+ };
69
+ /**
70
+ * @public
71
+ *
72
+ * Browser connect options for the service. This includes endpoint options and connect options.
73
+ *
74
+ * @example
75
+ * ```
76
+ * import playwright, { test, expect, BrowserType } from "@playwright/test";
77
+ * import { getConnectOptions, BrowserConnectOptions } from "@azure/microsoft-playwright-testing";
78
+ *
79
+ * test("has title", async ({ browserName }) => {
80
+ * const { wsEndpoint, options } : BrowserConnectOptions = await getConnectOptions();
81
+ * const browser = await (playwright[browserName] as BrowserType).connect(wsEndpoint, options);
82
+ * const context = await browser.newContext();
83
+ * const page = await context.newPage();
84
+ *
85
+ * await page.goto("https://playwright.dev/");
86
+ * await expect(page).toHaveTitle(/Playwright/);
87
+ *
88
+ * await page.close();
89
+ * await context.close();
90
+ * await browser.close();
91
+ * });
92
+ * ```
93
+ */
94
+ export type BrowserConnectOptions = EndpointOptions & {
95
+ options: ConnectOptions;
96
+ };
97
+ /**
98
+ * @public
99
+ *
100
+ * Base playwright configuration inputs required for generating the service config.
101
+ */
102
+ export type PlaywrightConfigInput = {
103
+ /**
104
+ * @public
105
+ *
106
+ * Path to the global setup file. This file will be required and run before all the tests. It must export a single
107
+ * function that takes a [`TestConfig`] argument.
108
+ *
109
+ * Learn more about {@link https://playwright.dev/docs/test-global-setup-teardown | global setup and teardown}.
110
+ */
111
+ globalSetup?: string;
112
+ /**
113
+ * @public
114
+ *
115
+ * Path to the global teardown file. This file will be required and run after all the tests. It must export a single
116
+ * function. See also
117
+ * {@link https://playwright.dev/docs/api/class-testconfig#test-config-global-teardown | testConfig.globalTeardown}.
118
+ *
119
+ * Learn more about {@link https://playwright.dev/docs/test-global-setup-teardown | global setup and teardown}.
120
+ */
121
+ globalTeardown?: string;
122
+ };
123
+ /**
124
+ * @public
125
+ *
126
+ * Playwright configuration integrated with Microsoft Playwright Testing.
127
+ *
128
+ * @remarks
129
+ *
130
+ * GlobalSetup and globalTeardown wraps around any existing global setup
131
+ * and teardown present in the base playwright configuration and runs it.
132
+ */
133
+ export type PlaywrightConfig = {
134
+ use?: {
135
+ connectOptions: BrowserConnectOptions;
136
+ };
137
+ globalSetup?: string;
138
+ globalTeardown?: string;
139
+ };
140
+ /**
141
+ * @public
142
+ *
143
+ * Additional options for the service.
144
+ */
145
+ export type PlaywrightServiceAdditionalOptions = {
146
+ /**
147
+ * @public
148
+ *
149
+ * Authentication types supported by Microsoft Playwright Testing.
150
+ *
151
+ * @defaultValue `ENTRA_ID`
152
+ */
153
+ serviceAuthType?: AuthenticationType;
154
+ /**
155
+ * @public
156
+ *
157
+ * Operating system types supported by Microsoft Playwright Testing.
158
+ *
159
+ * @defaultValue `linux`
160
+ */
161
+ os?: OsType;
162
+ /**
163
+ * @public
164
+ *
165
+ * Run id for the test run.
166
+ *
167
+ * @defaultValue `current datetime as ISO string`
168
+ */
169
+ runId?: string;
170
+ /**
171
+ * @public
172
+ *
173
+ * Maximum time in milliseconds to wait for the connection to be established.
174
+ *
175
+ * @defaultValue `30000`
176
+ */
177
+ timeout?: number;
178
+ /**
179
+ * @public
180
+ *
181
+ * Slows down Playwright operations by the specified amount of milliseconds.
182
+ *
183
+ * @defaultValue `0`
184
+ */
185
+ slowMo?: number;
186
+ /**
187
+ * @public
188
+ *
189
+ * Exposes network available on the connecting client to the browser being connected to.
190
+ *
191
+ * @defaultValue `<loopback>`
192
+ */
193
+ exposeNetwork?: string;
194
+ /**
195
+ * @public
196
+ *
197
+ * Use cloud hosted browsers.
198
+ *
199
+ * @defaultValue `false`
200
+ */
201
+ useCloudHostedBrowsers?: boolean;
202
+ /**
203
+ * @public
204
+ *
205
+ * Custom token credential for Entra ID authentication. Learn more at {@link https://github.com/Azure/azure-sdk-for-js/blob/main/documentation/using-azure-identity.md | Using Azure Identity}.
206
+ *
207
+ * @defaultValue `DefaultAzureCredential`
208
+ */
209
+ credential?: TokenCredential;
210
+ };
211
+ /**
212
+ * @public
213
+ *
214
+ * OS Types supported by Microsoft Playwright Testing.
215
+ */
216
+ export type OsType = (typeof ServiceOS)[keyof typeof ServiceOS];
217
+ /**
218
+ * @public
219
+ *
220
+ * Authentication types supported by Microsoft Playwright Testing.
221
+ */
222
+ export type AuthenticationType = (typeof ServiceAuth)[keyof typeof ServiceAuth];
223
+ export type ErrorDetails = {
224
+ message: string;
225
+ location?: Location;
226
+ };
227
+ export type ApiErrorMessage = {
228
+ [key: string]: {
229
+ [key: number]: string;
230
+ };
231
+ };
232
+ /**
233
+ * @public
234
+ *
235
+ * Optional configuration for MPT Reporter.
236
+ *
237
+ * @example
238
+ *
239
+ * ```
240
+ * import { defineConfig } from "@playwright/test";
241
+ *
242
+ * export default defineConfig({
243
+ * reporter: [["@azure/microsoft-playwright-testing/reporter", {
244
+ * enableGitHubSummary: true
245
+ * }]],
246
+ * });
247
+ * ```
248
+ */
249
+ export interface MPTReporterConfig {
250
+ /**
251
+ * @public
252
+ *
253
+ * Enable GitHub Actions annotations to diagnose test failures and deep link to MPT Portal.
254
+ *
255
+ * @defaultValue `true`
256
+ */
257
+ enableGitHubSummary?: boolean;
258
+ /**
259
+ * @public
260
+ *
261
+ * Enable result publishing for the test run. This will upload the test result and artifacts to the MPT Portal.
262
+ *
263
+ * @defaultValue `true`
264
+ */
265
+ enableResultPublish?: boolean;
266
+ }
267
+ export type DedupedStep = {
268
+ step: TestStep;
269
+ count: number;
270
+ duration: number;
271
+ };
272
+ export type RawTestStep = {
273
+ title: string;
274
+ category: string;
275
+ startTime: string;
276
+ duration: number;
277
+ error?: string;
278
+ steps: RawTestStep[];
279
+ location?: Location;
280
+ snippet?: string;
281
+ count: number;
282
+ };
283
+ export type IBackOffOptions = {
284
+ numOfAttempts: number;
285
+ retry: (e: any, attemptNumber: number) => boolean | Promise<boolean>;
286
+ jitter: JitterType;
287
+ };
288
+ export type JitterType = "full" | "none";
289
+ export type VersionInfo = {
290
+ major: number;
291
+ minor: number;
292
+ patch: number;
293
+ };
294
+ export type PackageManager = {
295
+ runCommand: (command: string, args: string) => string;
296
+ getVersionFromStdout: (stdout: string) => string;
297
+ };
298
+ export interface FullConfig {
299
+ configFile?: string;
300
+ }
301
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/common/types.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEvD,MAAM,MAAM,UAAU,GAAG;IACvB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IACxB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,UAAU,GAAG;IAC3C,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B;;;;OAIG;IACH,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B;;;;OAIG;IACH,OAAO,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IAEpC;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,MA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AAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,UAAU,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IACtD,oBAAoB,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC;CAClD,CAAC;AAIF,MAAM,WAAW,UAAU;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/common/types.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { Location, TestStep } from \"@playwright/test/reporter\";\nimport { ServiceAuth, ServiceOS } from \"./constants\";\nimport type { TokenCredential } from \"@azure/identity\";\n\nexport type JwtPayload = {\n iss?: string;\n sub?: string;\n aud?: string[] | string;\n exp?: number;\n nbf?: number;\n iat?: number;\n jti?: string;\n};\n\nexport type AccessTokenClaims = JwtPayload & {\n aid?: string;\n accountId?: string;\n};\n\n/**\n * @public\n *\n * Endpoint options for the service.\n */\nexport type EndpointOptions = {\n /**\n * @public\n *\n * A browser websocket endpoint to connect to.\n */\n wsEndpoint: string;\n};\n\n/**\n * @public\n *\n * Connect options for the service.\n */\nexport type ConnectOptions = {\n /**\n * @public\n *\n * Additional HTTP headers to be sent with web socket connect request.\n */\n headers?: { [key: string]: string };\n\n /**\n * @public\n *\n * Exposes network available on the connecting client to the browser being connected to.\n *\n * @defaultValue `<loopback>`\n */\n exposeNetwork?: string;\n\n /**\n * @public\n *\n * Maximum time in milliseconds to wait for the connection to be established.\n *\n * @defaultValue `30000`\n */\n timeout?: number;\n\n /**\n * @public\n *\n * Slows down Playwright operations by the specified amount of milliseconds.\n *\n * @defaultValue `0`\n */\n slowMo?: number;\n};\n\n/**\n * @public\n *\n * Browser connect options for the service. This includes endpoint options and connect options.\n *\n * @example\n * ```\n * import playwright, { test, expect, BrowserType } from \"@playwright/test\";\n * import { getConnectOptions, BrowserConnectOptions } from \"@azure/microsoft-playwright-testing\";\n *\n * test(\"has title\", async ({ browserName }) => {\n * const { wsEndpoint, options } : BrowserConnectOptions = await getConnectOptions();\n * const browser = await (playwright[browserName] as BrowserType).connect(wsEndpoint, options);\n * const context = await browser.newContext();\n * const page = await context.newPage();\n *\n * await page.goto(\"https://playwright.dev/\");\n * await expect(page).toHaveTitle(/Playwright/);\n *\n * await page.close();\n * await context.close();\n * await browser.close();\n * });\n * ```\n */\nexport type BrowserConnectOptions = EndpointOptions & {\n options: ConnectOptions;\n};\n\n/**\n * @public\n *\n * Base playwright configuration inputs required for generating the service config.\n */\nexport type PlaywrightConfigInput = {\n /**\n * @public\n *\n * Path to the global setup file. This file will be required and run before all the tests. It must export a single\n * function that takes a [`TestConfig`] argument.\n *\n * Learn more about {@link https://playwright.dev/docs/test-global-setup-teardown | global setup and teardown}.\n */\n globalSetup?: string;\n\n /**\n * @public\n *\n * Path to the global teardown file. This file will be required and run after all the tests. It must export a single\n * function. See also\n * {@link https://playwright.dev/docs/api/class-testconfig#test-config-global-teardown | testConfig.globalTeardown}.\n *\n * Learn more about {@link https://playwright.dev/docs/test-global-setup-teardown | global setup and teardown}.\n */\n globalTeardown?: string;\n};\n\n/**\n * @public\n *\n * Playwright configuration integrated with Microsoft Playwright Testing.\n *\n * @remarks\n *\n * GlobalSetup and globalTeardown wraps around any existing global setup\n * and teardown present in the base playwright configuration and runs it.\n */\nexport type PlaywrightConfig = {\n use?: {\n connectOptions: BrowserConnectOptions;\n };\n globalSetup?: string;\n globalTeardown?: string;\n};\n\n/**\n * @public\n *\n * Additional options for the service.\n */\nexport type PlaywrightServiceAdditionalOptions = {\n /**\n * @public\n *\n * Authentication types supported by Microsoft Playwright Testing.\n *\n * @defaultValue `ENTRA_ID`\n */\n serviceAuthType?: AuthenticationType;\n\n /**\n * @public\n *\n * Operating system types supported by Microsoft Playwright Testing.\n *\n * @defaultValue `linux`\n */\n os?: OsType;\n\n /**\n * @public\n *\n * Run id for the test run.\n *\n * @defaultValue `current datetime as ISO string`\n */\n runId?: string;\n\n /**\n * @public\n *\n * Maximum time in milliseconds to wait for the connection to be established.\n *\n * @defaultValue `30000`\n */\n timeout?: number;\n\n /**\n * @public\n *\n * Slows down Playwright operations by the specified amount of milliseconds.\n *\n * @defaultValue `0`\n */\n slowMo?: number;\n\n /**\n * @public\n *\n * Exposes network available on the connecting client to the browser being connected to.\n *\n * @defaultValue `<loopback>`\n */\n exposeNetwork?: string;\n\n /**\n * @public\n *\n * Use cloud hosted browsers.\n *\n * @defaultValue `false`\n */\n useCloudHostedBrowsers?: boolean;\n\n /**\n * @public\n *\n * Custom token credential for Entra ID authentication. Learn more at {@link https://github.com/Azure/azure-sdk-for-js/blob/main/documentation/using-azure-identity.md | Using Azure Identity}.\n *\n * @defaultValue `DefaultAzureCredential`\n */\n credential?: TokenCredential;\n};\n\n/**\n * @public\n *\n * OS Types supported by Microsoft Playwright Testing.\n */\nexport type OsType = (typeof ServiceOS)[keyof typeof ServiceOS];\n\n/**\n * @public\n *\n * Authentication types supported by Microsoft Playwright Testing.\n */\nexport type AuthenticationType = (typeof ServiceAuth)[keyof typeof ServiceAuth];\n\nexport type ErrorDetails = {\n message: string;\n location?: Location;\n};\nexport type ApiErrorMessage = {\n [key: string]: {\n [key: number]: string;\n };\n};\n/**\n * @public\n *\n * Optional configuration for MPT Reporter.\n *\n * @example\n *\n * ```\n * import { defineConfig } from \"@playwright/test\";\n *\n * export default defineConfig({\n * reporter: [[\"@azure/microsoft-playwright-testing/reporter\", {\n * enableGitHubSummary: true\n * }]],\n * });\n * ```\n */\nexport interface MPTReporterConfig {\n /**\n * @public\n *\n * Enable GitHub Actions annotations to diagnose test failures and deep link to MPT Portal.\n *\n * @defaultValue `true`\n */\n enableGitHubSummary?: boolean;\n\n /**\n * @public\n *\n * Enable result publishing for the test run. This will upload the test result and artifacts to the MPT Portal.\n *\n * @defaultValue `true`\n */\n enableResultPublish?: boolean;\n}\nexport type DedupedStep = { step: TestStep; count: number; duration: number };\n\nexport type RawTestStep = {\n title: string;\n category: string;\n startTime: string;\n duration: number;\n error?: string;\n steps: RawTestStep[];\n location?: Location;\n snippet?: string;\n count: number;\n};\n\nexport type IBackOffOptions = {\n numOfAttempts: number;\n retry: (e: any, attemptNumber: number) => boolean | Promise<boolean>;\n jitter: JitterType;\n};\n\nexport type JitterType = \"full\" | \"none\";\n\nexport type VersionInfo = {\n major: number;\n minor: number;\n patch: number;\n};\n\nexport type PackageManager = {\n runCommand: (command: string, args: string) => string;\n getVersionFromStdout: (stdout: string) => string;\n};\n\n// Playwright OSS Types\n\nexport interface FullConfig {\n configFile?: string;\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import { FullConfig } from "../../common/types";
2
+ declare const playwrightServiceGlobalSetupWrapper: (config: FullConfig) => Promise<any>;
3
+ export default playwrightServiceGlobalSetupWrapper;
4
+ //# sourceMappingURL=playwright-service-global-setup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"playwright-service-global-setup.d.ts","sourceRoot":"","sources":["../../../src/core/global/playwright-service-global-setup.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAKhD,QAAA,MAAM,mCAAmC,WAAkB,UAAU,KAAG,OAAO,CAAC,GAAG,CAWlF,CAAC;AAEF,eAAe,mCAAmC,CAAC"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ const tslib_1 = require("tslib");
6
+ const path_1 = require("path");
7
+ const playwrightServiceEntra_1 = tslib_1.__importDefault(require("../playwrightServiceEntra"));
8
+ const executor_1 = require("../../common/executor");
9
+ const customerConfig_1 = tslib_1.__importDefault(require("../../common/customerConfig"));
10
+ const playwrightServiceGlobalSetupWrapper = async (config) => {
11
+ const rootDir = config.configFile ? (0, path_1.dirname)(config.configFile) : process.cwd();
12
+ const customerGlobalSetupFunc = await (0, executor_1.loadCustomerGlobalFunction)(rootDir, customerConfig_1.default.globalSetup);
13
+ await playwrightServiceEntra_1.default.globalSetup();
14
+ if (customerGlobalSetupFunc) {
15
+ return customerGlobalSetupFunc(config);
16
+ }
17
+ };
18
+ exports.default = playwrightServiceGlobalSetupWrapper;
19
+ //# sourceMappingURL=playwright-service-global-setup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"playwright-service-global-setup.js","sourceRoot":"","sources":["../../../src/core/global/playwright-service-global-setup.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,+BAA+B;AAE/B,+FAA+D;AAC/D,oDAAmE;AACnE,yFAAyD;AAEzD,MAAM,mCAAmC,GAAG,KAAK,EAAE,MAAkB,EAAgB,EAAE;IACrF,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,IAAA,cAAO,EAAC,MAAM,CAAC,UAAW,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;IAChF,MAAM,uBAAuB,GAAG,MAAM,IAAA,qCAA0B,EAC9D,OAAO,EACP,wBAAc,CAAC,WAAW,CAC3B,CAAC;IAEF,MAAM,gCAAsB,CAAC,WAAW,EAAE,CAAC;IAC3C,IAAI,uBAAuB,EAAE,CAAC;QAC5B,OAAO,uBAAuB,CAAC,MAAM,CAAC,CAAC;IACzC,CAAC;AACH,CAAC,CAAC;AAEF,kBAAe,mCAAmC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { dirname } from \"path\";\nimport { FullConfig } from \"../../common/types\";\nimport playwrightServiceEntra from \"../playwrightServiceEntra\";\nimport { loadCustomerGlobalFunction } from \"../../common/executor\";\nimport customerConfig from \"../../common/customerConfig\";\n\nconst playwrightServiceGlobalSetupWrapper = async (config: FullConfig): Promise<any> => {\n const rootDir = config.configFile ? dirname(config.configFile!) : process.cwd();\n const customerGlobalSetupFunc = await loadCustomerGlobalFunction(\n rootDir,\n customerConfig.globalSetup,\n );\n\n await playwrightServiceEntra.globalSetup();\n if (customerGlobalSetupFunc) {\n return customerGlobalSetupFunc(config);\n }\n};\n\nexport default playwrightServiceGlobalSetupWrapper;\n"]}
@@ -0,0 +1,4 @@
1
+ import { FullConfig } from "../../common/types";
2
+ declare const playwrightServiceGlobalTeardownWrapper: (config: FullConfig) => Promise<void>;
3
+ export default playwrightServiceGlobalTeardownWrapper;
4
+ //# sourceMappingURL=playwright-service-global-teardown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"playwright-service-global-teardown.d.ts","sourceRoot":"","sources":["../../../src/core/global/playwright-service-global-teardown.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAKhD,QAAA,MAAM,sCAAsC,WAAkB,UAAU,KAAG,OAAO,CAAC,IAAI,CAWtF,CAAC;AAEF,eAAe,sCAAsC,CAAC"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ const tslib_1 = require("tslib");
6
+ const path_1 = require("path");
7
+ const playwrightServiceEntra_1 = tslib_1.__importDefault(require("../playwrightServiceEntra"));
8
+ const executor_1 = require("../../common/executor");
9
+ const customerConfig_1 = tslib_1.__importDefault(require("../../common/customerConfig"));
10
+ const playwrightServiceGlobalTeardownWrapper = async (config) => {
11
+ const rootDir = config.configFile ? (0, path_1.dirname)(config.configFile) : process.cwd();
12
+ const customerGlobalTeardownFunc = await (0, executor_1.loadCustomerGlobalFunction)(rootDir, customerConfig_1.default.globalTeardown);
13
+ playwrightServiceEntra_1.default.globalTeardown();
14
+ if (customerGlobalTeardownFunc) {
15
+ await customerGlobalTeardownFunc(config);
16
+ }
17
+ };
18
+ exports.default = playwrightServiceGlobalTeardownWrapper;
19
+ //# sourceMappingURL=playwright-service-global-teardown.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"playwright-service-global-teardown.js","sourceRoot":"","sources":["../../../src/core/global/playwright-service-global-teardown.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,+BAA+B;AAE/B,+FAA+D;AAC/D,oDAAmE;AACnE,yFAAyD;AAEzD,MAAM,sCAAsC,GAAG,KAAK,EAAE,MAAkB,EAAiB,EAAE;IACzF,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,IAAA,cAAO,EAAC,MAAM,CAAC,UAAW,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;IAChF,MAAM,0BAA0B,GAAG,MAAM,IAAA,qCAA0B,EACjE,OAAO,EACP,wBAAc,CAAC,cAAc,CAC9B,CAAC;IAEF,gCAAsB,CAAC,cAAc,EAAE,CAAC;IACxC,IAAI,0BAA0B,EAAE,CAAC;QAC/B,MAAM,0BAA0B,CAAC,MAAM,CAAC,CAAC;IAC3C,CAAC;AACH,CAAC,CAAC;AAEF,kBAAe,sCAAsC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { dirname } from \"path\";\nimport { FullConfig } from \"../../common/types\";\nimport playwrightServiceEntra from \"../playwrightServiceEntra\";\nimport { loadCustomerGlobalFunction } from \"../../common/executor\";\nimport customerConfig from \"../../common/customerConfig\";\n\nconst playwrightServiceGlobalTeardownWrapper = async (config: FullConfig): Promise<void> => {\n const rootDir = config.configFile ? dirname(config.configFile!) : process.cwd();\n const customerGlobalTeardownFunc = await loadCustomerGlobalFunction(\n rootDir,\n customerConfig.globalTeardown,\n );\n\n playwrightServiceEntra.globalTeardown();\n if (customerGlobalTeardownFunc) {\n await customerGlobalTeardownFunc(config);\n }\n};\n\nexport default playwrightServiceGlobalTeardownWrapper;\n"]}
@@ -0,0 +1,63 @@
1
+ import { PlaywrightServiceAdditionalOptions, PlaywrightConfig, PlaywrightConfigInput, BrowserConnectOptions } from "../common/types";
2
+ /**
3
+ * @public
4
+ *
5
+ * Generate playwright configuration integrated with Microsoft Playwright Testing.
6
+ *
7
+ * @param config - base playwright configuration
8
+ * @param options - additional options for the service
9
+ * @returns PlaywrightConfig
10
+ *
11
+ * @example
12
+ * ```
13
+ * import { defineConfig } from "playwright/test";
14
+ * import { getServiceConfig } from "@azure/microsoft-playwright-testing";
15
+ * import playwrightConfig from "./playwright.config";
16
+ *
17
+ * export default defineConfig(playwrightConfig, getServiceConfig(playwrightConfig));
18
+ * ```
19
+ *
20
+ * @example
21
+ * ```
22
+ * import { defineConfig } from "playwright/test";
23
+ * import { getServiceConfig, ServiceOS } from "@azure/microsoft-playwright-testing";
24
+ * import playwrightConfig from "./playwright.config";
25
+ *
26
+ * export default defineConfig(playwrightConfig, getServiceConfig(playwrightConfig, {
27
+ * runId: "custom run id",
28
+ * os: ServiceOS.WINDOWS
29
+ * }));
30
+ * ```
31
+ */
32
+ declare const getServiceConfig: (config: PlaywrightConfigInput, options?: PlaywrightServiceAdditionalOptions) => PlaywrightConfig;
33
+ /**
34
+ * @public
35
+ *
36
+ * Get connect options required to connect to Microsoft Playwright Testing's cloud hosted browsers.
37
+ *
38
+ * @param options - additional options for the service
39
+ * @returns BrowserConnectOptions
40
+ *
41
+ * @example
42
+ * ```
43
+ * import playwright, { test, expect, BrowserType } from "@playwright/test";
44
+ * import { getConnectOptions } from "@azure/microsoft-playwright-testing";
45
+ *
46
+ * test('has title', async ({ browserName }) => {
47
+ * const { wsEndpoint, options } = await getConnectOptions();
48
+ * const browser = await (playwright[browserName] as BrowserType).connect(wsEndpoint, options);
49
+ * const context = await browser.newContext();
50
+ * const page = await context.newPage();
51
+ *
52
+ * await page.goto('https://playwright.dev/');
53
+ * await expect(page).toHaveTitle(/Playwright/);
54
+ *
55
+ * await page.close();
56
+ * await context.close();
57
+ * await browser.close();
58
+ * });
59
+ * ```
60
+ */
61
+ declare const getConnectOptions: (options?: Omit<PlaywrightServiceAdditionalOptions, "serviceAuthType">) => Promise<BrowserConnectOptions>;
62
+ export { getServiceConfig, getConnectOptions };
63
+ //# sourceMappingURL=playwrightService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"playwrightService.d.ts","sourceRoot":"","sources":["../../src/core/playwrightService.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,kCAAkC,EAClC,gBAAgB,EAChB,qBAAqB,EACrB,qBAAqB,EACtB,MAAM,iBAAiB,CAAC;AAWzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,QAAA,MAAM,gBAAgB,WACZ,qBAAqB,YACnB,kCAAkC,KAC3C,gBAqDF,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,QAAA,MAAM,iBAAiB,aACX,IAAI,CAAC,kCAAkC,EAAE,iBAAiB,CAAC,KACpE,OAAO,CAAC,qBAAqB,CAmB/B,CAAC;AAEF,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,CAAC"}
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.getConnectOptions = exports.getServiceConfig = void 0;
6
+ const tslib_1 = require("tslib");
7
+ const constants_1 = require("../common/constants");
8
+ const customerConfig_1 = tslib_1.__importDefault(require("../common/customerConfig"));
9
+ const playwrightServiceConfig_1 = require("../common/playwrightServiceConfig");
10
+ const playwrightServiceEntra_1 = tslib_1.__importDefault(require("./playwrightServiceEntra"));
11
+ const utils_1 = require("../utils/utils");
12
+ /**
13
+ * @public
14
+ *
15
+ * Generate playwright configuration integrated with Microsoft Playwright Testing.
16
+ *
17
+ * @param config - base playwright configuration
18
+ * @param options - additional options for the service
19
+ * @returns PlaywrightConfig
20
+ *
21
+ * @example
22
+ * ```
23
+ * import { defineConfig } from "playwright/test";
24
+ * import { getServiceConfig } from "@azure/microsoft-playwright-testing";
25
+ * import playwrightConfig from "./playwright.config";
26
+ *
27
+ * export default defineConfig(playwrightConfig, getServiceConfig(playwrightConfig));
28
+ * ```
29
+ *
30
+ * @example
31
+ * ```
32
+ * import { defineConfig } from "playwright/test";
33
+ * import { getServiceConfig, ServiceOS } from "@azure/microsoft-playwright-testing";
34
+ * import playwrightConfig from "./playwright.config";
35
+ *
36
+ * export default defineConfig(playwrightConfig, getServiceConfig(playwrightConfig, {
37
+ * runId: "custom run id",
38
+ * os: ServiceOS.WINDOWS
39
+ * }));
40
+ * ```
41
+ */
42
+ const getServiceConfig = (config, options) => {
43
+ (0, utils_1.validatePlaywrightVersion)();
44
+ (0, utils_1.validateServiceUrl)();
45
+ if (options === null || options === void 0 ? void 0 : options.credential) {
46
+ playwrightServiceEntra_1.default.entraIdAccessToken = options.credential;
47
+ }
48
+ if (config.globalSetup) {
49
+ customerConfig_1.default.globalSetup = config.globalSetup;
50
+ }
51
+ if (config.globalTeardown) {
52
+ customerConfig_1.default.globalTeardown = config.globalTeardown;
53
+ }
54
+ const playwrightServiceConfig = new playwrightServiceConfig_1.PlaywrightServiceConfig();
55
+ playwrightServiceConfig.setOptions(options);
56
+ (0, utils_1.emitReportingUrl)();
57
+ const globalFunctions = {};
58
+ if ((options === null || options === void 0 ? void 0 : options.serviceAuthType) === constants_1.ServiceAuth.ACCESS_TOKEN) {
59
+ // mpt PAT requested and set by the customer, no need to setup entra lifecycle handlers
60
+ (0, utils_1.validateMptPAT)();
61
+ }
62
+ else {
63
+ globalFunctions.globalSetup = require.resolve("./global/playwright-service-global-setup");
64
+ globalFunctions.globalTeardown = require.resolve("./global/playwright-service-global-teardown");
65
+ }
66
+ if ((options === null || options === void 0 ? void 0 : options.useCloudHostedBrowsers) === false) {
67
+ return Object.assign({}, globalFunctions);
68
+ }
69
+ if (!process.env[constants_1.InternalEnvironmentVariables.MPT_CLOUD_HOSTED_BROWSER_USED]) {
70
+ process.env[constants_1.InternalEnvironmentVariables.MPT_CLOUD_HOSTED_BROWSER_USED] = "true";
71
+ console.log("\nRunning tests using Microsoft Playwright Testing service.");
72
+ }
73
+ return Object.assign({ use: {
74
+ connectOptions: {
75
+ wsEndpoint: (0, utils_1.getServiceWSEndpoint)(playwrightServiceConfig.runId, playwrightServiceConfig.serviceOs),
76
+ headers: {
77
+ Authorization: `Bearer ${(0, utils_1.getAccessToken)()}`,
78
+ },
79
+ timeout: playwrightServiceConfig.timeout,
80
+ exposeNetwork: playwrightServiceConfig.exposeNetwork,
81
+ slowMo: playwrightServiceConfig.slowMo,
82
+ },
83
+ } }, globalFunctions);
84
+ };
85
+ exports.getServiceConfig = getServiceConfig;
86
+ /**
87
+ * @public
88
+ *
89
+ * Get connect options required to connect to Microsoft Playwright Testing's cloud hosted browsers.
90
+ *
91
+ * @param options - additional options for the service
92
+ * @returns BrowserConnectOptions
93
+ *
94
+ * @example
95
+ * ```
96
+ * import playwright, { test, expect, BrowserType } from "@playwright/test";
97
+ * import { getConnectOptions } from "@azure/microsoft-playwright-testing";
98
+ *
99
+ * test('has title', async ({ browserName }) => {
100
+ * const { wsEndpoint, options } = await getConnectOptions();
101
+ * const browser = await (playwright[browserName] as BrowserType).connect(wsEndpoint, options);
102
+ * const context = await browser.newContext();
103
+ * const page = await context.newPage();
104
+ *
105
+ * await page.goto('https://playwright.dev/');
106
+ * await expect(page).toHaveTitle(/Playwright/);
107
+ *
108
+ * await page.close();
109
+ * await context.close();
110
+ * await browser.close();
111
+ * });
112
+ * ```
113
+ */
114
+ const getConnectOptions = async (options) => {
115
+ const playwrightServiceConfig = new playwrightServiceConfig_1.PlaywrightServiceConfig();
116
+ playwrightServiceConfig.setOptions(options);
117
+ const token = await (0, utils_1.fetchOrValidateAccessToken)(options === null || options === void 0 ? void 0 : options.credential);
118
+ return {
119
+ wsEndpoint: (0, utils_1.getServiceWSEndpoint)(playwrightServiceConfig.runId, playwrightServiceConfig.serviceOs),
120
+ options: {
121
+ headers: {
122
+ Authorization: `Bearer ${token}`,
123
+ },
124
+ timeout: playwrightServiceConfig.timeout,
125
+ exposeNetwork: playwrightServiceConfig.exposeNetwork,
126
+ slowMo: playwrightServiceConfig.slowMo,
127
+ },
128
+ };
129
+ };
130
+ exports.getConnectOptions = getConnectOptions;
131
+ //# sourceMappingURL=playwrightService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"playwrightService.js","sourceRoot":"","sources":["../../src/core/playwrightService.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;;AAElC,mDAAgF;AAChF,sFAAsD;AACtD,+EAA4E;AAC5E,8FAA8D;AAO9D,0CAQwB;AAExB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,gBAAgB,GAAG,CACvB,MAA6B,EAC7B,OAA4C,EAC1B,EAAE;IACpB,IAAA,iCAAyB,GAAE,CAAC;IAC5B,IAAA,0BAAkB,GAAE,CAAC;IACrB,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU,EAAE,CAAC;QACxB,gCAAsB,CAAC,kBAAkB,GAAG,OAAO,CAAC,UAAU,CAAC;IACjE,CAAC;IACD,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC;QACvB,wBAAc,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;IAClD,CAAC;IACD,IAAI,MAAM,CAAC,cAAc,EAAE,CAAC;QAC1B,wBAAc,CAAC,cAAc,GAAG,MAAM,CAAC,cAAc,CAAC;IACxD,CAAC;IAED,MAAM,uBAAuB,GAAG,IAAI,iDAAuB,EAAE,CAAC;IAC9D,uBAAuB,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;I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ACrC,EAAE;IAClC,MAAM,uBAAuB,GAAG,IAAI,iDAAuB,EAAE,CAAC;IAC9D,uBAAuB,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IAE5C,MAAM,KAAK,GAAG,MAAM,IAAA,kCAA0B,EAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU,CAAC,CAAC;IACpE,OAAO;QACL,UAAU,EAAE,IAAA,4BAAoB,EAC9B,uBAAuB,CAAC,KAAK,EAC7B,uBAAuB,CAAC,SAAS,CAClC;QACD,OAAO,EAAE;YACP,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,KAAK,EAAE;aACjC;YACD,OAAO,EAAE,uBAAuB,CAAC,OAAO;YACxC,aAAa,EAAE,uBAAuB,CAAC,aAAa;YACpD,MAAM,EAAE,uBAAuB,CAAC,MAAM;SACvC;KACF,CAAC;AACJ,CAAC,CAAC;AAEyB,8CAAiB","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { InternalEnvironmentVariables, ServiceAuth } from \"../common/constants\";\nimport customerConfig from \"../common/customerConfig\";\nimport { PlaywrightServiceConfig } from \"../common/playwrightServiceConfig\";\nimport playwrightServiceEntra from \"./playwrightServiceEntra\";\nimport {\n PlaywrightServiceAdditionalOptions,\n PlaywrightConfig,\n PlaywrightConfigInput,\n BrowserConnectOptions,\n} from \"../common/types\";\nimport {\n emitReportingUrl,\n fetchOrValidateAccessToken,\n getAccessToken,\n getServiceWSEndpoint,\n validateMptPAT,\n validatePlaywrightVersion,\n validateServiceUrl,\n} from \"../utils/utils\";\n\n/**\n * @public\n *\n * Generate playwright configuration integrated with Microsoft Playwright Testing.\n *\n * @param config - base playwright configuration\n * @param options - additional options for the service\n * @returns PlaywrightConfig\n *\n * @example\n * ```\n * import { defineConfig } from \"playwright/test\";\n * import { getServiceConfig } from \"@azure/microsoft-playwright-testing\";\n * import playwrightConfig from \"./playwright.config\";\n *\n * export default defineConfig(playwrightConfig, getServiceConfig(playwrightConfig));\n * ```\n *\n * @example\n * ```\n * import { defineConfig } from \"playwright/test\";\n * import { getServiceConfig, ServiceOS } from \"@azure/microsoft-playwright-testing\";\n * import playwrightConfig from \"./playwright.config\";\n *\n * export default defineConfig(playwrightConfig, getServiceConfig(playwrightConfig, {\n * runId: \"custom run id\",\n * os: ServiceOS.WINDOWS\n * }));\n * ```\n */\nconst getServiceConfig = (\n config: PlaywrightConfigInput,\n options?: PlaywrightServiceAdditionalOptions,\n): PlaywrightConfig => {\n validatePlaywrightVersion();\n validateServiceUrl();\n if (options?.credential) {\n playwrightServiceEntra.entraIdAccessToken = options.credential;\n }\n if (config.globalSetup) {\n customerConfig.globalSetup = config.globalSetup;\n }\n if (config.globalTeardown) {\n customerConfig.globalTeardown = config.globalTeardown;\n }\n\n const playwrightServiceConfig = new PlaywrightServiceConfig();\n playwrightServiceConfig.setOptions(options);\n emitReportingUrl();\n\n const globalFunctions: any = {};\n if (options?.serviceAuthType === ServiceAuth.ACCESS_TOKEN) {\n // mpt PAT requested and set by the customer, no need to setup entra lifecycle handlers\n validateMptPAT();\n } else {\n globalFunctions.globalSetup = require.resolve(\"./global/playwright-service-global-setup\");\n globalFunctions.globalTeardown = require.resolve(\"./global/playwright-service-global-teardown\");\n }\n\n if (options?.useCloudHostedBrowsers === false) {\n return {\n ...globalFunctions,\n };\n }\n if (!process.env[InternalEnvironmentVariables.MPT_CLOUD_HOSTED_BROWSER_USED]) {\n process.env[InternalEnvironmentVariables.MPT_CLOUD_HOSTED_BROWSER_USED] = \"true\";\n console.log(\"\\nRunning tests using Microsoft Playwright Testing service.\");\n }\n\n return {\n use: {\n connectOptions: {\n wsEndpoint: getServiceWSEndpoint(\n playwrightServiceConfig.runId,\n playwrightServiceConfig.serviceOs,\n ),\n headers: {\n Authorization: `Bearer ${getAccessToken()}`,\n },\n timeout: playwrightServiceConfig.timeout,\n exposeNetwork: playwrightServiceConfig.exposeNetwork,\n slowMo: playwrightServiceConfig.slowMo,\n },\n },\n ...globalFunctions,\n };\n};\n\n/**\n * @public\n *\n * Get connect options required to connect to Microsoft Playwright Testing's cloud hosted browsers.\n *\n * @param options - additional options for the service\n * @returns BrowserConnectOptions\n *\n * @example\n * ```\n * import playwright, { test, expect, BrowserType } from \"@playwright/test\";\n * import { getConnectOptions } from \"@azure/microsoft-playwright-testing\";\n *\n * test('has title', async ({ browserName }) => {\n * const { wsEndpoint, options } = await getConnectOptions();\n * const browser = await (playwright[browserName] as BrowserType).connect(wsEndpoint, options);\n * const context = await browser.newContext();\n * const page = await context.newPage();\n *\n * await page.goto('https://playwright.dev/');\n * await expect(page).toHaveTitle(/Playwright/);\n *\n * await page.close();\n * await context.close();\n * await browser.close();\n * });\n * ```\n */\nconst getConnectOptions = async (\n options?: Omit<PlaywrightServiceAdditionalOptions, \"serviceAuthType\">,\n): Promise<BrowserConnectOptions> => {\n const playwrightServiceConfig = new PlaywrightServiceConfig();\n playwrightServiceConfig.setOptions(options);\n\n const token = await fetchOrValidateAccessToken(options?.credential);\n return {\n wsEndpoint: getServiceWSEndpoint(\n playwrightServiceConfig.runId,\n playwrightServiceConfig.serviceOs,\n ),\n options: {\n headers: {\n Authorization: `Bearer ${token}`,\n },\n timeout: playwrightServiceConfig.timeout,\n exposeNetwork: playwrightServiceConfig.exposeNetwork,\n slowMo: playwrightServiceConfig.slowMo,\n },\n };\n};\n\nexport { getServiceConfig, getConnectOptions };\n"]}
@@ -0,0 +1,16 @@
1
+ import type { TokenCredential } from "@azure/identity";
2
+ declare class PlaywrightServiceEntra {
3
+ private _entraIdAccessTokenRotationInterval?;
4
+ private static instance;
5
+ private _entraIdAccessToken;
6
+ static getInstance: () => PlaywrightServiceEntra;
7
+ set entraIdAccessToken(credential: TokenCredential);
8
+ constructor();
9
+ globalSetup: () => Promise<void>;
10
+ globalTeardown: () => void;
11
+ private entraIdGlobalSetupRotationHandler;
12
+ private entraIdAccessTokenRotation;
13
+ }
14
+ declare const instance: PlaywrightServiceEntra;
15
+ export default instance;
16
+ //# sourceMappingURL=playwrightServiceEntra.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"playwrightServiceEntra.d.ts","sourceRoot":"","sources":["../../src/core/playwrightServiceEntra.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEvD,cAAM,sBAAsB;IAC1B,OAAO,CAAC,mCAAmC,CAAC,CAAiB;IAC7D,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAyB;IAChD,OAAO,CAAC,mBAAmB,CAAqB;IAEhD,MAAM,CAAC,WAAW,QAAO,sBAAsB,CAK7C;IAEF,IAAI,kBAAkB,CAAC,UAAU,EAAE,eAAe,EAEjD;;IAMM,WAAW,QAAa,OAAO,CAAC,IAAI,CAAC,CAI1C;IAEK,cAAc,QAAO,IAAI,CAM9B;IAEF,OAAO,CAAC,iCAAiC,CAMvC;IAEF,OAAO,CAAC,0BAA0B,CAShC;CACH;AAED,QAAA,MAAM,QAAQ,wBAAuC,CAAC;AACtD,eAAe,QAAQ,CAAC"}