@azure/playwright 1.1.3 → 1.1.4

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 (125) hide show
  1. package/dist/browser/common/constants.d.ts +1 -4
  2. package/dist/browser/common/constants.d.ts.map +1 -1
  3. package/dist/browser/common/constants.js +1 -4
  4. package/dist/browser/common/constants.js.map +1 -1
  5. package/dist/browser/common/types.d.ts +0 -4
  6. package/dist/browser/common/types.d.ts.map +1 -1
  7. package/dist/browser/common/types.js.map +1 -1
  8. package/dist/browser/reporter/playwrightReporter.d.ts +0 -1
  9. package/dist/browser/reporter/playwrightReporter.d.ts.map +1 -1
  10. package/dist/browser/reporter/playwrightReporter.js +3 -17
  11. package/dist/browser/reporter/playwrightReporter.js.map +1 -1
  12. package/dist/browser/utils/PlaywrightServiceClient.d.ts +1 -2
  13. package/dist/browser/utils/PlaywrightServiceClient.d.ts.map +1 -1
  14. package/dist/browser/utils/PlaywrightServiceClient.js +1 -26
  15. package/dist/browser/utils/PlaywrightServiceClient.js.map +1 -1
  16. package/dist/browser/utils/utils.d.ts +2 -3
  17. package/dist/browser/utils/utils.d.ts.map +1 -1
  18. package/dist/browser/utils/utils.js +8 -21
  19. package/dist/browser/utils/utils.js.map +1 -1
  20. package/dist/commonjs/common/constants.d.ts +1 -4
  21. package/dist/commonjs/common/constants.d.ts.map +1 -1
  22. package/dist/commonjs/common/constants.js +2 -5
  23. package/dist/commonjs/common/constants.js.map +1 -1
  24. package/dist/commonjs/common/types.d.ts +0 -4
  25. package/dist/commonjs/common/types.d.ts.map +1 -1
  26. package/dist/commonjs/common/types.js.map +1 -1
  27. package/dist/commonjs/reporter/playwrightReporter.d.ts +0 -1
  28. package/dist/commonjs/reporter/playwrightReporter.d.ts.map +1 -1
  29. package/dist/commonjs/reporter/playwrightReporter.js +2 -16
  30. package/dist/commonjs/reporter/playwrightReporter.js.map +1 -1
  31. package/dist/commonjs/tsdoc-metadata.json +1 -1
  32. package/dist/commonjs/utils/PlaywrightServiceClient.d.ts +1 -2
  33. package/dist/commonjs/utils/PlaywrightServiceClient.d.ts.map +1 -1
  34. package/dist/commonjs/utils/PlaywrightServiceClient.js +0 -25
  35. package/dist/commonjs/utils/PlaywrightServiceClient.js.map +1 -1
  36. package/dist/commonjs/utils/utils.d.ts +2 -3
  37. package/dist/commonjs/utils/utils.d.ts.map +1 -1
  38. package/dist/commonjs/utils/utils.js +8 -22
  39. package/dist/commonjs/utils/utils.js.map +1 -1
  40. package/dist/esm/common/constants.d.ts +1 -4
  41. package/dist/esm/common/constants.d.ts.map +1 -1
  42. package/dist/esm/common/constants.js +92 -96
  43. package/dist/esm/common/constants.js.map +1 -7
  44. package/dist/esm/common/customerConfig.js +11 -11
  45. package/dist/esm/common/customerConfig.js.map +1 -7
  46. package/dist/esm/common/entraIdAccessToken.js +77 -85
  47. package/dist/esm/common/entraIdAccessToken.js.map +1 -7
  48. package/dist/esm/common/environmentVariables.js +19 -19
  49. package/dist/esm/common/environmentVariables.js.map +1 -7
  50. package/dist/esm/common/executor.js +58 -51
  51. package/dist/esm/common/executor.js.map +1 -7
  52. package/dist/esm/common/httpService.js +29 -34
  53. package/dist/esm/common/httpService.js.map +1 -7
  54. package/dist/esm/common/logger.js +4 -4
  55. package/dist/esm/common/logger.js.map +1 -7
  56. package/dist/esm/common/messages.js +166 -166
  57. package/dist/esm/common/messages.js.map +1 -7
  58. package/dist/esm/common/playwrightServiceConfig.js +91 -91
  59. package/dist/esm/common/playwrightServiceConfig.js.map +1 -7
  60. package/dist/esm/common/state.js +7 -7
  61. package/dist/esm/common/state.js.map +1 -7
  62. package/dist/esm/common/types.d.ts +0 -4
  63. package/dist/esm/common/types.d.ts.map +1 -1
  64. package/dist/esm/common/types.js +4 -0
  65. package/dist/esm/common/types.js.map +1 -7
  66. package/dist/esm/core/global/playwright-service-global-setup.js +17 -17
  67. package/dist/esm/core/global/playwright-service-global-setup.js.map +1 -7
  68. package/dist/esm/core/global/playwright-service-global-teardown.js +13 -16
  69. package/dist/esm/core/global/playwright-service-global-teardown.js.map +1 -7
  70. package/dist/esm/core/initializePlaywrightServiceTestRun.js +21 -13
  71. package/dist/esm/core/initializePlaywrightServiceTestRun.js.map +1 -7
  72. package/dist/esm/core/playwrightService.js +200 -149
  73. package/dist/esm/core/playwrightService.js.map +1 -7
  74. package/dist/esm/core/playwrightServiceEntra.js +42 -44
  75. package/dist/esm/core/playwrightServiceEntra.js.map +1 -7
  76. package/dist/esm/core/playwrightServiceUtils.js +8 -6
  77. package/dist/esm/core/playwrightServiceUtils.js.map +1 -7
  78. package/dist/esm/index.js +9 -7
  79. package/dist/esm/index.js.map +1 -7
  80. package/dist/esm/reporter/index.js +11 -4
  81. package/dist/esm/reporter/index.js.map +1 -7
  82. package/dist/esm/reporter/playwrightReporter.d.ts +0 -1
  83. package/dist/esm/reporter/playwrightReporter.d.ts.map +1 -1
  84. package/dist/esm/reporter/playwrightReporter.js +193 -202
  85. package/dist/esm/reporter/playwrightReporter.js.map +1 -7
  86. package/dist/esm/utils/PlaywrightServiceClient.d.ts +1 -2
  87. package/dist/esm/utils/PlaywrightServiceClient.d.ts.map +1 -1
  88. package/dist/esm/utils/PlaywrightServiceClient.js +61 -121
  89. package/dist/esm/utils/PlaywrightServiceClient.js.map +1 -7
  90. package/dist/esm/utils/cIInfoProvider.js +71 -58
  91. package/dist/esm/utils/cIInfoProvider.js.map +1 -7
  92. package/dist/esm/utils/getPackageVersion.js +17 -12
  93. package/dist/esm/utils/getPackageVersion.js.map +1 -7
  94. package/dist/esm/utils/getPlaywrightVersion.js +13 -15
  95. package/dist/esm/utils/getPlaywrightVersion.js.map +1 -7
  96. package/dist/esm/utils/packageManager.js +37 -37
  97. package/dist/esm/utils/packageManager.js.map +1 -7
  98. package/dist/esm/utils/parseJwt.js +14 -15
  99. package/dist/esm/utils/parseJwt.js.map +1 -7
  100. package/dist/esm/utils/playwrightReporterStorageManager.js +333 -358
  101. package/dist/esm/utils/playwrightReporterStorageManager.js.map +1 -7
  102. package/dist/esm/utils/utils.d.ts +2 -3
  103. package/dist/esm/utils/utils.d.ts.map +1 -1
  104. package/dist/esm/utils/utils.js +338 -380
  105. package/dist/esm/utils/utils.js.map +1 -7
  106. package/dist/react-native/common/constants.d.ts +1 -4
  107. package/dist/react-native/common/constants.d.ts.map +1 -1
  108. package/dist/react-native/common/constants.js +1 -4
  109. package/dist/react-native/common/constants.js.map +1 -1
  110. package/dist/react-native/common/types.d.ts +0 -4
  111. package/dist/react-native/common/types.d.ts.map +1 -1
  112. package/dist/react-native/common/types.js.map +1 -1
  113. package/dist/react-native/reporter/playwrightReporter.d.ts +0 -1
  114. package/dist/react-native/reporter/playwrightReporter.d.ts.map +1 -1
  115. package/dist/react-native/reporter/playwrightReporter.js +3 -17
  116. package/dist/react-native/reporter/playwrightReporter.js.map +1 -1
  117. package/dist/react-native/utils/PlaywrightServiceClient.d.ts +1 -2
  118. package/dist/react-native/utils/PlaywrightServiceClient.d.ts.map +1 -1
  119. package/dist/react-native/utils/PlaywrightServiceClient.js +1 -26
  120. package/dist/react-native/utils/PlaywrightServiceClient.js.map +1 -1
  121. package/dist/react-native/utils/utils.d.ts +2 -3
  122. package/dist/react-native/utils/utils.d.ts.map +1 -1
  123. package/dist/react-native/utils/utils.js +8 -21
  124. package/dist/react-native/utils/utils.js.map +1 -1
  125. package/package.json +6 -6
