@azure/playwright 1.1.3-alpha.20260310.1 → 1.1.3

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 (103) hide show
  1. package/dist/browser/common/constants.d.ts +3 -0
  2. package/dist/browser/common/constants.d.ts.map +1 -1
  3. package/dist/browser/common/constants.js +3 -0
  4. package/dist/browser/common/constants.js.map +1 -1
  5. package/dist/browser/common/types.d.ts +8 -0
  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/core/playwrightService.d.ts.map +1 -1
  9. package/dist/browser/core/playwrightService.js +6 -0
  10. package/dist/browser/core/playwrightService.js.map +1 -1
  11. package/dist/browser/utils/utils.d.ts.map +1 -1
  12. package/dist/browser/utils/utils.js +2 -3
  13. package/dist/browser/utils/utils.js.map +1 -1
  14. package/dist/commonjs/common/constants.d.ts +3 -0
  15. package/dist/commonjs/common/constants.d.ts.map +1 -1
  16. package/dist/commonjs/common/constants.js +97 -126
  17. package/dist/commonjs/common/constants.js.map +1 -7
  18. package/dist/commonjs/common/customerConfig.js +14 -31
  19. package/dist/commonjs/common/customerConfig.js.map +1 -7
  20. package/dist/commonjs/common/entraIdAccessToken.js +83 -106
  21. package/dist/commonjs/common/entraIdAccessToken.js.map +1 -7
  22. package/dist/commonjs/common/environmentVariables.js +24 -43
  23. package/dist/commonjs/common/environmentVariables.js.map +1 -7
  24. package/dist/commonjs/common/executor.js +67 -88
  25. package/dist/commonjs/common/executor.js.map +1 -7
  26. package/dist/commonjs/common/httpService.js +35 -54
  27. package/dist/commonjs/common/httpService.js.map +1 -7
  28. package/dist/commonjs/common/logger.js +8 -28
  29. package/dist/commonjs/common/logger.js.map +1 -7
  30. package/dist/commonjs/common/messages.js +169 -189
  31. package/dist/commonjs/common/messages.js.map +1 -7
  32. package/dist/commonjs/common/playwrightServiceConfig.js +98 -113
  33. package/dist/commonjs/common/playwrightServiceConfig.js.map +1 -7
  34. package/dist/commonjs/common/state.js +10 -30
  35. package/dist/commonjs/common/state.js.map +1 -7
  36. package/dist/commonjs/common/types.d.ts +8 -0
  37. package/dist/commonjs/common/types.d.ts.map +1 -1
  38. package/dist/commonjs/common/types.js +5 -15
  39. package/dist/commonjs/common/types.js.map +1 -7
  40. package/dist/commonjs/core/global/playwright-service-global-setup.js +26 -52
  41. package/dist/commonjs/core/global/playwright-service-global-setup.js.map +1 -7
  42. package/dist/commonjs/core/global/playwright-service-global-teardown.js +20 -49
  43. package/dist/commonjs/core/global/playwright-service-global-teardown.js.map +1 -7
  44. package/dist/commonjs/core/initializePlaywrightServiceTestRun.js +27 -39
  45. package/dist/commonjs/core/initializePlaywrightServiceTestRun.js.map +1 -7
  46. package/dist/commonjs/core/playwrightService.d.ts.map +1 -1
  47. package/dist/commonjs/core/playwrightService.js +211 -166
  48. package/dist/commonjs/core/playwrightService.js.map +1 -7
  49. package/dist/commonjs/core/playwrightServiceEntra.js +48 -67
  50. package/dist/commonjs/core/playwrightServiceEntra.js.map +1 -7
  51. package/dist/commonjs/core/playwrightServiceUtils.d.ts.map +1 -1
  52. package/dist/commonjs/core/playwrightServiceUtils.js +11 -44
  53. package/dist/commonjs/core/playwrightServiceUtils.js.map +1 -7
  54. package/dist/commonjs/index.js +18 -36
  55. package/dist/commonjs/index.js.map +1 -7
  56. package/dist/commonjs/reporter/index.js +15 -34
  57. package/dist/commonjs/reporter/index.js.map +1 -7
  58. package/dist/commonjs/reporter/playwrightReporter.js +216 -222
  59. package/dist/commonjs/reporter/playwrightReporter.js.map +1 -7
  60. package/dist/commonjs/utils/PlaywrightServiceClient.js +91 -140
  61. package/dist/commonjs/utils/PlaywrightServiceClient.js.map +1 -7
  62. package/dist/commonjs/utils/cIInfoProvider.js +74 -81
  63. package/dist/commonjs/utils/cIInfoProvider.js.map +1 -7
  64. package/dist/commonjs/utils/getPackageVersion.d.ts.map +1 -1
  65. package/dist/commonjs/utils/getPackageVersion.js +19 -50
  66. package/dist/commonjs/utils/getPackageVersion.js.map +1 -7
  67. package/dist/commonjs/utils/getPlaywrightVersion.js +21 -42
  68. package/dist/commonjs/utils/getPlaywrightVersion.js.map +1 -7
  69. package/dist/commonjs/utils/packageManager.js +40 -59
  70. package/dist/commonjs/utils/packageManager.js.map +1 -7
  71. package/dist/commonjs/utils/parseJwt.js +17 -37
  72. package/dist/commonjs/utils/parseJwt.js.map +1 -7
  73. package/dist/commonjs/utils/playwrightReporterStorageManager.js +342 -381
  74. package/dist/commonjs/utils/playwrightReporterStorageManager.js.map +1 -7
  75. package/dist/commonjs/utils/utils.d.ts.map +1 -1
  76. package/dist/commonjs/utils/utils.js +368 -417
  77. package/dist/commonjs/utils/utils.js.map +1 -7
  78. package/dist/esm/common/constants.d.ts +3 -0
  79. package/dist/esm/common/constants.d.ts.map +1 -1
  80. package/dist/esm/common/constants.js +4 -0
  81. package/dist/esm/common/constants.js.map +2 -2
  82. package/dist/esm/common/types.d.ts +8 -0
  83. package/dist/esm/common/types.d.ts.map +1 -1
  84. package/dist/esm/core/playwrightService.d.ts.map +1 -1
  85. package/dist/esm/core/playwrightService.js +6 -0
  86. package/dist/esm/core/playwrightService.js.map +2 -2
  87. package/dist/esm/utils/utils.d.ts.map +1 -1
  88. package/dist/esm/utils/utils.js +4 -3
  89. package/dist/esm/utils/utils.js.map +2 -2
  90. package/dist/react-native/common/constants.d.ts +3 -0
  91. package/dist/react-native/common/constants.d.ts.map +1 -1
  92. package/dist/react-native/common/constants.js +3 -0
  93. package/dist/react-native/common/constants.js.map +1 -1
  94. package/dist/react-native/common/types.d.ts +8 -0
  95. package/dist/react-native/common/types.d.ts.map +1 -1
  96. package/dist/react-native/common/types.js.map +1 -1
  97. package/dist/react-native/core/playwrightService.d.ts.map +1 -1
  98. package/dist/react-native/core/playwrightService.js +6 -0
  99. package/dist/react-native/core/playwrightService.js.map +1 -1
  100. package/dist/react-native/utils/utils.d.ts.map +1 -1
  101. package/dist/react-native/utils/utils.js +2 -3
  102. package/dist/react-native/utils/utils.js.map +1 -1
  103. package/package.json +6 -6