@@ -1,168 +1,219 @@
1
- import {
2
- DefaultConnectOptionsConstants,
3
- InternalEnvironmentVariables,
4
- ServiceAuth
5
- } from "../common/constants.js";
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ import { DefaultConnectOptionsConstants, InternalEnvironmentVariables, ServiceAuth, } from "../common/constants.js";
6
4
  import customerConfig from "../common/customerConfig.js";
7
5
  import { PlaywrightServiceConfig } from "../common/playwrightServiceConfig.js";
8
6
  import playwrightServiceEntra from "./playwrightServiceEntra.js";
9
- import {
10
- fetchOrValidateAccessToken,
11
- getAccessToken,
12
- getServiceWSEndpoint,
13
- validateMptPAT,
14
- validatePlaywrightVersion,
15
- validateServiceUrl,
16
- exitWithFailureMessage,
17
- getPlaywrightVersion,
18
- getVersionInfo,
19
- throwErrorWithFailureMessage,
20
- getPackageVersion,
21
- warnIfAccessTokenCloseToExpiry
22
- } from "../utils/utils.js";
7
+ import { fetchOrValidateAccessToken, getAccessToken, getServiceWSEndpoint, validateMptPAT, validatePlaywrightVersion, validateServiceUrl, exitWithFailureMessage, getPlaywrightVersion, getVersionInfo, throwErrorWithFailureMessage, getPackageVersion, warnIfAccessTokenCloseToExpiry, } from "../utils/utils.js";
23
8
  import { ServiceErrorMessageConstants } from "../common/messages.js";
24
9
  import { globalPaths } from "./playwrightServiceUtils.js";
25
10
  const performOneTimeOperation = (options) => {
26
- const oneTimeOperationFlag = process.env[InternalEnvironmentVariables.ONE_TIME_OPERATION_FLAG] === "true";
27
- if (oneTimeOperationFlag) return;
28
- process.env[InternalEnvironmentVariables.ONE_TIME_OPERATION_FLAG] = "true";
29
- if (options?.serviceAuthType === ServiceAuth.ACCESS_TOKEN) {
30
- warnIfAccessTokenCloseToExpiry();
31
- }
11
+ const oneTimeOperationFlag = process.env[InternalEnvironmentVariables.ONE_TIME_OPERATION_FLAG] === "true";
12
+ if (oneTimeOperationFlag)
13
+ return;
14
+ process.env[InternalEnvironmentVariables.ONE_TIME_OPERATION_FLAG] = "true";
15
+ if (options?.serviceAuthType === ServiceAuth.ACCESS_TOKEN) {
16
+ warnIfAccessTokenCloseToExpiry();
17
+ }
32
18
  };
19
+ /**
20
+ * @public
21
+ *
22
+ * Generate playwright configuration integrated with Azure Playwright.
23
+ *
24
+ * @param baseConfig - base playwright configuration
25
+ * @param options - additional options for the service
26
+ * @returns PlaywrightConfig
27
+ *
28
+ * @example
29
+ * ```
30
+ * import { defineConfig } from "playwright/test";
31
+ * import { createAzurePlaywrightConfig } from "@azure/playwright";
32
+ * import playwrightConfig from "./playwright.config";
33
+ *
34
+ * export default defineConfig(playwrightConfig, createAzurePlaywrightConfig(playwrightConfig));
35
+ * ```
36
+ *
37
+ * @example
38
+ * ```
39
+ * import { defineConfig } from "playwright/test";
40
+ * import { createAzurePlaywrightConfig, ServiceOS, ServiceAuth } from "@azure/playwright";
41
+ * import playwrightConfig from "./playwright.config";
42
+ * import { DefaultAzureCredential } from '@azure/identity';
43
+ *
44
+ * export default defineConfig(playwrightConfig, createAzurePlaywrightConfig(playwrightConfig, {
45
+ * credential: new DefaultAzureCredential(),
46
+ * serviceAuthType: ServiceAuth.ENTRA_ID,
47
+ * os: ServiceOS.WINDOWS
48
+ * }));
49
+ * ```
50
+ */
33
51
  const createAzurePlaywrightConfig = (baseConfig, options) => {
34
- validatePlaywrightVersion();
35
- validateServiceUrl();
36
- process.env[InternalEnvironmentVariables.USING_SERVICE_CONFIG] = "true";
37
- const playwrightVersionInfo = getVersionInfo(getPlaywrightVersion());
38
- const isMultipleGlobalFileSupported = playwrightVersionInfo.major >= 1 && playwrightVersionInfo.minor >= 49;
39
- if (options?.credential) {
40
- playwrightServiceEntra.entraIdAccessToken = options.credential;
41
- }
42
- if (baseConfig && baseConfig.globalSetup) {
43
- if (typeof baseConfig.globalSetup === "string") {
44
- if (isMultipleGlobalFileSupported) {
45
- customerConfig.globalSetup = [baseConfig.globalSetup];
46
- } else {
47
- customerConfig.globalSetup = baseConfig.globalSetup;
48
- }
49
- } else {
50
- if (!isMultipleGlobalFileSupported) {
51
- throw new Error(
52
- ServiceErrorMessageConstants.MULTIPLE_SETUP_FILE_PLAYWRIGHT_VERSION_ERROR.message
53
- );
54
- }
55
- customerConfig.globalSetup = baseConfig.globalSetup;
52
+ validatePlaywrightVersion();
53
+ validateServiceUrl();
54
+ // Set environment variable to indicate user is using service config
55
+ process.env[InternalEnvironmentVariables.USING_SERVICE_CONFIG] = "true";
56
+ const playwrightVersionInfo = getVersionInfo(getPlaywrightVersion());
57
+ const isMultipleGlobalFileSupported = playwrightVersionInfo.major >= 1 && playwrightVersionInfo.minor >= 49;
58
+ if (options?.credential) {
59
+ playwrightServiceEntra.entraIdAccessToken = options.credential;
60
+ }
61
+ // if global setup/teardown is string -
62
+ // 1. if multiple global file is supported, convert it to array
63
+ // 2. wrap playwright-service global setup/teardown with customer provided global setup/teardown
64
+ // if global setup/teardown is array -
65
+ // 1. if multiple global file is not supported, throw error
66
+ // 2. append playwright-service global setup/teardown with customer provided global setup/teardown
67
+ if (baseConfig && baseConfig.globalSetup) {
68
+ if (typeof baseConfig.globalSetup === "string") {
69
+ if (isMultipleGlobalFileSupported) {
70
+ customerConfig.globalSetup = [baseConfig.globalSetup];
71
+ }
72
+ else {
73
+ customerConfig.globalSetup = baseConfig.globalSetup;
74
+ }
75
+ }
76
+ else {
77
+ if (!isMultipleGlobalFileSupported) {
78
+ throw new Error(ServiceErrorMessageConstants.MULTIPLE_SETUP_FILE_PLAYWRIGHT_VERSION_ERROR.message);
79
+ }
80
+ customerConfig.globalSetup = baseConfig.globalSetup;
81
+ }
82
+ }
83
+ if (baseConfig && baseConfig.globalTeardown) {
84
+ if (typeof baseConfig.globalTeardown === "string") {
85
+ if (isMultipleGlobalFileSupported) {
86
+ customerConfig.globalTeardown = [baseConfig.globalTeardown];
87
+ }
88
+ else {
89
+ customerConfig.globalTeardown = baseConfig.globalTeardown;
90
+ }
91
+ }
92
+ else {
93
+ if (!isMultipleGlobalFileSupported) {
94
+ throw new Error(ServiceErrorMessageConstants.MULTIPLE_SETUP_FILE_PLAYWRIGHT_VERSION_ERROR.message);
95
+ }
96
+ customerConfig.globalTeardown = baseConfig.globalTeardown;
97
+ }
98
+ }
99
+ const playwrightServiceConfig = PlaywrightServiceConfig.instance;
100
+ playwrightServiceConfig.setOptions(options);
101
+ playwrightServiceConfig.serviceAuthType =
102
+ options?.serviceAuthType || DefaultConnectOptionsConstants.DEFAULT_SERVICE_AUTH_TYPE;
103
+ const globalFunctions = {};
104
+ if (options?.serviceAuthType === ServiceAuth.ACCESS_TOKEN) {
105
+ // mpt PAT requested and set by the customer, no need to setup entra lifecycle handlers
106
+ validateMptPAT(exitWithFailureMessage);
56
107
  }
57
- }
58
- if (baseConfig && baseConfig.globalTeardown) {
59
- if (typeof baseConfig.globalTeardown === "string") {
60
- if (isMultipleGlobalFileSupported) {
61
- customerConfig.globalTeardown = [baseConfig.globalTeardown];
62
- } else {
63
- customerConfig.globalTeardown = baseConfig.globalTeardown;
64
- }
65
- } else {
66
- if (!isMultipleGlobalFileSupported) {
67
- throw new Error(
68
- ServiceErrorMessageConstants.MULTIPLE_SETUP_FILE_PLAYWRIGHT_VERSION_ERROR.message
69
- );
70
- }
71
- customerConfig.globalTeardown = baseConfig.globalTeardown;
108
+ // If multiple global file is supported, append playwright-service global setup/teardown with customer provided global setup/teardown
109
+ if (isMultipleGlobalFileSupported) {
110
+ globalFunctions.globalSetup = [];
111
+ globalFunctions.globalTeardown = [];
112
+ if (customerConfig.globalSetup) {
113
+ globalFunctions.globalSetup.push(...customerConfig.globalSetup);
114
+ }
115
+ if (customerConfig.globalTeardown) {
116
+ globalFunctions.globalTeardown.push(...customerConfig.globalTeardown);
117
+ }
118
+ globalFunctions.globalSetup.push(globalPaths.setup);
119
+ globalFunctions.globalTeardown.push(globalPaths.teardown);
72
120
  }
73
- }
74
- const playwrightServiceConfig = PlaywrightServiceConfig.instance;
75
- playwrightServiceConfig.setOptions(options);
76
- playwrightServiceConfig.serviceAuthType = options?.serviceAuthType || DefaultConnectOptionsConstants.DEFAULT_SERVICE_AUTH_TYPE;
77
- const globalFunctions = {};
78
- if (options?.serviceAuthType === ServiceAuth.ACCESS_TOKEN) {
79
- validateMptPAT(exitWithFailureMessage);
80
- }
81
- if (isMultipleGlobalFileSupported) {
82
- globalFunctions.globalSetup = [];
83
- globalFunctions.globalTeardown = [];
84
- if (customerConfig.globalSetup) {
85
- globalFunctions.globalSetup.push(...customerConfig.globalSetup);
121
+ else {
122
+ // If multiple global file is not supported, wrap playwright-service global setup/teardown with customer provided global setup/teardown
123
+ globalFunctions.globalSetup = globalPaths.setup;
124
+ globalFunctions.globalTeardown = globalPaths.teardown;
86
125
  }
87
- if (customerConfig.globalTeardown) {
88
- globalFunctions.globalTeardown.push(...customerConfig.globalTeardown);
126
+ performOneTimeOperation(options);
127
+ if (options?.useCloudHostedBrowsers === false) {
128
+ console.log("\nRunning tests using local browsers.");
129
+ return {
130
+ ...globalFunctions,
131
+ };
132
+ }
133
+ if (!process.env[InternalEnvironmentVariables.MPT_CLOUD_HOSTED_BROWSER_USED]) {
134
+ process.env[InternalEnvironmentVariables.MPT_CLOUD_HOSTED_BROWSER_USED] = "true";
135
+ console.log("\nRunning tests using Playwright workspaces.");
89
136
  }
90
- globalFunctions.globalSetup.push(globalPaths.setup);
91
- globalFunctions.globalTeardown.push(globalPaths.teardown);
92
- } else {
93
- globalFunctions.globalSetup = globalPaths.setup;
94
- globalFunctions.globalTeardown = globalPaths.teardown;
95
- }
96
- performOneTimeOperation(options);
97
- if (options?.useCloudHostedBrowsers === false) {
98
- console.log("\nRunning tests using local browsers.");
99
137
  return {
100
- ...globalFunctions
101
- };
102
- }
103
- if (!process.env[InternalEnvironmentVariables.MPT_CLOUD_HOSTED_BROWSER_USED]) {
104
- process.env[InternalEnvironmentVariables.MPT_CLOUD_HOSTED_BROWSER_USED] = "true";
105
- console.log("\nRunning tests using Playwright workspaces.");
106
- }
107
- return {
108
- use: {
109
- connectOptions: {
110
- wsEndpoint: getServiceWSEndpoint(
111
- playwrightServiceConfig.runId,
112
- playwrightServiceConfig.serviceOs,
113
- playwrightServiceConfig.apiVersion
114
- ),
115
- headers: {
116
- Authorization: `Bearer ${getAccessToken()}`,
117
- "x-ms-package-version": `@azure/playwright/${getPackageVersion()}`
138
+ use: {
139
+ connectOptions: {
140
+ wsEndpoint: getServiceWSEndpoint(playwrightServiceConfig.runId, playwrightServiceConfig.serviceOs, playwrightServiceConfig.apiVersion),
141
+ headers: {
142
+ Authorization: `Bearer ${getAccessToken()}`,
143
+ "x-ms-package-version": `@azure/playwright/${getPackageVersion()}`,
144
+ },
145
+ timeout: playwrightServiceConfig.connectTimeout,
146
+ exposeNetwork: playwrightServiceConfig.exposeNetwork,
147
+ slowMo: playwrightServiceConfig.slowMo,
148
+ },
118
149
  },
119
- timeout: playwrightServiceConfig.connectTimeout,
120
- exposeNetwork: playwrightServiceConfig.exposeNetwork,
121
- slowMo: playwrightServiceConfig.slowMo
122
- }
123
- },
124
- ...globalFunctions
125
- };
150
+ ...globalFunctions,
151
+ };
126
152
  };
153
+ /**
154
+ * @public
155
+ *
156
+ * Get connect options required to connect to Azure Playwright's cloud hosted browsers.
157
+ *
158
+ * @param options - additional options for the service
159
+ * @returns BrowserConnectOptions
160
+ *
161
+ * @example
162
+ * ```
163
+ * import playwright, { test, expect, BrowserType } from "@playwright/test";
164
+ * import { getConnectOptions } from "@azure/playwright";
165
+ *
166
+ * test('has title', async ({ browserName }) => {
167
+ * const { wsEndpoint, options } = await getConnectOptions();
168
+ * const browser = await (playwright[browserName] as BrowserType).connect(wsEndpoint, options);
169
+ * const context = await browser.newContext();
170
+ * const page = await context.newPage();
171
+ *
172
+ * await page.goto('https://playwright.dev/');
173
+ * await expect(page).toHaveTitle(/Playwright/);
174
+ *
175
+ * await page.close();
176
+ * await context.close();
177
+ * await browser.close();
178
+ * });
179
+ * ```
180
+ */
127
181
  const getConnectOptions = async (options) => {
128
- const playwrightServiceConfig = PlaywrightServiceConfig.instance;
129
- playwrightServiceConfig.setOptions(options, true);
130
- performOneTimeOperation(options);
131
- playwrightServiceConfig.serviceAuthType = options?.serviceAuthType || DefaultConnectOptionsConstants.DEFAULT_SERVICE_AUTH_TYPE;
132
- let token;
133
- if (playwrightServiceConfig.serviceAuthType === ServiceAuth.ENTRA_ID) {
134
- if (!options?.credential) {
135
- throw new Error(ServiceErrorMessageConstants.NO_CRED_ENTRA_AUTH_ERROR.message);
182
+ const playwrightServiceConfig = PlaywrightServiceConfig.instance;
183
+ playwrightServiceConfig.setOptions(options, true);
184
+ performOneTimeOperation(options);
185
+ playwrightServiceConfig.serviceAuthType =
186
+ options?.serviceAuthType || DefaultConnectOptionsConstants.DEFAULT_SERVICE_AUTH_TYPE;
187
+ let token;
188
+ if (playwrightServiceConfig.serviceAuthType === ServiceAuth.ENTRA_ID) {
189
+ if (!options?.credential) {
190
+ throw new Error(ServiceErrorMessageConstants.NO_CRED_ENTRA_AUTH_ERROR.message);
191
+ }
192
+ playwrightServiceEntra.entraIdAccessToken = options.credential;
193
+ token = await fetchOrValidateAccessToken(options.credential);
136
194
  }
137
- playwrightServiceEntra.entraIdAccessToken = options.credential;
138
- token = await fetchOrValidateAccessToken(options.credential);
139
- } else if (playwrightServiceConfig.serviceAuthType === ServiceAuth.ACCESS_TOKEN) {
140
- validateMptPAT(throwErrorWithFailureMessage);
141
- token = getAccessToken();
142
- } else {
143
- throw new Error(ServiceErrorMessageConstants.INVALID_AUTH_TYPE_ERROR.message);
144
- }
145
- if (!token) {
146
- throw new Error(ServiceErrorMessageConstants.NO_AUTH_ERROR_PAT_TOKEN.message);
147
- }
148
- return {
149
- wsEndpoint: getServiceWSEndpoint(
150
- playwrightServiceConfig.runId,
151
- playwrightServiceConfig.serviceOs,
152
- playwrightServiceConfig.apiVersion
153
- ),
154
- options: {
155
- headers: {
156
- Authorization: `Bearer ${token}`,
157
- "x-ms-package-version": `@azure/playwright/${getPackageVersion()}`
158
- },
159
- timeout: playwrightServiceConfig.connectTimeout,
160
- exposeNetwork: playwrightServiceConfig.exposeNetwork,
161
- slowMo: playwrightServiceConfig.slowMo
195
+ else if (playwrightServiceConfig.serviceAuthType === ServiceAuth.ACCESS_TOKEN) {
196
+ validateMptPAT(throwErrorWithFailureMessage);
197
+ token = getAccessToken();
162
198
  }
163
- };
164
- };
165
- export {
166
- createAzurePlaywrightConfig,
167
- getConnectOptions
199
+ else {
200
+ throw new Error(ServiceErrorMessageConstants.INVALID_AUTH_TYPE_ERROR.message);
201
+ }
202
+ if (!token) {
203
+ throw new Error(ServiceErrorMessageConstants.NO_AUTH_ERROR_PAT_TOKEN.message);
204
+ }
205
+ return {
206
+ wsEndpoint: getServiceWSEndpoint(playwrightServiceConfig.runId, playwrightServiceConfig.serviceOs, playwrightServiceConfig.apiVersion),
207
+ options: {
208
+ headers: {
209
+ Authorization: `Bearer ${token}`,
210
+ "x-ms-package-version": `@azure/playwright/${getPackageVersion()}`,
211
+ },
212
+ timeout: playwrightServiceConfig.connectTimeout,
213
+ exposeNetwork: playwrightServiceConfig.exposeNetwork,
214
+ slowMo: playwrightServiceConfig.slowMo,
215
+ },
216
+ };
168
217
  };
218
+ export { createAzurePlaywrightConfig, getConnectOptions };
219
+ //# sourceMappingURL=playwrightService.js.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["/mnt/vss/_work/1/s/sdk/loadtesting/playwright/src/core/playwrightService.ts"],
4
- "sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport {\n DefaultConnectOptionsConstants,\n InternalEnvironmentVariables,\n ServiceAuth,\n} from \"../common/constants.js\";\nimport customerConfig from \"../common/customerConfig.js\";\nimport { PlaywrightServiceConfig } from \"../common/playwrightServiceConfig.js\";\nimport playwrightServiceEntra from \"./playwrightServiceEntra.js\";\nimport type { PlaywrightServiceAdditionalOptions, BrowserConnectOptions } from \"../common/types.js\";\nimport {\n fetchOrValidateAccessToken,\n getAccessToken,\n getServiceWSEndpoint,\n validateMptPAT,\n validatePlaywrightVersion,\n validateServiceUrl,\n exitWithFailureMessage,\n getPlaywrightVersion,\n getVersionInfo,\n throwErrorWithFailureMessage,\n getPackageVersion,\n warnIfAccessTokenCloseToExpiry,\n} from \"../utils/utils.js\";\nimport { ServiceErrorMessageConstants } from \"../common/messages.js\";\nimport type { PlaywrightTestConfig } from \"@playwright/test\";\nimport { globalPaths } from \"./playwrightServiceUtils.js\";\n\nconst performOneTimeOperation = (options?: PlaywrightServiceAdditionalOptions): void => {\n const oneTimeOperationFlag =\n process.env[InternalEnvironmentVariables.ONE_TIME_OPERATION_FLAG] === \"true\";\n if (oneTimeOperationFlag) return;\n process.env[InternalEnvironmentVariables.ONE_TIME_OPERATION_FLAG] = \"true\";\n if (options?.serviceAuthType === ServiceAuth.ACCESS_TOKEN) {\n warnIfAccessTokenCloseToExpiry();\n }\n};\n\n/**\n * @public\n *\n * Generate playwright configuration integrated with Azure Playwright.\n *\n * @param baseConfig - 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 { createAzurePlaywrightConfig } from \"@azure/playwright\";\n * import playwrightConfig from \"./playwright.config\";\n *\n * export default defineConfig(playwrightConfig, createAzurePlaywrightConfig(playwrightConfig));\n * ```\n *\n * @example\n * ```\n * import { defineConfig } from \"playwright/test\";\n * import { createAzurePlaywrightConfig, ServiceOS, ServiceAuth } from \"@azure/playwright\";\n * import playwrightConfig from \"./playwright.config\";\n * import { DefaultAzureCredential } from '@azure/identity';\n *\n * export default defineConfig(playwrightConfig, createAzurePlaywrightConfig(playwrightConfig, {\n * credential: new DefaultAzureCredential(),\n * serviceAuthType: ServiceAuth.ENTRA_ID,\n * os: ServiceOS.WINDOWS\n * }));\n * ```\n */\nconst createAzurePlaywrightConfig = (\n baseConfig: PlaywrightTestConfig,\n options?: PlaywrightServiceAdditionalOptions,\n): PlaywrightTestConfig => {\n validatePlaywrightVersion();\n validateServiceUrl();\n\n // Set environment variable to indicate user is using service config\n process.env[InternalEnvironmentVariables.USING_SERVICE_CONFIG] = \"true\";\n const playwrightVersionInfo = getVersionInfo(getPlaywrightVersion());\n const isMultipleGlobalFileSupported =\n playwrightVersionInfo.major >= 1 && playwrightVersionInfo.minor >= 49;\n if (options?.credential) {\n playwrightServiceEntra.entraIdAccessToken = options.credential;\n }\n\n // if global setup/teardown is string -\n // 1. if multiple global file is supported, convert it to array\n // 2. wrap playwright-service global setup/teardown with customer provided global setup/teardown\n\n // if global setup/teardown is array -\n // 1. if multiple global file is not supported, throw error\n // 2. append playwright-service global setup/teardown with customer provided global setup/teardown\n if (baseConfig && baseConfig.globalSetup) {\n if (typeof baseConfig.globalSetup === \"string\") {\n if (isMultipleGlobalFileSupported) {\n customerConfig.globalSetup = [baseConfig.globalSetup];\n } else {\n customerConfig.globalSetup = baseConfig.globalSetup;\n }\n } else {\n if (!isMultipleGlobalFileSupported) {\n throw new Error(\n ServiceErrorMessageConstants.MULTIPLE_SETUP_FILE_PLAYWRIGHT_VERSION_ERROR.message,\n );\n }\n customerConfig.globalSetup = baseConfig.globalSetup;\n }\n }\n\n if (baseConfig && baseConfig.globalTeardown) {\n if (typeof baseConfig.globalTeardown === \"string\") {\n if (isMultipleGlobalFileSupported) {\n customerConfig.globalTeardown = [baseConfig.globalTeardown];\n } else {\n customerConfig.globalTeardown = baseConfig.globalTeardown;\n }\n } else {\n if (!isMultipleGlobalFileSupported) {\n throw new Error(\n ServiceErrorMessageConstants.MULTIPLE_SETUP_FILE_PLAYWRIGHT_VERSION_ERROR.message,\n );\n }\n customerConfig.globalTeardown = baseConfig.globalTeardown;\n }\n }\n\n const playwrightServiceConfig = PlaywrightServiceConfig.instance;\n playwrightServiceConfig.setOptions(options);\n playwrightServiceConfig.serviceAuthType =\n options?.serviceAuthType || DefaultConnectOptionsConstants.DEFAULT_SERVICE_AUTH_TYPE;\n\n const globalFunctions: any = {};\n\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(exitWithFailureMessage);\n }\n // If multiple global file is supported, append playwright-service global setup/teardown with customer provided global setup/teardown\n if (isMultipleGlobalFileSupported) {\n globalFunctions.globalSetup = [] as string[];\n globalFunctions.globalTeardown = [] as string[];\n if (customerConfig.globalSetup) {\n globalFunctions.globalSetup.push(...(customerConfig.globalSetup as string[]));\n }\n if (customerConfig.globalTeardown) {\n globalFunctions.globalTeardown.push(...(customerConfig.globalTeardown as string[]));\n }\n globalFunctions.globalSetup.push(globalPaths.setup);\n globalFunctions.globalTeardown.push(globalPaths.teardown);\n } else {\n // If multiple global file is not supported, wrap playwright-service global setup/teardown with customer provided global setup/teardown\n globalFunctions.globalSetup = globalPaths.setup;\n globalFunctions.globalTeardown = globalPaths.teardown;\n }\n performOneTimeOperation(options);\n if (options?.useCloudHostedBrowsers === false) {\n console.log(\"\\nRunning tests using local browsers.\");\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 Playwright workspaces.\");\n }\n\n return {\n use: {\n connectOptions: {\n wsEndpoint: getServiceWSEndpoint(\n playwrightServiceConfig.runId,\n playwrightServiceConfig.serviceOs,\n playwrightServiceConfig.apiVersion,\n ),\n headers: {\n Authorization: `Bearer ${getAccessToken()}`,\n \"x-ms-package-version\": `@azure/playwright/${getPackageVersion()}`,\n },\n timeout: playwrightServiceConfig.connectTimeout,\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 Azure Playwright'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/playwright\";\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?: PlaywrightServiceAdditionalOptions,\n): Promise<BrowserConnectOptions> => {\n const playwrightServiceConfig = PlaywrightServiceConfig.instance;\n\n playwrightServiceConfig.setOptions(options, true);\n performOneTimeOperation(options);\n playwrightServiceConfig.serviceAuthType =\n options?.serviceAuthType || DefaultConnectOptionsConstants.DEFAULT_SERVICE_AUTH_TYPE;\n\n let token: string | undefined;\n if (playwrightServiceConfig.serviceAuthType === ServiceAuth.ENTRA_ID) {\n if (!options?.credential) {\n throw new Error(ServiceErrorMessageConstants.NO_CRED_ENTRA_AUTH_ERROR.message);\n }\n playwrightServiceEntra.entraIdAccessToken = options.credential;\n token = await fetchOrValidateAccessToken(options.credential);\n } else if (playwrightServiceConfig.serviceAuthType === ServiceAuth.ACCESS_TOKEN) {\n validateMptPAT(throwErrorWithFailureMessage);\n token = getAccessToken();\n } else {\n throw new Error(ServiceErrorMessageConstants.INVALID_AUTH_TYPE_ERROR.message);\n }\n\n if (!token) {\n throw new Error(ServiceErrorMessageConstants.NO_AUTH_ERROR_PAT_TOKEN.message);\n }\n\n return {\n wsEndpoint: getServiceWSEndpoint(\n playwrightServiceConfig.runId,\n playwrightServiceConfig.serviceOs,\n playwrightServiceConfig.apiVersion,\n ),\n options: {\n headers: {\n Authorization: `Bearer ${token}`,\n \"x-ms-package-version\": `@azure/playwright/${getPackageVersion()}`,\n },\n timeout: playwrightServiceConfig.connectTimeout,\n exposeNetwork: playwrightServiceConfig.exposeNetwork,\n slowMo: playwrightServiceConfig.slowMo,\n },\n };\n};\n\nexport { createAzurePlaywrightConfig, getConnectOptions };\n"],
5
- "mappings": "AAGA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,OAAO,oBAAoB;AAC3B,SAAS,+BAA+B;AACxC,OAAO,4BAA4B;AAEnC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,oCAAoC;AAE7C,SAAS,mBAAmB;AAE5B,MAAM,0BAA0B,CAAC,YAAu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QAAM,0BAA0B,wBAAwB;AAExD,0BAAwB,WAAW,SAAS,IAAI;AAChD,0BAAwB,OAAO;AAC/B,0BAAwB,kBACtB,SAAS,mBAAmB,+BAA+B;AAE7D,MAAI;AACJ,MAAI,wBAAwB,oBAAoB,YAAY,UAAU;AACpE,QAAI,CAAC,SAAS,YAAY;AACxB,YAAM,IAAI,MAAM,6BAA6B,yBAAyB,OAAO;AAAA,IAC/E;AACA,2BAAuB,qBAAqB,QAAQ;AACpD,YAAQ,MAAM,2BAA2B,QAAQ,UAAU;AAAA,EAC7D,WAAW,wBAAwB,oBAAoB,YAAY,cAAc;AAC/E,mBAAe,4BAA4B;AAC3C,YAAQ,eAAe;AAAA,EACzB,OAAO;AACL,UAAM,IAAI,MAAM,6BAA6B,wBAAwB,OAAO;AAAA,EAC9E;AAEA,MAAI,CAAC,OAAO;AACV,UAAM,IAAI,MAAM,6BAA6B,wBAAwB,OAAO;AAAA,EAC9E;AAEA,SAAO;AAAA,IACL,YAAY;AAAA,MACV,wBAAwB;AAAA,MACxB,wBAAwB;AAAA,MACxB,wBAAwB;AAAA,IAC1B;AAAA,IACA,SAAS;AAAA,MACP,SAAS;AAAA,QACP,eAAe,UAAU,KAAK;AAAA,QAC9B,wBAAwB,qBAAqB,kBAAkB,CAAC;AAAA,MAClE;AAAA,MACA,SAAS,wBAAwB;AAAA,MACjC,eAAe,wBAAwB;AAAA,MACvC,QAAQ,wBAAwB;AAAA,IAClC;AAAA,EACF;AACF;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"playwrightService.js","sourceRoot":"","sources":["../../../src/core/playwrightService.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EACL,8BAA8B,EAC9B,4BAA4B,EAC5B,WAAW,GACZ,MAAM,wBAAwB,CAAC;AAChC,OAAO,cAAc,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAC;AAC/E,OAAO,sBAAsB,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CAAC;QACD,sBAAsB,CAAC,kBAAkB,GAAG,OAAO,CAAC,UAAU,CAAC;QAC/D,KAAK,GAAG,MAAM,0BAA0B,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAC/D,CAAC;SAAM,IAAI,uBAAuB,CAAC,eAAe,KAAK,WAAW,CAAC,YAAY,EAAE,CAAC;QAChF,cAAc,CAAC,4BAA4B,CAAC,CAAC;QAC7C,KAAK,GAAG,cAAc,EAAE,CAAC;IAC3B,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,uBAAuB,CAAC,OAAO,CAAC,CAAC;IAChF,CAAC;IAED,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,uBAAuB,CAAC,OAAO,CAAC,CAAC;IAChF,CAAC;IAED,OAAO;QACL,UAAU,EAAE,oBAAoB,CAC9B,uBAAuB,CAAC,KAAK,EAC7B,uBAAuB,CAAC,SAAS,EACjC,uBAAuB,CAAC,UAAU,CACnC;QACD,OAAO,EAAE;YACP,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,KAAK,EAAE;gBAChC,sBAAsB,EAAE,qBAAqB,iBAAiB,EAAE,EAAE;aACnE;YACD,OAAO,EAAE,uBAAuB,CAAC,cAAc;YAC/C,aAAa,EAAE,uBAAuB,CAAC,aAAa;YACpD,MAAM,EAAE,uBAAuB,CAAC,MAAM;SACvC;KACF,CAAC;AACJ,CAAC,CAAC;AAEF,OAAO,EAAE,2BAA2B,EAAE,iBAAiB,EAAE,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport {\n DefaultConnectOptionsConstants,\n InternalEnvironmentVariables,\n ServiceAuth,\n} from \"../common/constants.js\";\nimport customerConfig from \"../common/customerConfig.js\";\nimport { PlaywrightServiceConfig } from \"../common/playwrightServiceConfig.js\";\nimport playwrightServiceEntra from \"./playwrightServiceEntra.js\";\nimport type { PlaywrightServiceAdditionalOptions, BrowserConnectOptions } from \"../common/types.js\";\nimport {\n fetchOrValidateAccessToken,\n getAccessToken,\n getServiceWSEndpoint,\n validateMptPAT,\n validatePlaywrightVersion,\n validateServiceUrl,\n exitWithFailureMessage,\n getPlaywrightVersion,\n getVersionInfo,\n throwErrorWithFailureMessage,\n getPackageVersion,\n warnIfAccessTokenCloseToExpiry,\n} from \"../utils/utils.js\";\nimport { ServiceErrorMessageConstants } from \"../common/messages.js\";\nimport type { PlaywrightTestConfig } from \"@playwright/test\";\nimport { globalPaths } from \"./playwrightServiceUtils.js\";\n\nconst performOneTimeOperation = (options?: PlaywrightServiceAdditionalOptions): void => {\n const oneTimeOperationFlag =\n process.env[InternalEnvironmentVariables.ONE_TIME_OPERATION_FLAG] === \"true\";\n if (oneTimeOperationFlag) return;\n process.env[InternalEnvironmentVariables.ONE_TIME_OPERATION_FLAG] = \"true\";\n if (options?.serviceAuthType === ServiceAuth.ACCESS_TOKEN) {\n warnIfAccessTokenCloseToExpiry();\n }\n};\n\n/**\n * @public\n *\n * Generate playwright configuration integrated with Azure Playwright.\n *\n * @param baseConfig - 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 { createAzurePlaywrightConfig } from \"@azure/playwright\";\n * import playwrightConfig from \"./playwright.config\";\n *\n * export default defineConfig(playwrightConfig, createAzurePlaywrightConfig(playwrightConfig));\n * ```\n *\n * @example\n * ```\n * import { defineConfig } from \"playwright/test\";\n * import { createAzurePlaywrightConfig, ServiceOS, ServiceAuth } from \"@azure/playwright\";\n * import playwrightConfig from \"./playwright.config\";\n * import { DefaultAzureCredential } from '@azure/identity';\n *\n * export default defineConfig(playwrightConfig, createAzurePlaywrightConfig(playwrightConfig, {\n * credential: new DefaultAzureCredential(),\n * serviceAuthType: ServiceAuth.ENTRA_ID,\n * os: ServiceOS.WINDOWS\n * }));\n * ```\n */\nconst createAzurePlaywrightConfig = (\n baseConfig: PlaywrightTestConfig,\n options?: PlaywrightServiceAdditionalOptions,\n): PlaywrightTestConfig => {\n validatePlaywrightVersion();\n validateServiceUrl();\n\n // Set environment variable to indicate user is using service config\n process.env[InternalEnvironmentVariables.USING_SERVICE_CONFIG] = \"true\";\n const playwrightVersionInfo = getVersionInfo(getPlaywrightVersion());\n const isMultipleGlobalFileSupported =\n playwrightVersionInfo.major >= 1 && playwrightVersionInfo.minor >= 49;\n if (options?.credential) {\n playwrightServiceEntra.entraIdAccessToken = options.credential;\n }\n\n // if global setup/teardown is string -\n // 1. if multiple global file is supported, convert it to array\n // 2. wrap playwright-service global setup/teardown with customer provided global setup/teardown\n\n // if global setup/teardown is array -\n // 1. if multiple global file is not supported, throw error\n // 2. append playwright-service global setup/teardown with customer provided global setup/teardown\n if (baseConfig && baseConfig.globalSetup) {\n if (typeof baseConfig.globalSetup === \"string\") {\n if (isMultipleGlobalFileSupported) {\n customerConfig.globalSetup = [baseConfig.globalSetup];\n } else {\n customerConfig.globalSetup = baseConfig.globalSetup;\n }\n } else {\n if (!isMultipleGlobalFileSupported) {\n throw new Error(\n ServiceErrorMessageConstants.MULTIPLE_SETUP_FILE_PLAYWRIGHT_VERSION_ERROR.message,\n );\n }\n customerConfig.globalSetup = baseConfig.globalSetup;\n }\n }\n\n if (baseConfig && baseConfig.globalTeardown) {\n if (typeof baseConfig.globalTeardown === \"string\") {\n if (isMultipleGlobalFileSupported) {\n customerConfig.globalTeardown = [baseConfig.globalTeardown];\n } else {\n customerConfig.globalTeardown = baseConfig.globalTeardown;\n }\n } else {\n if (!isMultipleGlobalFileSupported) {\n throw new Error(\n ServiceErrorMessageConstants.MULTIPLE_SETUP_FILE_PLAYWRIGHT_VERSION_ERROR.message,\n );\n }\n customerConfig.globalTeardown = baseConfig.globalTeardown;\n }\n }\n\n const playwrightServiceConfig = PlaywrightServiceConfig.instance;\n playwrightServiceConfig.setOptions(options);\n playwrightServiceConfig.serviceAuthType =\n options?.serviceAuthType || DefaultConnectOptionsConstants.DEFAULT_SERVICE_AUTH_TYPE;\n\n const globalFunctions: any = {};\n\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(exitWithFailureMessage);\n }\n // If multiple global file is supported, append playwright-service global setup/teardown with customer provided global setup/teardown\n if (isMultipleGlobalFileSupported) {\n globalFunctions.globalSetup = [] as string[];\n globalFunctions.globalTeardown = [] as string[];\n if (customerConfig.globalSetup) {\n globalFunctions.globalSetup.push(...(customerConfig.globalSetup as string[]));\n }\n if (customerConfig.globalTeardown) {\n globalFunctions.globalTeardown.push(...(customerConfig.globalTeardown as string[]));\n }\n globalFunctions.globalSetup.push(globalPaths.setup);\n globalFunctions.globalTeardown.push(globalPaths.teardown);\n } else {\n // If multiple global file is not supported, wrap playwright-service global setup/teardown with customer provided global setup/teardown\n globalFunctions.globalSetup = globalPaths.setup;\n globalFunctions.globalTeardown = globalPaths.teardown;\n }\n performOneTimeOperation(options);\n if (options?.useCloudHostedBrowsers === false) {\n console.log(\"\\nRunning tests using local browsers.\");\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 Playwright workspaces.\");\n }\n\n return {\n use: {\n connectOptions: {\n wsEndpoint: getServiceWSEndpoint(\n playwrightServiceConfig.runId,\n playwrightServiceConfig.serviceOs,\n playwrightServiceConfig.apiVersion,\n ),\n headers: {\n Authorization: `Bearer ${getAccessToken()}`,\n \"x-ms-package-version\": `@azure/playwright/${getPackageVersion()}`,\n },\n timeout: playwrightServiceConfig.connectTimeout,\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 Azure Playwright'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/playwright\";\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?: PlaywrightServiceAdditionalOptions,\n): Promise<BrowserConnectOptions> => {\n const playwrightServiceConfig = PlaywrightServiceConfig.instance;\n\n playwrightServiceConfig.setOptions(options, true);\n performOneTimeOperation(options);\n playwrightServiceConfig.serviceAuthType =\n options?.serviceAuthType || DefaultConnectOptionsConstants.DEFAULT_SERVICE_AUTH_TYPE;\n\n let token: string | undefined;\n if (playwrightServiceConfig.serviceAuthType === ServiceAuth.ENTRA_ID) {\n if (!options?.credential) {\n throw new Error(ServiceErrorMessageConstants.NO_CRED_ENTRA_AUTH_ERROR.message);\n }\n playwrightServiceEntra.entraIdAccessToken = options.credential;\n token = await fetchOrValidateAccessToken(options.credential);\n } else if (playwrightServiceConfig.serviceAuthType === ServiceAuth.ACCESS_TOKEN) {\n validateMptPAT(throwErrorWithFailureMessage);\n token = getAccessToken();\n } else {\n throw new Error(ServiceErrorMessageConstants.INVALID_AUTH_TYPE_ERROR.message);\n }\n\n if (!token) {\n throw new Error(ServiceErrorMessageConstants.NO_AUTH_ERROR_PAT_TOKEN.message);\n }\n\n return {\n wsEndpoint: getServiceWSEndpoint(\n playwrightServiceConfig.runId,\n playwrightServiceConfig.serviceOs,\n playwrightServiceConfig.apiVersion,\n ),\n options: {\n headers: {\n Authorization: `Bearer ${token}`,\n \"x-ms-package-version\": `@azure/playwright/${getPackageVersion()}`,\n },\n timeout: playwrightServiceConfig.connectTimeout,\n exposeNetwork: playwrightServiceConfig.exposeNetwork,\n slowMo: playwrightServiceConfig.slowMo,\n },\n };\n};\n\nexport { createAzurePlaywrightConfig, getConnectOptions };\n"]}
@@ -1,54 +1,52 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
1
3
  import { EntraIdAccessTokenConstants } from "../common/constants.js";
2
4
  import { coreLogger } from "../common/logger.js";
3
5
  import { EntraIdAccessToken } from "../common/entraIdAccessToken.js";
4
6
  import { state } from "../common/state.js";
5
7
  class PlaywrightServiceEntra {
6
- _entraIdAccessTokenRotationInterval;
7
- _entraIdAccessToken;
8
- static getInstance = () => {
9
- if (!state.playwrightServiceEntra) {
10
- state.playwrightServiceEntra = new PlaywrightServiceEntra();
8
+ _entraIdAccessTokenRotationInterval;
9
+ _entraIdAccessToken;
10
+ static getInstance = () => {
11
+ if (!state.playwrightServiceEntra) {
12
+ state.playwrightServiceEntra = new PlaywrightServiceEntra();
13
+ }
14
+ return state.playwrightServiceEntra;
15
+ };
16
+ set entraIdAccessToken(credential) {
17
+ this._entraIdAccessToken = new EntraIdAccessToken(credential);
11
18
  }
12
- return state.playwrightServiceEntra;
13
- };
14
- set entraIdAccessToken(credential) {
15
- this._entraIdAccessToken = new EntraIdAccessToken(credential);
16
- }
17
- constructor() {
18
- this._entraIdAccessToken = new EntraIdAccessToken();
19
- }
20
- globalSetup = async () => {
21
- coreLogger.info("Entra id access token setup start");
22
- await this._entraIdAccessToken.fetchEntraIdAccessToken();
23
- this.entraIdGlobalSetupRotationHandler();
24
- };
25
- globalTeardown = () => {
26
- coreLogger.info("Entra id access token teardown start");
27
- if (this._entraIdAccessTokenRotationInterval) {
28
- clearInterval(this._entraIdAccessTokenRotationInterval);
29
- coreLogger.info("Entra id access token rotation interval cleared");
19
+ constructor() {
20
+ this._entraIdAccessToken = new EntraIdAccessToken();
30
21
  }
31
- };
32
- entraIdGlobalSetupRotationHandler = () => {
33
- this._entraIdAccessTokenRotationInterval = setInterval(
34
- this.entraIdAccessTokenRotation,
35
- EntraIdAccessTokenConstants.ROTATION_INTERVAL_PERIOD_IN_MINUTES * 60 * 1e3
36
- );
37
- coreLogger.info("Entra id access token rotation handler setup done");
38
- };
39
- entraIdAccessTokenRotation = async () => {
40
- coreLogger.info("Entra id access token rotation handler");
41
- try {
42
- if (this._entraIdAccessToken.doesEntraIdAccessTokenNeedRotation()) {
22
+ globalSetup = async () => {
23
+ coreLogger.info("Entra id access token setup start");
43
24
  await this._entraIdAccessToken.fetchEntraIdAccessToken();
44
- }
45
- } catch (err) {
46
- coreLogger.error(err);
47
- }
48
- };
25
+ this.entraIdGlobalSetupRotationHandler();
26
+ };
27
+ globalTeardown = () => {
28
+ coreLogger.info("Entra id access token teardown start");
29
+ if (this._entraIdAccessTokenRotationInterval) {
30
+ clearInterval(this._entraIdAccessTokenRotationInterval);
31
+ coreLogger.info("Entra id access token rotation interval cleared");
32
+ }
33
+ };
34
+ entraIdGlobalSetupRotationHandler = () => {
35
+ this._entraIdAccessTokenRotationInterval = setInterval(this.entraIdAccessTokenRotation, EntraIdAccessTokenConstants.ROTATION_INTERVAL_PERIOD_IN_MINUTES * 60 * 1000);
36
+ coreLogger.info("Entra id access token rotation handler setup done");
37
+ };
38
+ entraIdAccessTokenRotation = async () => {
39
+ coreLogger.info("Entra id access token rotation handler");
40
+ try {
41
+ if (this._entraIdAccessToken.doesEntraIdAccessTokenNeedRotation()) {
42
+ await this._entraIdAccessToken.fetchEntraIdAccessToken();
43
+ }
44
+ }
45
+ catch (err) {
46
+ coreLogger.error(err); // log error and continue if it's an intermittent issue (optimistic approach)
47
+ }
48
+ };
49
49
  }
50
50
  const instance = PlaywrightServiceEntra.getInstance();
51
- var playwrightServiceEntra_default = instance;
52
- export {
53
- playwrightServiceEntra_default as default
54
- };
51
+ export default instance;
52
+ //# sourceMappingURL=playwrightServiceEntra.js.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["/mnt/vss/_work/1/s/sdk/loadtesting/playwright/src/core/playwrightServiceEntra.ts"],
4
- "sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { EntraIdAccessTokenConstants } from \"../common/constants.js\";\nimport { coreLogger } from \"../common/logger.js\";\nimport { EntraIdAccessToken } from \"../common/entraIdAccessToken.js\";\nimport { state } from \"../common/state.js\";\nimport type { TokenCredential } from \"@azure/identity\";\n\nclass PlaywrightServiceEntra {\n private _entraIdAccessTokenRotationInterval?: NodeJS.Timeout;\n private _entraIdAccessToken: EntraIdAccessToken;\n\n static getInstance = (): PlaywrightServiceEntra => {\n if (!state.playwrightServiceEntra) {\n state.playwrightServiceEntra = new PlaywrightServiceEntra();\n }\n return state.playwrightServiceEntra;\n };\n\n set entraIdAccessToken(credential: TokenCredential) {\n this._entraIdAccessToken = new EntraIdAccessToken(credential);\n }\n\n constructor() {\n this._entraIdAccessToken = new EntraIdAccessToken();\n }\n\n public globalSetup = async (): Promise<void> => {\n coreLogger.info(\"Entra id access token setup start\");\n await this._entraIdAccessToken.fetchEntraIdAccessToken();\n this.entraIdGlobalSetupRotationHandler();\n };\n\n public globalTeardown = (): void => {\n coreLogger.info(\"Entra id access token teardown start\");\n if (this._entraIdAccessTokenRotationInterval) {\n clearInterval(this._entraIdAccessTokenRotationInterval);\n coreLogger.info(\"Entra id access token rotation interval cleared\");\n }\n };\n\n private entraIdGlobalSetupRotationHandler = (): void => {\n this._entraIdAccessTokenRotationInterval = setInterval(\n this.entraIdAccessTokenRotation,\n EntraIdAccessTokenConstants.ROTATION_INTERVAL_PERIOD_IN_MINUTES * 60 * 1000,\n );\n coreLogger.info(\"Entra id access token rotation handler setup done\");\n };\n\n private entraIdAccessTokenRotation = async (): Promise<void> => {\n coreLogger.info(\"Entra id access token rotation handler\");\n try {\n if (this._entraIdAccessToken.doesEntraIdAccessTokenNeedRotation()) {\n await this._entraIdAccessToken.fetchEntraIdAccessToken();\n }\n } catch (err) {\n coreLogger.error(err); // log error and continue if it's an intermittent issue (optimistic approach)\n }\n };\n}\n\nconst instance = PlaywrightServiceEntra.getInstance();\nexport default instance;\n"],
5
- "mappings": "AAGA,SAAS,mCAAmC;AAC5C,SAAS,kBAAkB;AAC3B,SAAS,0BAA0B;AACnC,SAAS,aAAa;AAGtB,MAAM,uBAAuB;AAAA,EACnB;AAAA,EACA;AAAA,EAER,OAAO,cAAc,MAA8B;AACjD,QAAI,CAAC,MAAM,wBAAwB;AACjC,YAAM,yBAAyB,IAAI,uBAAuB;AAAA,IAC5D;AACA,WAAO,MAAM;AAAA,EACf;AAAA,EAEA,IAAI,mBAAmB,YAA6B;AAClD,SAAK,sBAAsB,IAAI,mBAAmB,UAAU;AAAA,EAC9D;AAAA,EAEA,cAAc;AACZ,SAAK,sBAAsB,IAAI,mBAAmB;AAAA,EACpD;AAAA,EAEO,cAAc,YAA2B;AAC9C,eAAW,KAAK,mCAAmC;AACnD,UAAM,KAAK,oBAAoB,wBAAwB;AACvD,SAAK,kCAAkC;AAAA,EACzC;AAAA,EAEO,iBAAiB,MAAY;AAClC,eAAW,KAAK,sCAAsC;AACtD,QAAI,KAAK,qCAAqC;AAC5C,oBAAc,KAAK,mCAAmC;AACtD,iBAAW,KAAK,iDAAiD;AAAA,IACnE;AAAA,EACF;AAAA,EAEQ,oCAAoC,MAAY;AACtD,SAAK,sCAAsC;AAAA,MACzC,KAAK;AAAA,MACL,4BAA4B,sCAAsC,KAAK;AAAA,IACzE;AACA,eAAW,KAAK,mDAAmD;AAAA,EACrE;AAAA,EAEQ,6BAA6B,YAA2B;AAC9D,eAAW,KAAK,wCAAwC;AACxD,QAAI;AACF,UAAI,KAAK,oBAAoB,mCAAmC,GAAG;AACjE,cAAM,KAAK,oBAAoB,wBAAwB;AAAA,MACzD;AAAA,IACF,SAAS,KAAK;AACZ,iBAAW,MAAM,GAAG;AAAA,IACtB;AAAA,EACF;AACF;AAEA,MAAM,WAAW,uBAAuB,YAAY;AACpD,IAAO,iCAAQ;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"playwrightServiceEntra.js","sourceRoot":"","sources":["../../../src/core/playwrightServiceEntra.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAG3C,MAAM,sBAAsB;IAClB,mCAAmC,CAAkB;IACrD,mBAAmB,CAAqB;IAEhD,MAAM,CAAC,WAAW,GAAG,GAA2B,EAAE;QAChD,IAAI,CAAC,KAAK,CAAC,sBAAsB,EAAE,CAAC;YAClC,KAAK,CAAC,sBAAsB,GAAG,IAAI,sBAAsB,EAAE,CAAC;QAC9D,CAAC;QACD,OAAO,KAAK,CAAC,sBAAsB,CAAC;IACtC,CAAC,CAAC;IAEF,IAAI,kBAAkB,CAAC,UAA2B;QAChD,IAAI,CAAC,mBAAmB,GAAG,IAAI,kBAAkB,CAAC,UAAU,CAAC,CAAC;IAChE,CAAC;IAED;QACE,IAAI,CAAC,mBAAmB,GAAG,IAAI,kBAAkB,EAAE,CAAC;IACtD,CAAC;IAEM,WAAW,GAAG,KAAK,IAAmB,EAAE;QAC7C,UAAU,CAAC,IAAI,CAAC,mCAAmC,CAAC,CAAC;QACrD,MAAM,IAAI,CAAC,mBAAmB,CAAC,uBAAuB,EAAE,CAAC;QACzD,IAAI,CAAC,iCAAiC,EAAE,CAAC;IAC3C,CAAC,CAAC;IAEK,cAAc,GAAG,GAAS,EAAE;QACjC,UAAU,CAAC,IAAI,CAAC,sCAAsC,CAAC,CAAC;QACxD,IAAI,IAAI,CAAC,mCAAmC,EAAE,CAAC;YAC7C,aAAa,CAAC,IAAI,CAAC,mCAAmC,CAAC,CAAC;YACxD,UAAU,CAAC,IAAI,CAAC,iDAAiD,CAAC,CAAC;QACrE,CAAC;IACH,CAAC,CAAC;IAEM,iCAAiC,GAAG,GAAS,EAAE;QACrD,IAAI,CAAC,mCAAmC,GAAG,WAAW,CACpD,IAAI,CAAC,0BAA0B,EAC/B,2BAA2B,CAAC,mCAAmC,GAAG,EAAE,GAAG,IAAI,CAC5E,CAAC;QACF,UAAU,CAAC,IAAI,CAAC,mDAAmD,CAAC,CAAC;IACvE,CAAC,CAAC;IAEM,0BAA0B,GAAG,KAAK,IAAmB,EAAE;QAC7D,UAAU,CAAC,IAAI,CAAC,wCAAwC,CAAC,CAAC;QAC1D,IAAI,CAAC;YACH,IAAI,IAAI,CAAC,mBAAmB,CAAC,kCAAkC,EAAE,EAAE,CAAC;gBAClE,MAAM,IAAI,CAAC,mBAAmB,CAAC,uBAAuB,EAAE,CAAC;YAC3D,CAAC;QACH,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,6EAA6E;QACtG,CAAC;IACH,CAAC,CAAC;;AAGJ,MAAM,QAAQ,GAAG,sBAAsB,CAAC,WAAW,EAAE,CAAC;AACtD,eAAe,QAAQ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { EntraIdAccessTokenConstants } from \"../common/constants.js\";\nimport { coreLogger } from \"../common/logger.js\";\nimport { EntraIdAccessToken } from \"../common/entraIdAccessToken.js\";\nimport { state } from \"../common/state.js\";\nimport type { TokenCredential } from \"@azure/identity\";\n\nclass PlaywrightServiceEntra {\n private _entraIdAccessTokenRotationInterval?: NodeJS.Timeout;\n private _entraIdAccessToken: EntraIdAccessToken;\n\n static getInstance = (): PlaywrightServiceEntra => {\n if (!state.playwrightServiceEntra) {\n state.playwrightServiceEntra = new PlaywrightServiceEntra();\n }\n return state.playwrightServiceEntra;\n };\n\n set entraIdAccessToken(credential: TokenCredential) {\n this._entraIdAccessToken = new EntraIdAccessToken(credential);\n }\n\n constructor() {\n this._entraIdAccessToken = new EntraIdAccessToken();\n }\n\n public globalSetup = async (): Promise<void> => {\n coreLogger.info(\"Entra id access token setup start\");\n await this._entraIdAccessToken.fetchEntraIdAccessToken();\n this.entraIdGlobalSetupRotationHandler();\n };\n\n public globalTeardown = (): void => {\n coreLogger.info(\"Entra id access token teardown start\");\n if (this._entraIdAccessTokenRotationInterval) {\n clearInterval(this._entraIdAccessTokenRotationInterval);\n coreLogger.info(\"Entra id access token rotation interval cleared\");\n }\n };\n\n private entraIdGlobalSetupRotationHandler = (): void => {\n this._entraIdAccessTokenRotationInterval = setInterval(\n this.entraIdAccessTokenRotation,\n EntraIdAccessTokenConstants.ROTATION_INTERVAL_PERIOD_IN_MINUTES * 60 * 1000,\n );\n coreLogger.info(\"Entra id access token rotation handler setup done\");\n };\n\n private entraIdAccessTokenRotation = async (): Promise<void> => {\n coreLogger.info(\"Entra id access token rotation handler\");\n try {\n if (this._entraIdAccessToken.doesEntraIdAccessTokenNeedRotation()) {\n await this._entraIdAccessToken.fetchEntraIdAccessToken();\n }\n } catch (err) {\n coreLogger.error(err); // log error and continue if it's an intermittent issue (optimistic approach)\n }\n };\n}\n\nconst instance = PlaywrightServiceEntra.getInstance();\nexport default instance;\n"]}
@@ -1,11 +1,13 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
1
3
  import path from "node:path";
2
4
  import { dirname } from "node:path";
3
5
  import { fileURLToPath } from "node:url";
6
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
7
+ // @ts-ignore ESM only output
4
8
  const currentDir = dirname(fileURLToPath(import.meta.url));
5
- const globalPaths = {
6
- setup: path.join(currentDir, "./global/playwright-service-global-setup.js"),
7
- teardown: path.join(currentDir, "./global/playwright-service-global-teardown.js")
8
- };
9
- export {
10
- globalPaths
9
+ export const globalPaths = {
10
+ setup: path.join(currentDir, "./global/playwright-service-global-setup.js"),
11
+ teardown: path.join(currentDir, "./global/playwright-service-global-teardown.js"),
11
12
  };
13
+ //# sourceMappingURL=playwrightServiceUtils.js.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["/mnt/vss/_work/1/s/sdk/loadtesting/playwright/src/core/playwrightServiceUtils.ts"],
4
- "sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport path from \"node:path\";\nimport { dirname } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore ESM only output\nconst currentDir = dirname(fileURLToPath(import.meta.url));\n\nexport const globalPaths = {\n setup: path.join(currentDir, \"./global/playwright-service-global-setup.js\"),\n teardown: path.join(currentDir, \"./global/playwright-service-global-teardown.js\"),\n};\n"],
5
- "mappings": "AAGA,OAAO,UAAU;AACjB,SAAS,eAAe;AACxB,SAAS,qBAAqB;AAI9B,MAAM,aAAa,QAAQ,cAAc,YAAY,GAAG,CAAC;AAElD,MAAM,cAAc;AAAA,EACzB,OAAO,KAAK,KAAK,YAAY,6CAA6C;AAAA,EAC1E,UAAU,KAAK,KAAK,YAAY,gDAAgD;AAClF;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"playwrightServiceUtils.js","sourceRoot":"","sources":["../../../src/core/playwrightServiceUtils.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,6DAA6D;AAC7D,6BAA6B;AAC7B,MAAM,UAAU,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAE3D,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,6CAA6C,CAAC;IAC3E,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,gDAAgD,CAAC;CAClF,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport path from \"node:path\";\nimport { dirname } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore ESM only output\nconst currentDir = dirname(fileURLToPath(import.meta.url));\n\nexport const globalPaths = {\n setup: path.join(currentDir, \"./global/playwright-service-global-setup.js\"),\n teardown: path.join(currentDir, \"./global/playwright-service-global-teardown.js\"),\n};\n"]}
package/dist/esm/index.js CHANGED
@@ -1,9 +1,11 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ /**
4
+ * Library for integrating Azure Playwright with existing playwright projects.
5
+ *
6
+ * @packageDocumentation
7
+ */
1
8
  import { ServiceAuth, ServiceOS, ServiceEnvironmentVariable } from "./common/constants.js";