@@ -1,41 +1,29 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var initializePlaywrightServiceTestRun_exports = {};
19
- __export(initializePlaywrightServiceTestRun_exports, {
20
- initializePlaywrightServiceTestRun: () => initializePlaywrightServiceTestRun
21
- });
22
- module.exports = __toCommonJS(initializePlaywrightServiceTestRun_exports);
23
- var import_PlaywrightServiceClient = require("../utils/PlaywrightServiceClient.js");
24
- var import_playwrightServiceConfig = require("../common/playwrightServiceConfig.js");
25
- var import_utils = require("../utils/utils.js");
26
- var import_cIInfoProvider = require("../utils/cIInfoProvider.js");
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.initializePlaywrightServiceTestRun = initializePlaywrightServiceTestRun;
6
+ const PlaywrightServiceClient_js_1 = require("../utils/PlaywrightServiceClient.js");
7
+ const playwrightServiceConfig_js_1 = require("../common/playwrightServiceConfig.js");
8
+ const utils_js_1 = require("../utils/utils.js");
9
+ const cIInfoProvider_js_1 = require("../utils/cIInfoProvider.js");
10
+ /**
11
+ * Initializes the Playwright workspaces by setting up authentication and creating a test run.
12
+ *
13
+ * @param config - The full Playwright configuration
14
+ * @returns Promise that resolves when service initialization is complete
15
+ */
27
16
  async function initializePlaywrightServiceTestRun(config) {
28
- const playwrightServiceApiClient = new import_PlaywrightServiceClient.PlaywrightServiceClient();
29
- const playwrightServiceConfig = import_playwrightServiceConfig.PlaywrightServiceConfig.instance;
30
- const ciConfigInfo = import_cIInfoProvider.CIInfoProvider.getCIInfo();
31
- const testRunCreatePayload = {
32
- displayName: playwrightServiceConfig.runName === "" ? playwrightServiceConfig.runId : playwrightServiceConfig.runName,
33
- config: (0, import_utils.getTestRunConfig)(config),
34
- ciConfig: ciConfigInfo
35
- };
36
- await playwrightServiceApiClient.createOrUpdateTestRun(testRunCreatePayload);
17
+ const playwrightServiceApiClient = new PlaywrightServiceClient_js_1.PlaywrightServiceClient();
18
+ const playwrightServiceConfig = playwrightServiceConfig_js_1.PlaywrightServiceConfig.instance;
19
+ const ciConfigInfo = cIInfoProvider_js_1.CIInfoProvider.getCIInfo();
20
+ const testRunCreatePayload = {
21
+ displayName: playwrightServiceConfig.runName === ""
22
+ ? playwrightServiceConfig.runId
23
+ : playwrightServiceConfig.runName,
24
+ config: (0, utils_js_1.getTestRunConfig)(config),
25
+ ciConfig: ciConfigInfo,
26
+ };
27
+ await playwrightServiceApiClient.createOrUpdateTestRun(testRunCreatePayload);
37
28
  }