2
9
  import { createAzurePlaywrightConfig, getConnectOptions } from "./core/playwrightService.js";
3
- export {
4
- ServiceAuth,
5
- ServiceEnvironmentVariable,
6
- ServiceOS,
7
- createAzurePlaywrightConfig,
8
- getConnectOptions
9
- };
10
+ export { createAzurePlaywrightConfig, getConnectOptions, ServiceOS, ServiceAuth, ServiceEnvironmentVariable, };
11
+ //# sourceMappingURL=index.js.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["/mnt/vss/_work/1/s/sdk/loadtesting/playwright/src/index.ts"],
4
- "sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * Library for integrating Azure Playwright with existing playwright projects.\n *\n * @packageDocumentation\n */\n\nimport { ServiceAuth, ServiceOS, ServiceEnvironmentVariable } from \"./common/constants.js\";\nimport type {\n OsType,\n AuthenticationType,\n BrowserConnectOptions,\n EndpointOptions,\n PlaywrightServiceAdditionalOptions,\n} from \"./common/types.js\";\nimport { createAzurePlaywrightConfig, getConnectOptions } from \"./core/playwrightService.js\";\n\nexport {\n createAzurePlaywrightConfig,\n getConnectOptions,\n ServiceOS,\n ServiceAuth,\n ServiceEnvironmentVariable,\n type OsType,\n type AuthenticationType,\n type BrowserConnectOptions,\n type EndpointOptions,\n type PlaywrightServiceAdditionalOptions,\n};\n"],
5
- "mappings": "AASA,SAAS,aAAa,WAAW,kCAAkC;AAQnE,SAAS,6BAA6B,yBAAyB;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AAQ3F,OAAO,EAAE,2BAA2B,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAE7F,OAAO,EACL,2BAA2B,EAC3B,iBAAiB,EACjB,SAAS,EACT,WAAW,EACX,0BAA0B,GAM3B,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * Library for integrating Azure Playwright with existing playwright projects.\n *\n * @packageDocumentation\n */\n\nimport { ServiceAuth, ServiceOS, ServiceEnvironmentVariable } from \"./common/constants.js\";\nimport type {\n OsType,\n AuthenticationType,\n BrowserConnectOptions,\n EndpointOptions,\n PlaywrightServiceAdditionalOptions,\n} from \"./common/types.js\";\nimport { createAzurePlaywrightConfig, getConnectOptions } from \"./core/playwrightService.js\";\n\nexport {\n createAzurePlaywrightConfig,\n getConnectOptions,\n ServiceOS,\n ServiceAuth,\n ServiceEnvironmentVariable,\n type OsType,\n type AuthenticationType,\n type BrowserConnectOptions,\n type EndpointOptions,\n type PlaywrightServiceAdditionalOptions,\n};\n"]}