38
- // Annotate the CommonJS export names for ESM import in node:
39
- 0 && (module.exports = {
40
- initializePlaywrightServiceTestRun
41
- });
29
+ //# sourceMappingURL=initializePlaywrightServiceTestRun.js.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["/mnt/vss/_work/1/s/sdk/loadtesting/playwright/src/core/initializePlaywrightServiceTestRun.ts"],
4
- "sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { FullConfig } from \"@playwright/test\";\nimport { PlaywrightServiceClient } from \"../utils/PlaywrightServiceClient.js\";\nimport { PlaywrightServiceConfig } from \"../common/playwrightServiceConfig.js\";\nimport { getTestRunConfig } from \"../utils/utils.js\";\nimport { CIInfoProvider } from \"../utils/cIInfoProvider.js\";\n\n/**\n * Initializes the Playwright workspaces by setting up authentication and creating a test run.\n *\n * @param config - The full Playwright configuration\n * @returns Promise that resolves when service initialization is complete\n */\nexport async function initializePlaywrightServiceTestRun(config: FullConfig): Promise<void> {\n const playwrightServiceApiClient = new PlaywrightServiceClient();\n const playwrightServiceConfig = PlaywrightServiceConfig.instance;\n const ciConfigInfo = CIInfoProvider.getCIInfo();\n\n const testRunCreatePayload = {\n displayName:\n playwrightServiceConfig.runName === \"\"\n ? playwrightServiceConfig.runId\n : playwrightServiceConfig.runName,\n config: getTestRunConfig(config),\n ciConfig: ciConfigInfo,\n };\n\n await playwrightServiceApiClient.createOrUpdateTestRun(testRunCreatePayload);\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,qCAAwC;AACxC,qCAAwC;AACxC,mBAAiC;AACjC,4BAA+B;AAQ/B,eAAsB,mCAAmC,QAAmC;AAC1F,QAAM,6BAA6B,IAAI,uDAAwB;AAC/D,QAAM,0BAA0B,uDAAwB;AACxD,QAAM,eAAe,qCAAe,UAAU;AAE9C,QAAM,uBAAuB;AAAA,IAC3B,aACE,wBAAwB,YAAY,KAChC,wBAAwB,QACxB,wBAAwB;AAAA,IAC9B,YAAQ,+BAAiB,MAAM;AAAA,IAC/B,UAAU;AAAA,EACZ;AAEA,QAAM,2BAA2B,sBAAsB,oBAAoB;AAC7E;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"initializePlaywrightServiceTestRun.js","sourceRoot":"","sources":["../../../src/core/initializePlaywrightServiceTestRun.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAclC,gFAeC;AA1BD,oFAA8E;AAC9E,qFAA+E;AAC/E,gDAAqD;AACrD,kEAA4D;AAE5D;;;;;GAKG;AACI,KAAK,UAAU,kCAAkC,CAAC,MAAkB;IACzE,MAAM,0BAA0B,GAAG,IAAI,oDAAuB,EAAE,CAAC;IACjE,MAAM,uBAAuB,GAAG,oDAAuB,CAAC,QAAQ,CAAC;IACjE,MAAM,YAAY,GAAG,kCAAc,CAAC,SAAS,EAAE,CAAC;IAEhD,MAAM,oBAAoB,GAAG;QAC3B,WAAW,EACT,uBAAuB,CAAC,OAAO,KAAK,EAAE;YACpC,CAAC,CAAC,uBAAuB,CAAC,KAAK;YAC/B,CAAC,CAAC,uBAAuB,CAAC,OAAO;QACrC,MAAM,EAAE,IAAA,2BAAgB,EAAC,MAAM,CAAC;QAChC,QAAQ,EAAE,YAAY;KACvB,CAAC;IAEF,MAAM,0BAA0B,CAAC,qBAAqB,CAAC,oBAAoB,CAAC,CAAC;AAC/E,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { FullConfig } from \"@playwright/test\";\nimport { PlaywrightServiceClient } from \"../utils/PlaywrightServiceClient.js\";\nimport { PlaywrightServiceConfig } from \"../common/playwrightServiceConfig.js\";\nimport { getTestRunConfig } from \"../utils/utils.js\";\nimport { CIInfoProvider } from \"../utils/cIInfoProvider.js\";\n\n/**\n * Initializes the Playwright workspaces by setting up authentication and creating a test run.\n *\n * @param config - The full Playwright configuration\n * @returns Promise that resolves when service initialization is complete\n */\nexport async function initializePlaywrightServiceTestRun(config: FullConfig): Promise<void> {\n const playwrightServiceApiClient = new PlaywrightServiceClient();\n const playwrightServiceConfig = PlaywrightServiceConfig.instance;\n const ciConfigInfo = CIInfoProvider.getCIInfo();\n\n const testRunCreatePayload = {\n displayName:\n playwrightServiceConfig.runName === \"\"\n ? playwrightServiceConfig.runId\n : playwrightServiceConfig.runName,\n config: getTestRunConfig(config),\n ciConfig: ciConfigInfo,\n };\n\n await playwrightServiceApiClient.createOrUpdateTestRun(testRunCreatePayload);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"playwrightService.d.ts","sourceRoot":"","sources":["../../../src/core/playwrightService.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,kCAAkC,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAgBpG,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAa7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,QAAA,MAAM,2BAA2B,GAC/B,YAAY,oBAAoB,EAChC,UAAU,kCAAkC,KAC3C,oBA6GF,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,QAAA,MAAM,iBAAiB,GACrB,UAAU,kCAAkC,KAC3C,OAAO,CAAC,qBAAqB,CA0C/B,CAAC;AAEF,OAAO,EAAE,2BAA2B,EAAE,iBAAiB,EAAE,CAAC"}
1
+ {"version":3,"file":"playwrightService.d.ts","sourceRoot":"","sources":["../../../src/core/playwrightService.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,kCAAkC,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAgBpG,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAa7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,QAAA,MAAM,2BAA2B,GAC/B,YAAY,oBAAoB,EAChC,UAAU,kCAAkC,KAC3C,oBAiHF,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,QAAA,MAAM,iBAAiB,GACrB,UAAU,kCAAkC,KAC3C,OAAO,CAAC,qBAAqB,CA0C/B,CAAC;AAEF,OAAO,EAAE,2BAA2B,EAAE,iBAAiB,EAAE,CAAC"}
@@ -1,179 +1,224 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
- var playwrightService_exports = {};
29
- __export(playwrightService_exports, {
30
- createAzurePlaywrightConfig: () => createAzurePlaywrightConfig,
31
- getConnectOptions: () => getConnectOptions
32
- });
33
- module.exports = __toCommonJS(playwrightService_exports);
34
- var import_constants = require("../common/constants.js");
35
- var import_customerConfig = __toESM(require("../common/customerConfig.js"));
36
- var import_playwrightServiceConfig = require("../common/playwrightServiceConfig.js");
37
- var import_playwrightServiceEntra = __toESM(require("./playwrightServiceEntra.js"));
38
- var import_utils = require("../utils/utils.js");
39
- var import_messages = require("../common/messages.js");
40
- var import_playwrightServiceUtils = require("./playwrightServiceUtils.js");
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.createAzurePlaywrightConfig = void 0;
6
+ const tslib_1 = require("tslib");
7
+ const constants_js_1 = require("../common/constants.js");
8
+ const customerConfig_js_1 = tslib_1.__importDefault(require("../common/customerConfig.js"));
9
+ const playwrightServiceConfig_js_1 = require("../common/playwrightServiceConfig.js");
10
+ const playwrightServiceEntra_js_1 = tslib_1.__importDefault(require("./playwrightServiceEntra.js"));
11
+ const utils_js_1 = require("../utils/utils.js");
12
+ const messages_js_1 = require("../common/messages.js");
13
+ const playwrightServiceUtils_js_1 = require("./playwrightServiceUtils.js");
41
14
  const performOneTimeOperation = (options) => {
42
- const oneTimeOperationFlag = process.env[import_constants.InternalEnvironmentVariables.ONE_TIME_OPERATION_FLAG] === "true";
43
- if (oneTimeOperationFlag) return;
44
- process.env[import_constants.InternalEnvironmentVariables.ONE_TIME_OPERATION_FLAG] = "true";
45
- if (options?.serviceAuthType === import_constants.ServiceAuth.ACCESS_TOKEN) {
46
- (0, import_utils.warnIfAccessTokenCloseToExpiry)();
47
- }
15
+ const oneTimeOperationFlag = process.env[constants_js_1.InternalEnvironmentVariables.ONE_TIME_OPERATION_FLAG] === "true";
16
+ if (oneTimeOperationFlag)
17
+ return;
18
+ process.env[constants_js_1.InternalEnvironmentVariables.ONE_TIME_OPERATION_FLAG] = "true";
19
+ if (options?.serviceAuthType === constants_js_1.ServiceAuth.ACCESS_TOKEN) {
20
+ (0, utils_js_1.warnIfAccessTokenCloseToExpiry)();
21
+ }
48
22
  };
23
+ /**
24
+ * @public
25
+ *
26
+ * Generate playwright configuration integrated with Azure Playwright.
27
+ *
28
+ * @param baseConfig - base playwright configuration
29
+ * @param options - additional options for the service
30
+ * @returns PlaywrightConfig
31
+ *
32
+ * @example
33
+ * ```
34
+ * import { defineConfig } from "playwright/test";
35
+ * import { createAzurePlaywrightConfig } from "@azure/playwright";
36
+ * import playwrightConfig from "./playwright.config";
37
+ *
38
+ * export default defineConfig(playwrightConfig, createAzurePlaywrightConfig(playwrightConfig));
39
+ * ```
40
+ *
41
+ * @example
42
+ * ```
43
+ * import { defineConfig } from "playwright/test";
44
+ * import { createAzurePlaywrightConfig, ServiceOS, ServiceAuth } from "@azure/playwright";
45
+ * import playwrightConfig from "./playwright.config";
46
+ * import { DefaultAzureCredential } from '@azure/identity';
47
+ *
48
+ * export default defineConfig(playwrightConfig, createAzurePlaywrightConfig(playwrightConfig, {
49
+ * credential: new DefaultAzureCredential(),
50
+ * serviceAuthType: ServiceAuth.ENTRA_ID,
51
+ * os: ServiceOS.WINDOWS
52
+ * }));
53
+ * ```
54
+ */
49
55
  const createAzurePlaywrightConfig = (baseConfig, options) => {
50
- (0, import_utils.validatePlaywrightVersion)();
51
- (0, import_utils.validateServiceUrl)();
52
- process.env[import_constants.InternalEnvironmentVariables.USING_SERVICE_CONFIG] = "true";
53
- const playwrightVersionInfo = (0, import_utils.getVersionInfo)((0, import_utils.getPlaywrightVersion)());
54
- const isMultipleGlobalFileSupported = playwrightVersionInfo.major >= 1 && playwrightVersionInfo.minor >= 49;
55
- if (options?.credential) {
56
- import_playwrightServiceEntra.default.entraIdAccessToken = options.credential;
57
- }
58
- if (baseConfig && baseConfig.globalSetup) {
59
- if (typeof baseConfig.globalSetup === "string") {
60
- if (isMultipleGlobalFileSupported) {
61
- import_customerConfig.default.globalSetup = [baseConfig.globalSetup];
62
- } else {
63
- import_customerConfig.default.globalSetup = baseConfig.globalSetup;
64
- }
65
- } else {
66
- if (!isMultipleGlobalFileSupported) {
67
- throw new Error(
68
- import_messages.ServiceErrorMessageConstants.MULTIPLE_SETUP_FILE_PLAYWRIGHT_VERSION_ERROR.message
69
- );
70
- }
71
- import_customerConfig.default.globalSetup = baseConfig.globalSetup;
56
+ (0, utils_js_1.validatePlaywrightVersion)();
57
+ (0, utils_js_1.validateServiceUrl)();
58
+ // Set environment variable to indicate user is using service config
59
+ process.env[constants_js_1.InternalEnvironmentVariables.USING_SERVICE_CONFIG] = "true";
60
+ const playwrightVersionInfo = (0, utils_js_1.getVersionInfo)((0, utils_js_1.getPlaywrightVersion)());
61
+ const isMultipleGlobalFileSupported = playwrightVersionInfo.major >= 1 && playwrightVersionInfo.minor >= 49;
62
+ if (options?.credential) {
63
+ playwrightServiceEntra_js_1.default.entraIdAccessToken = options.credential;
64
+ }
65
+ // if global setup/teardown is string -
66
+ // 1. if multiple global file is supported, convert it to array
67
+ // 2. wrap playwright-service global setup/teardown with customer provided global setup/teardown
68
+ // if global setup/teardown is array -
69
+ // 1. if multiple global file is not supported, throw error
70
+ // 2. append playwright-service global setup/teardown with customer provided global setup/teardown
71
+ if (baseConfig && baseConfig.globalSetup) {
72
+ if (typeof baseConfig.globalSetup === "string") {
73
+ if (isMultipleGlobalFileSupported) {
74
+ customerConfig_js_1.default.globalSetup = [baseConfig.globalSetup];
75
+ }
76
+ else {
77
+ customerConfig_js_1.default.globalSetup = baseConfig.globalSetup;
78
+ }
79
+ }
80
+ else {
81
+ if (!isMultipleGlobalFileSupported) {
82
+ throw new Error(messages_js_1.ServiceErrorMessageConstants.MULTIPLE_SETUP_FILE_PLAYWRIGHT_VERSION_ERROR.message);
83
+ }
84
+ customerConfig_js_1.default.globalSetup = baseConfig.globalSetup;
85
+ }
86
+ }
87
+ if (baseConfig && baseConfig.globalTeardown) {
88
+ if (typeof baseConfig.globalTeardown === "string") {
89
+ if (isMultipleGlobalFileSupported) {
90
+ customerConfig_js_1.default.globalTeardown = [baseConfig.globalTeardown];
91
+ }
92
+ else {
93
+ customerConfig_js_1.default.globalTeardown = baseConfig.globalTeardown;
94
+ }
95
+ }
96
+ else {
97
+ if (!isMultipleGlobalFileSupported) {
98
+ throw new Error(messages_js_1.ServiceErrorMessageConstants.MULTIPLE_SETUP_FILE_PLAYWRIGHT_VERSION_ERROR.message);
99
+ }
100
+ customerConfig_js_1.default.globalTeardown = baseConfig.globalTeardown;
101
+ }
72
102
  }
73
- }
74
- if (baseConfig && baseConfig.globalTeardown) {
75
- if (typeof baseConfig.globalTeardown === "string") {
76
- if (isMultipleGlobalFileSupported) {
77
- import_customerConfig.default.globalTeardown = [baseConfig.globalTeardown];
78
- } else {
79
- import_customerConfig.default.globalTeardown = baseConfig.globalTeardown;
80
- }
81
- } else {
82
- if (!isMultipleGlobalFileSupported) {
83
- throw new Error(
84
- import_messages.ServiceErrorMessageConstants.MULTIPLE_SETUP_FILE_PLAYWRIGHT_VERSION_ERROR.message
85
- );
86
- }
87
- import_customerConfig.default.globalTeardown = baseConfig.globalTeardown;
103
+ const playwrightServiceConfig = playwrightServiceConfig_js_1.PlaywrightServiceConfig.instance;
104
+ playwrightServiceConfig.setOptions(options);
105
+ playwrightServiceConfig.serviceAuthType =
106
+ options?.serviceAuthType || constants_js_1.DefaultConnectOptionsConstants.DEFAULT_SERVICE_AUTH_TYPE;
107
+ const globalFunctions = {};
108
+ if (options?.serviceAuthType === constants_js_1.ServiceAuth.ACCESS_TOKEN) {
109
+ // mpt PAT requested and set by the customer, no need to setup entra lifecycle handlers
110
+ (0, utils_js_1.validateMptPAT)(utils_js_1.exitWithFailureMessage);
88
111
  }
89
- }
90
- const playwrightServiceConfig = import_playwrightServiceConfig.PlaywrightServiceConfig.instance;
91
- playwrightServiceConfig.setOptions(options);
92
- playwrightServiceConfig.serviceAuthType = options?.serviceAuthType || import_constants.DefaultConnectOptionsConstants.DEFAULT_SERVICE_AUTH_TYPE;
93
- const globalFunctions = {};
94
- if (options?.serviceAuthType === import_constants.ServiceAuth.ACCESS_TOKEN) {
95
- (0, import_utils.validateMptPAT)(import_utils.exitWithFailureMessage);
96
- }
97
- if (isMultipleGlobalFileSupported) {
98
- globalFunctions.globalSetup = [];
99
- globalFunctions.globalTeardown = [];
100
- if (import_customerConfig.default.globalSetup) {
101
- globalFunctions.globalSetup.push(...import_customerConfig.default.globalSetup);
112
+ // If multiple global file is supported, append playwright-service global setup/teardown with customer provided global setup/teardown
113
+ if (isMultipleGlobalFileSupported) {
114
+ globalFunctions.globalSetup = [];
115
+ globalFunctions.globalTeardown = [];
116
+ if (customerConfig_js_1.default.globalSetup) {
117
+ globalFunctions.globalSetup.push(...customerConfig_js_1.default.globalSetup);
118
+ }
119
+ if (customerConfig_js_1.default.globalTeardown) {
120
+ globalFunctions.globalTeardown.push(...customerConfig_js_1.default.globalTeardown);
121
+ }
122
+ globalFunctions.globalSetup.push(playwrightServiceUtils_js_1.globalPaths.setup);
123
+ globalFunctions.globalTeardown.push(playwrightServiceUtils_js_1.globalPaths.teardown);
102
124
  }
103
- if (import_customerConfig.default.globalTeardown) {
104
- globalFunctions.globalTeardown.push(...import_customerConfig.default.globalTeardown);
125
+ else {
126
+ // If multiple global file is not supported, wrap playwright-service global setup/teardown with customer provided global setup/teardown
127
+ globalFunctions.globalSetup = playwrightServiceUtils_js_1.globalPaths.setup;
128
+ globalFunctions.globalTeardown = playwrightServiceUtils_js_1.globalPaths.teardown;
105
129
  }
106
- globalFunctions.globalSetup.push(import_playwrightServiceUtils.globalPaths.setup);
107
- globalFunctions.globalTeardown.push(import_playwrightServiceUtils.globalPaths.teardown);
108
- } else {
109
- globalFunctions.globalSetup = import_playwrightServiceUtils.globalPaths.setup;
110
- globalFunctions.globalTeardown = import_playwrightServiceUtils.globalPaths.teardown;
111
- }
112
- performOneTimeOperation(options);
113
- if (!process.env[import_constants.InternalEnvironmentVariables.MPT_CLOUD_HOSTED_BROWSER_USED]) {
114
- process.env[import_constants.InternalEnvironmentVariables.MPT_CLOUD_HOSTED_BROWSER_USED] = "true";
115
- console.log("\nRunning tests using Playwright workspaces.");
116
- }
117
- return {
118
- use: {
119
- connectOptions: {
120
- wsEndpoint: (0, import_utils.getServiceWSEndpoint)(
121
- playwrightServiceConfig.runId,
122
- playwrightServiceConfig.serviceOs,
123
- playwrightServiceConfig.apiVersion
124
- ),
125
- headers: {
126
- Authorization: `Bearer ${(0, import_utils.getAccessToken)()}`,
127
- "x-ms-package-version": `@azure/playwright/${(0, import_utils.getPackageVersion)()}`
130
+ performOneTimeOperation(options);
131
+ if (options?.useCloudHostedBrowsers === false) {
132
+ console.log("\nRunning tests using local browsers.");
133
+ return {
134
+ ...globalFunctions,
135
+ };
136
+ }
137
+ if (!process.env[constants_js_1.InternalEnvironmentVariables.MPT_CLOUD_HOSTED_BROWSER_USED]) {
138
+ process.env[constants_js_1.InternalEnvironmentVariables.MPT_CLOUD_HOSTED_BROWSER_USED] = "true";
139
+ console.log("\nRunning tests using Playwright workspaces.");
140
+ }
141
+ return {
142
+ use: {
143
+ connectOptions: {
144
+ wsEndpoint: (0, utils_js_1.getServiceWSEndpoint)(playwrightServiceConfig.runId, playwrightServiceConfig.serviceOs, playwrightServiceConfig.apiVersion),
145
+ headers: {
146
+ Authorization: `Bearer ${(0, utils_js_1.getAccessToken)()}`,
147
+ "x-ms-package-version": `@azure/playwright/${(0, utils_js_1.getPackageVersion)()}`,
148
+ },
149
+ timeout: playwrightServiceConfig.connectTimeout,
150
+ exposeNetwork: playwrightServiceConfig.exposeNetwork,
151
+ slowMo: playwrightServiceConfig.slowMo,
152
+ },
128
153
  },
129
- timeout: playwrightServiceConfig.connectTimeout,
130
- exposeNetwork: playwrightServiceConfig.exposeNetwork,
131
- slowMo: playwrightServiceConfig.slowMo
132
- }
133
- },
134
- ...globalFunctions
135
- };
154
+ ...globalFunctions,
155
+ };
136
156
  };
157
+ exports.createAzurePlaywrightConfig = createAzurePlaywrightConfig;
158
+ /**
159
+ * @public
160
+ *
161
+ * Get connect options required to connect to Azure Playwright's cloud hosted browsers.
162
+ *
163
+ * @param options - additional options for the service
164
+ * @returns BrowserConnectOptions
165
+ *
166
+ * @example
167
+ * ```
168
+ * import playwright, { test, expect, BrowserType } from "@playwright/test";
169
+ * import { getConnectOptions } from "@azure/playwright";
170
+ *
171
+ * test('has title', async ({ browserName }) => {
172
+ * const { wsEndpoint, options } = await getConnectOptions();
173
+ * const browser = await (playwright[browserName] as BrowserType).connect(wsEndpoint, options);
174
+ * const context = await browser.newContext();
175
+ * const page = await context.newPage();
176
+ *
177
+ * await page.goto('https://playwright.dev/');
178
+ * await expect(page).toHaveTitle(/Playwright/);
179
+ *
180
+ * await page.close();
181
+ * await context.close();
182
+ * await browser.close();
183
+ * });
184
+ * ```
185
+ */
137
186
  const getConnectOptions = async (options) => {
138
- const playwrightServiceConfig = import_playwrightServiceConfig.PlaywrightServiceConfig.instance;
139
- playwrightServiceConfig.setOptions(options, true);
140
- performOneTimeOperation(options);
141
- playwrightServiceConfig.serviceAuthType = options?.serviceAuthType || import_constants.DefaultConnectOptionsConstants.DEFAULT_SERVICE_AUTH_TYPE;
142
- let token;
143
- if (playwrightServiceConfig.serviceAuthType === import_constants.ServiceAuth.ENTRA_ID) {
144
- if (!options?.credential) {
145
- throw new Error(import_messages.ServiceErrorMessageConstants.NO_CRED_ENTRA_AUTH_ERROR.message);
187
+ const playwrightServiceConfig = playwrightServiceConfig_js_1.PlaywrightServiceConfig.instance;
188
+ playwrightServiceConfig.setOptions(options, true);
189
+ performOneTimeOperation(options);
190
+ playwrightServiceConfig.serviceAuthType =
191
+ options?.serviceAuthType || constants_js_1.DefaultConnectOptionsConstants.DEFAULT_SERVICE_AUTH_TYPE;
192
+ let token;
193
+ if (playwrightServiceConfig.serviceAuthType === constants_js_1.ServiceAuth.ENTRA_ID) {
194
+ if (!options?.credential) {
195
+ throw new Error(messages_js_1.ServiceErrorMessageConstants.NO_CRED_ENTRA_AUTH_ERROR.message);
196
+ }
197
+ playwrightServiceEntra_js_1.default.entraIdAccessToken = options.credential;
198
+ token = await (0, utils_js_1.fetchOrValidateAccessToken)(options.credential);
199
+ }
200
+ else if (playwrightServiceConfig.serviceAuthType === constants_js_1.ServiceAuth.ACCESS_TOKEN) {
201
+ (0, utils_js_1.validateMptPAT)(utils_js_1.throwErrorWithFailureMessage);
202
+ token = (0, utils_js_1.getAccessToken)();
146
203
  }
147
- import_playwrightServiceEntra.default.entraIdAccessToken = options.credential;
148
- token = await (0, import_utils.fetchOrValidateAccessToken)(options.credential);
149
- } else if (playwrightServiceConfig.serviceAuthType === import_constants.ServiceAuth.ACCESS_TOKEN) {
150
- (0, import_utils.validateMptPAT)(import_utils.throwErrorWithFailureMessage);
151
- token = (0, import_utils.getAccessToken)();
152
- } else {
153
- throw new Error(import_messages.ServiceErrorMessageConstants.INVALID_AUTH_TYPE_ERROR.message);
154
- }
155
- if (!token) {
156
- throw new Error(import_messages.ServiceErrorMessageConstants.NO_AUTH_ERROR_PAT_TOKEN.message);
157
- }
158
- return {
159
- wsEndpoint: (0, import_utils.getServiceWSEndpoint)(
160
- playwrightServiceConfig.runId,
161
- playwrightServiceConfig.serviceOs,
162
- playwrightServiceConfig.apiVersion
163
- ),
164
- options: {
165
- headers: {
166
- Authorization: `Bearer ${token}`,
167
- "x-ms-package-version": `@azure/playwright/${(0, import_utils.getPackageVersion)()}`
168
- },
169
- timeout: playwrightServiceConfig.connectTimeout,
170
- exposeNetwork: playwrightServiceConfig.exposeNetwork,
171
- slowMo: playwrightServiceConfig.slowMo
204
+ else {
205
+ throw new Error(messages_js_1.ServiceErrorMessageConstants.INVALID_AUTH_TYPE_ERROR.message);
172
206
  }
173
- };
207
+ if (!token) {
208
+ throw new Error(messages_js_1.ServiceErrorMessageConstants.NO_AUTH_ERROR_PAT_TOKEN.message);
209
+ }
210
+ return {
211
+ wsEndpoint: (0, utils_js_1.getServiceWSEndpoint)(playwrightServiceConfig.runId, playwrightServiceConfig.serviceOs, playwrightServiceConfig.apiVersion),
212
+ options: {
213
+ headers: {
214
+ Authorization: `Bearer ${token}`,
215
+ "x-ms-package-version": `@azure/playwright/${(0, utils_js_1.getPackageVersion)()}`,
216
+ },
217
+ timeout: playwrightServiceConfig.connectTimeout,
218
+ exposeNetwork: playwrightServiceConfig.exposeNetwork,
219
+ slowMo: playwrightServiceConfig.slowMo,
220
+ },
221
+ };
174
222
  };
175
- // Annotate the CommonJS export names for ESM import in node:
176
- 0 && (module.exports = {
177
- createAzurePlaywrightConfig,
178
- getConnectOptions
179
- });
223
+ exports.getConnectOptions = getConnectOptions;
224
+ //# 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\n performOneTimeOperation(options);\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": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAIO;AACP,4BAA2B;AAC3B,qCAAwC;AACxC,oCAAmC;AAEnC,mBAaO;AACP,sBAA6C;AAE7C,oCAA4B;AAE5B,MAAM,0BAA0B,CAAC,YAAuD;AACtF,QAAM,uBACJ,QAAQ,IAAI,8CAA6B,uBAAuB,MAAM;AACxE,MAAI,qBAAsB;AAC1B,UAAQ,IAAI,8CAA6B,uBAAuB,IAAI;AACpE,MAAI,SAAS,oBAAoB,6BAAY,cAAc;AACzD,qDAA+B;AAAA,EACjC;AACF;AAkCA,MAAM,8BAA8B,CAClC,YACA,YACyB;AACzB,8CAA0B;AAC1B,uCAAmB;AAGnB,UAAQ,IAAI,8CAA6B,oBAAoB,IAAI;AACjE,QAAM,4BAAwB,iCAAe,mCAAqB,CAAC;AACnE,QAAM,gCACJ,sBAAsB,SAAS,KAAK,sBAAsB,SAAS;AACrE,MAAI,SAAS,YAAY;AACvB,kCAAAA,QAAuB,qBAAqB,QAAQ;AAAA,EACtD;AASA,MAAI,cAAc,WAAW,aAAa;AACxC,QAAI,OAAO,WAAW,gBAAgB,UAAU;AAC9C,UAAI,+BAA+B;AACjC,8BAAAC,QAAe,cAAc,CAAC,WAAW,WAAW;AAAA,MACtD,OAAO;AACL,8BAAAA,QAAe,cAAc,WAAW;AAAA,MAC1C;AAAA,IACF,OAAO;AACL,UAAI,CAAC,+BAA+B;AAClC,cAAM,IAAI;AAAA,UACR,6CAA6B,6CAA6C;AAAA,QAC5E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B,yBAAqB,gCAAkB,CAAC;AAAA,MAClE;AAAA,MACA,SAAS,wBAAwB;AAAA,MACjC,eAAe,wBAAwB;AAAA,MACvC,QAAQ,wBAAwB;AAAA,IAClC;AAAA,EACF;AACF;",
6
- "names": ["playwrightServiceEntra", "customerConfig"]
7
- }
1
+ {"version":3,"file":"playwrightService.js","sourceRoot":"","sources":["../../../src/core/playwrightService.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;;AAElC,yDAIgC;AAChC,4FAAyD;AACzD,qFAA+E;AAC/E,oGAAiE;AAEjE,gDAa2B;AAC3B,uDAAqE;AAErE,2EAA0D;AAE1D,MAAM,uBAAuB,GAAG,CAAC,OAA4C,EAAQ,EAAE;IACrF,MAAM,oBAAoB,GACxB,OAAO,CAAC,GAAG,CAAC,2CAA4B,CAAC,uBAAuB,CAAC,KAAK,MAAM,CAAC;IAC/E,IAAI,oBAAoB;QAAE,OAAO;IACjC,OAAO,CAAC,GAAG,CAAC,2CAA4B,CAAC,uBAAuB,CAAC,GAAG,MAAM,CAAC;IAC3E,IAAI,OAAO,EAAE,eAAe,KAAK,0BAAW,CAAC,YAAY,EAAE,CAAC;QAC1D,IAAA,yCAA8B,GAAE,CAAC;IACnC,CAAC;AACH,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,2BAA2B,GAAG,CAClC,UAAgC,EAChC,OAA4C,EACtB,EAAE;IACxB,IAAA,oCAAyB,GAAE,CAAC;IAC5B,IAAA,6BAAkB,GAAE,CAAC;IAErB,oEAAoE;IACpE,OAAO,CAAC,GAAG,CAAC,2CAA4B,CAAC,oBAAoB,CAAC,GAAG,MAAM,CAAC;IACxE,MAAM,qBAAqB,GAAG,IAAA,yBAAc,EAAC,IAAA,+BAAoB,GAAE,CAAC,CAAC;IACrE,MAAM,6BAA6B,GACjC,qBAAqB,CAAC,KAAK,IAAI,CAAC,IAAI,qBAAqB,CAAC,KAAK,IAAI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K,0BAAW,CAAC,QAAQ,EAAE,CAAC;QACrE,IAAI,CAAC,OAAO,EAAE,UAAU,EAAE,CAAC;YACzB,MAAM,IAAI,KAAK,CAAC,0CAA4B,CAAC,wBAAwB,CAAC,OAAO,CAAC,CAAC;QACjF,CAAC;QACD,mCAAsB,CAAC,kBAAkB,GAAG,OAAO,CAAC,UAAU,CAAC;QAC/D,KAAK,GAAG,MAAM,IAAA,qCAA0B,EAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAC/D,CAAC;SAAM,IAAI,uBAAuB,CAAC,eAAe,KAAK,0BAAW,CAAC,YAAY,EAAE,CAAC;QAChF,IAAA,yBAAc,EAAC,uCAA4B,CAAC,CAAC;QAC7C,KAAK,GAAG,IAAA,yBAAc,GAAE,CAAC;IAC3B,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CAAC,0CAA4B,CAAC,uBAAuB,CAAC,OAAO,CAAC,CAAC;IAChF,CAAC;IAED,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,0CAA4B,CAAC,uBAAuB,CAAC,OAAO,CAAC,CAAC;IAChF,CAAC;IAED,OAAO;QACL,UAAU,EAAE,IAAA,+BAAoB,EAC9B,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,IAAA,4BAAiB,GAAE,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;AAEoC,8CAAiB","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"]}