@azure/create-playwright 1.0.0-alpha.20250605.1

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 (61) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +54 -0
  3. package/dist/commonjs/bin/init.d.ts +2 -0
  4. package/dist/commonjs/bin/init.d.ts.map +1 -0
  5. package/dist/commonjs/bin/init.js +23 -0
  6. package/dist/commonjs/bin/init.js.map +1 -0
  7. package/dist/commonjs/constants.d.ts +19 -0
  8. package/dist/commonjs/constants.d.ts.map +1 -0
  9. package/dist/commonjs/constants.js +23 -0
  10. package/dist/commonjs/constants.js.map +1 -0
  11. package/dist/commonjs/index.d.ts +3 -0
  12. package/dist/commonjs/index.d.ts.map +1 -0
  13. package/dist/commonjs/index.js +13 -0
  14. package/dist/commonjs/index.js.map +1 -0
  15. package/dist/commonjs/initialize.d.ts +16 -0
  16. package/dist/commonjs/initialize.d.ts.map +1 -0
  17. package/dist/commonjs/initialize.js +109 -0
  18. package/dist/commonjs/initialize.js.map +1 -0
  19. package/dist/commonjs/package.json +3 -0
  20. package/dist/commonjs/packageManager.d.ts +17 -0
  21. package/dist/commonjs/packageManager.d.ts.map +1 -0
  22. package/dist/commonjs/packageManager.js +56 -0
  23. package/dist/commonjs/packageManager.js.map +1 -0
  24. package/dist/commonjs/types.d.ts +17 -0
  25. package/dist/commonjs/types.d.ts.map +1 -0
  26. package/dist/commonjs/types.js +5 -0
  27. package/dist/commonjs/types.js.map +1 -0
  28. package/dist/commonjs/utils.d.ts +8 -0
  29. package/dist/commonjs/utils.d.ts.map +1 -0
  30. package/dist/commonjs/utils.js +102 -0
  31. package/dist/commonjs/utils.js.map +1 -0
  32. package/dist/esm/bin/init.d.ts +2 -0
  33. package/dist/esm/bin/init.d.ts.map +1 -0
  34. package/dist/esm/bin/init.js +19 -0
  35. package/dist/esm/bin/init.js.map +1 -0
  36. package/dist/esm/constants.d.ts +19 -0
  37. package/dist/esm/constants.d.ts.map +1 -0
  38. package/dist/esm/constants.js +20 -0
  39. package/dist/esm/constants.js.map +1 -0
  40. package/dist/esm/index.d.ts +3 -0
  41. package/dist/esm/index.d.ts.map +1 -0
  42. package/dist/esm/index.js +11 -0
  43. package/dist/esm/index.js.map +1 -0
  44. package/dist/esm/initialize.d.ts +16 -0
  45. package/dist/esm/initialize.d.ts.map +1 -0
  46. package/dist/esm/initialize.js +104 -0
  47. package/dist/esm/initialize.js.map +1 -0
  48. package/dist/esm/package.json +3 -0
  49. package/dist/esm/packageManager.d.ts +17 -0
  50. package/dist/esm/packageManager.d.ts.map +1 -0
  51. package/dist/esm/packageManager.js +49 -0
  52. package/dist/esm/packageManager.js.map +1 -0
  53. package/dist/esm/types.d.ts +17 -0
  54. package/dist/esm/types.d.ts.map +1 -0
  55. package/dist/esm/types.js +4 -0
  56. package/dist/esm/types.js.map +1 -0
  57. package/dist/esm/utils.d.ts +8 -0
  58. package/dist/esm/utils.d.ts.map +1 -0
  59. package/dist/esm/utils.js +92 -0
  60. package/dist/esm/utils.js.map +1 -0
  61. package/package.json +105 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) Microsoft Corporation.
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # Azure Playwright preview
2
+
3
+ Azure Playwright is a fully managed service that uses the cloud to enable you to run Playwright tests with much higher parallelization across different operating system-browser combinations simultaneously. This means faster test runs with broader scenario coverage, which helps speed up delivery of features without sacrificing quality. The service also enables you to publish test results and related artifacts to the service and view them in the service portal enabling faster and easier troubleshooting. With Azure Playwright service, you can release features faster and more confidently.
4
+
5
+ ## Usage
6
+
7
+ Get started with Azure Playwright with a single command
8
+
9
+ ```sh
10
+ npm init @azure/playwright@latest
11
+ # Or for Yarn
12
+ yarn create @azure/playwright
13
+ # Or for pnpm
14
+ pnpm create @azure/playwright
15
+ ```
16
+
17
+ ## Useful Links
18
+ - [Quickstart: Run end-to-end tests at scale](https://aka.ms/mpt/quickstart)
19
+ - [Quickstart: Set up continuous end-to-end testing across different browsers and operating systems](https://aka.ms/mpt/ci)
20
+ - [Explore features and benefits](https://aka.ms/mpt/about)
21
+ - [View Azure Playwright service demo](https://youtu.be/GenC1jAeTZE)
22
+ - [Documentation](https://aka.ms/mpt/docs)
23
+ - [Pricing](https://aka.ms/mpt/pricing)
24
+ - [Share feedback](https://aka.ms/mpt/feedback)
25
+
26
+ ## Next steps
27
+
28
+ - Run tests in a [CI/CD pipeline.](https://aka.ms/mpt/configure-pipeline)
29
+
30
+ - Learn how to [manage access](https://aka.ms/mpt/manage-access) to the created workspace.
31
+
32
+ - Experiment with different number of workers to [determine the optimal configuration of your test suite](https://aka.ms/mpt/parallelism).
33
+
34
+ ## Contributing
35
+
36
+ This project welcomes contributions and suggestions. Most contributions require you to agree to a
37
+ Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
38
+ the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
39
+
40
+ When you submit a pull request, a CLA bot will automatically determine whether you need to provide
41
+ a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions
42
+ provided by the bot. You will only need to do this once across all repos using our CLA.
43
+
44
+ This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
45
+ For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
46
+ contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
47
+
48
+ ## Trademarks
49
+
50
+ This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft
51
+ trademarks or logos is subject to and must follow
52
+ [Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/legal/intellectualproperty/trademarks/usage/general).
53
+ Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
54
+ Any use of third-party trademarks or logos is subject to those third-party's policies.
@@ -0,0 +1,2 @@
1
+ export declare const init: () => Promise<void>;
2
+ //# sourceMappingURL=init.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../src/bin/init.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,IAAI,QAAa,OAAO,CAAC,IAAI,CAkBzC,CAAC"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.init = void 0;
6
+ const initialize_js_1 = require("../initialize.js");
7
+ const utils_js_1 = require("../utils.js");
8
+ const init = async () => {
9
+ const options = (0, utils_js_1.parseCLIArguments)();
10
+ const { config: playwrightConfigFile } = options;
11
+ let playwrightServiceInitConfig;
12
+ if (playwrightConfigFile) {
13
+ playwrightServiceInitConfig = Object.assign({}, (0, utils_js_1.getLanguageAndConfigInfoFromConfigurationFile)(playwrightConfigFile));
14
+ }
15
+ else {
16
+ playwrightServiceInitConfig = Object.assign({}, (0, utils_js_1.getLanguageAndConfigInfoFromDirectory)());
17
+ }
18
+ console.log("");
19
+ const playwrightServiceInitialize = new initialize_js_1.PlaywrightServiceInitialize(playwrightServiceInitConfig);
20
+ await playwrightServiceInitialize.addServiceSupportToTestSuite();
21
+ };
22
+ exports.init = init;
23
+ //# sourceMappingURL=init.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.js","sourceRoot":"","sources":["../../../src/bin/init.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAGlC,oDAA+D;AAC/D,0CAIqB;AAEd,MAAM,IAAI,GAAG,KAAK,IAAmB,EAAE;IAC5C,MAAM,OAAO,GAAG,IAAA,4BAAiB,GAAE,CAAC;IACpC,MAAM,EAAE,MAAM,EAAE,oBAAoB,EAAE,GAAG,OAAO,CAAC;IACjD,IAAI,2BAAwD,CAAC;IAE7D,IAAI,oBAAoB,EAAE,CAAC;QACzB,2BAA2B,qBACtB,IAAA,wDAA6C,EAAC,oBAAoB,CAAC,CACvE,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,2BAA2B,qBACtB,IAAA,gDAAqC,GAAE,CAC3C,CAAC;IACJ,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChB,MAAM,2BAA2B,GAAG,IAAI,2CAA2B,CAAC,2BAA2B,CAAC,CAAC;IACjG,MAAM,2BAA2B,CAAC,4BAA4B,EAAE,CAAC;AACnE,CAAC,CAAC;AAlBW,QAAA,IAAI,QAkBf","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { PlaywrightServiceInitConfig } from \"../types.js\";\nimport { PlaywrightServiceInitialize } from \"../initialize.js\";\nimport {\n getLanguageAndConfigInfoFromConfigurationFile,\n getLanguageAndConfigInfoFromDirectory,\n parseCLIArguments,\n} from \"../utils.js\";\n\nexport const init = async (): Promise<void> => {\n const options = parseCLIArguments();\n const { config: playwrightConfigFile } = options;\n let playwrightServiceInitConfig: PlaywrightServiceInitConfig;\n\n if (playwrightConfigFile) {\n playwrightServiceInitConfig = {\n ...getLanguageAndConfigInfoFromConfigurationFile(playwrightConfigFile),\n };\n } else {\n playwrightServiceInitConfig = {\n ...getLanguageAndConfigInfoFromDirectory(),\n };\n }\n\n console.log(\"\");\n const playwrightServiceInitialize = new PlaywrightServiceInitialize(playwrightServiceInitConfig);\n await playwrightServiceInitialize.addServiceSupportToTestSuite();\n};\n"]}
@@ -0,0 +1,19 @@
1
+ import type { Language } from "./types.js";
2
+ export declare const Languages: {
3
+ TypeScript: Language;
4
+ JavaScript: Language;
5
+ };
6
+ export declare const Extensions: {
7
+ TypeScript: string;
8
+ JavaScript: string;
9
+ };
10
+ export declare const ErrorMessages: {
11
+ NO_CONFIGURATION_FILE_FOUND: string;
12
+ UNSUPPORTED_CONFIGURATION_FILE: string;
13
+ };
14
+ export declare const Messages: {
15
+ CAN_OVERRIDE_MESSAGE: string;
16
+ CONFIRMATION_FOR_EXIT_MESSAGE: string;
17
+ SETUP_PROCESS_EXIT_MESSAGE: string;
18
+ };
19
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,eAAO,MAAM,SAAS;gBACQ,QAAQ;gBACR,QAAQ;CACrC,CAAC;AAEF,eAAO,MAAM,UAAU;;;CAGtB,CAAC;AAEF,eAAO,MAAM,aAAa;;;CAIzB,CAAC;AAEF,eAAO,MAAM,QAAQ;;;;CAMpB,CAAC"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.Messages = exports.ErrorMessages = exports.Extensions = exports.Languages = void 0;
6
+ exports.Languages = {
7
+ TypeScript: "TypeScript",
8
+ JavaScript: "JavaScript",
9
+ };
10
+ exports.Extensions = {
11
+ TypeScript: ".ts",
12
+ JavaScript: ".js",
13
+ };
14
+ exports.ErrorMessages = {
15
+ NO_CONFIGURATION_FILE_FOUND: "Could not find a playwright configuration file in the current directory. Please use --config parameter to specify the configuration file.",
16
+ UNSUPPORTED_CONFIGURATION_FILE: "The playwright configuration file passed is not supported.",
17
+ };
18
+ exports.Messages = {
19
+ CAN_OVERRIDE_MESSAGE: "There's already a playwright service configuration file present. Do you want to overwrite it?",
20
+ CONFIRMATION_FOR_EXIT_MESSAGE: "You won't be able to install and setup up the service without overwriting the existing configuration file. Do you still want to exit the setup process?",
21
+ SETUP_PROCESS_EXIT_MESSAGE: "Exiting the service setup process.",
22
+ };
23
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAIrB,QAAA,SAAS,GAAG;IACvB,UAAU,EAAE,YAAwB;IACpC,UAAU,EAAE,YAAwB;CACrC,CAAC;AAEW,QAAA,UAAU,GAAG;IACxB,UAAU,EAAE,KAAK;IACjB,UAAU,EAAE,KAAK;CAClB,CAAC;AAEW,QAAA,aAAa,GAAG;IAC3B,2BAA2B,EACzB,2IAA2I;IAC7I,8BAA8B,EAAE,4DAA4D;CAC7F,CAAC;AAEW,QAAA,QAAQ,GAAG;IACtB,oBAAoB,EAClB,+FAA+F;IACjG,6BAA6B,EAC3B,yJAAyJ;IAC3J,0BAA0B,EAAE,oCAAoC;CACjE,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { Language } from \"./types.js\";\n\nexport const Languages = {\n TypeScript: \"TypeScript\" as Language,\n JavaScript: \"JavaScript\" as Language,\n};\n\nexport const Extensions = {\n TypeScript: \".ts\",\n JavaScript: \".js\",\n};\n\nexport const ErrorMessages = {\n NO_CONFIGURATION_FILE_FOUND:\n \"Could not find a playwright configuration file in the current directory. Please use --config parameter to specify the configuration file.\",\n UNSUPPORTED_CONFIGURATION_FILE: \"The playwright configuration file passed is not supported.\",\n};\n\nexport const Messages = {\n CAN_OVERRIDE_MESSAGE:\n \"There's already a playwright service configuration file present. Do you want to overwrite it?\",\n CONFIRMATION_FOR_EXIT_MESSAGE:\n \"You won't be able to install and setup up the service without overwriting the existing configuration file. Do you still want to exit the setup process?\",\n SETUP_PROCESS_EXIT_MESSAGE: \"Exiting the service setup process.\",\n};\n"]}
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ // Copyright (c) Microsoft Corporation.
4
+ // Licensed under the MIT License.
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const init_js_1 = require("./bin/init.js");
7
+ (async () => {
8
+ await (0, init_js_1.init)();
9
+ })().catch((err) => {
10
+ console.error(err);
11
+ process.exit(1);
12
+ });
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;AAEA,uCAAuC;AACvC,kCAAkC;;AAElC,2CAAqC;AAErC,CAAC,KAAK,IAAI,EAAE;IACV,MAAM,IAAA,cAAI,GAAE,CAAC;AACf,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACjB,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC","sourcesContent":["#!/usr/bin/env node\n\n// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { init } from \"./bin/init.js\";\n\n(async () => {\n await init();\n})().catch((err) => {\n console.error(err);\n process.exit(1);\n});\n"]}
@@ -0,0 +1,16 @@
1
+ import type { PlaywrightServiceInitConfig } from "./types.js";
2
+ export declare class PlaywrightServiceInitialize {
3
+ private _setupConfig;
4
+ private _packageManager;
5
+ constructor(setupConfig: PlaywrightServiceInitConfig);
6
+ addServiceSupportToTestSuite: () => Promise<void>;
7
+ private checkIfServiceConfigCanBeAdded;
8
+ private promptOnCancel;
9
+ private isServiceConfigFileAlreadyPresent;
10
+ private displayAdditionalInformation;
11
+ private installServicePackage;
12
+ private createServiceConfig;
13
+ private getServiceConfigContent;
14
+ private getServiceConfigFileName;
15
+ }
16
+ //# sourceMappingURL=initialize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initialize.d.ts","sourceRoot":"","sources":["../../src/initialize.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAGV,2BAA2B,EAC5B,MAAM,YAAY,CAAC;AAmBpB,qBAAa,2BAA2B;IACtC,OAAO,CAAC,YAAY,CAA8B;IAClD,OAAO,CAAC,eAAe,CAAiB;gBAE5B,WAAW,EAAE,2BAA2B;IAK7C,4BAA4B,QAAa,OAAO,CAAC,IAAI,CAAC,CAM3D;IAEF,OAAO,CAAC,8BAA8B,CAUpC;IAEF,OAAO,CAAC,cAAc,CAEpB;IAEF,OAAO,CAAC,iCAAiC,CAEvC;IAEF,OAAO,CAAC,4BAA4B,CAclC;IAEF,OAAO,CAAC,qBAAqB,CAI3B;IAEF,OAAO,CAAC,mBAAmB,CAKzB;IAEF,OAAO,CAAC,uBAAuB,CAmC7B;IAEF,OAAO,CAAC,wBAAwB,CAE9B;CACH"}
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.PlaywrightServiceInitialize = void 0;
6
+ const tslib_1 = require("tslib");
7
+ const prompts_1 = tslib_1.__importDefault(require("prompts"));
8
+ const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
9
+ const constants_js_1 = require("./constants.js");
10
+ const utils_js_1 = require("./utils.js");
11
+ const packageManager_js_1 = require("./packageManager.js");
12
+ const questions = [
13
+ {
14
+ type: "confirm",
15
+ name: "canOverride",
16
+ message: constants_js_1.Messages.CAN_OVERRIDE_MESSAGE,
17
+ initial: true,
18
+ },
19
+ {
20
+ type: (prev) => (prev ? null : "confirm"),
21
+ name: "confirmationForExit",
22
+ message: constants_js_1.Messages.CONFIRMATION_FOR_EXIT_MESSAGE,
23
+ initial: true,
24
+ },
25
+ ];
26
+ class PlaywrightServiceInitialize {
27
+ constructor(setupConfig) {
28
+ this.addServiceSupportToTestSuite = async () => {
29
+ const canProceedWithServiceInitialization = await this.checkIfServiceConfigCanBeAdded(); // if service config already present, ask user for overwrite permission
30
+ if (!canProceedWithServiceInitialization)
31
+ return;
32
+ await this.installServicePackage(); // install service packages
33
+ await this.createServiceConfig(); // create service config file
34
+ this.displayAdditionalInformation(); // display additional information
35
+ };
36
+ this.checkIfServiceConfigCanBeAdded = async () => {
37
+ if (!this.isServiceConfigFileAlreadyPresent())
38
+ return true;
39
+ const response = (await prompts_1.default.prompt(questions, {
40
+ onCancel: this.promptOnCancel,
41
+ }));
42
+ if (response.canOverride)
43
+ return true;
44
+ if (!response.confirmationForExit)
45
+ return this.checkIfServiceConfigCanBeAdded();
46
+ console.log(`\n${constants_js_1.Messages.SETUP_PROCESS_EXIT_MESSAGE}`);
47
+ return false;
48
+ };
49
+ this.promptOnCancel = () => {
50
+ process.exit(0);
51
+ };
52
+ this.isServiceConfigFileAlreadyPresent = () => {
53
+ return node_fs_1.default.existsSync(this.getServiceConfigFileName());
54
+ };
55
+ this.displayAdditionalInformation = () => {
56
+ const runCommandParallelWorkers = this._packageManager.runCommand("playwright", `test -c ${this.getServiceConfigFileName()} --workers=20`);
57
+ console.log(`\n\nTo run playwrights tests using Playwright Service\n`);
58
+ console.log(`\t${runCommandParallelWorkers}\n`);
59
+ console.log("Getting Started - https://aka.ms/mpt/quickstart\n");
60
+ console.log("If you're already using the Azure Playwright service, please review the quickstart guide [https://aka.ms/mpt/quickstart] to ensure your tests continue running smoothly.");
61
+ };
62
+ this.installServicePackage = async () => {
63
+ const command = this._packageManager.installDevDependencyCommand("@azure/playwright");
64
+ console.log(`Installing Service package (${command})`);
65
+ await (0, utils_js_1.executeCommand)(command);
66
+ };
67
+ this.createServiceConfig = async () => {
68
+ const serviceConfigFile = this.getServiceConfigFileName();
69
+ const serviceConfigFileContent = this.getServiceConfigContent();
70
+ await node_fs_1.default.promises.writeFile(serviceConfigFile, serviceConfigFileContent);
71
+ console.log(`Success! Created service configuration file - ${serviceConfigFile}`);
72
+ };
73
+ this.getServiceConfigContent = () => {
74
+ const customerConfigFileName = (0, utils_js_1.getFileReferenceForImport)(this._setupConfig.playwrightConfigFile);
75
+ const importCommandTypeScript = `import { defineConfig } from '@playwright/test';
76
+ import { getServiceConfig, ServiceOS } from '@azure/playwright';
77
+ import config from '${customerConfigFileName}';
78
+ `;
79
+ const importCommandJavaScript = `const { defineConfig } = require('@playwright/test');
80
+ const { getServiceConfig, ServiceOS } = require('@azure/playwright');
81
+ const config = require('${customerConfigFileName}');
82
+ `;
83
+ const importCommand = this._setupConfig.projectLanguage === constants_js_1.Languages.TypeScript
84
+ ? importCommandTypeScript
85
+ : importCommandJavaScript;
86
+ const content = importCommand +
87
+ `
88
+ /* Learn more about service configuration at https://aka.ms/mpt/config */
89
+ export default defineConfig(
90
+ config,
91
+ getServiceConfig(config, {
92
+ exposeNetwork: '<loopback>',
93
+ timeout: 30000,
94
+ os: ServiceOS.LINUX,
95
+ useCloudHostedBrowsers: true
96
+ })
97
+ );
98
+ `;
99
+ return content;
100
+ };
101
+ this.getServiceConfigFileName = () => {
102
+ return "playwright.service.config" + constants_js_1.Extensions[this._setupConfig.projectLanguage];
103
+ };
104
+ this._setupConfig = setupConfig;
105
+ this._packageManager = (0, packageManager_js_1.getPackageManager)();
106
+ }
107
+ }
108
+ exports.PlaywrightServiceInitialize = PlaywrightServiceInitialize;
109
+ //# sourceMappingURL=initialize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../src/initialize.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;;AAGlC,8DAA8B;AAC9B,8DAAyB;AACzB,iDAAiE;AAMjE,yCAAuE;AACvE,2DAAwD;AAExD,MAAM,SAAS,GAAmB;IAChC;QACE,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,aAAa;QACnB,OAAO,EAAE,uBAAQ,CAAC,oBAAoB;QACtC,OAAO,EAAE,IAAI;KACd;IACD;QACE,IAAI,EAAE,CAAC,IAAa,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;QAClD,IAAI,EAAE,qBAAqB;QAC3B,OAAO,EAAE,uBAAQ,CAAC,6BAA6B;QAC/C,OAAO,EAAE,IAAI;KACd;CACF,CAAC;AAEF,MAAa,2BAA2B;IAItC,YAAY,WAAwC;QAK7C,iCAA4B,GAAG,KAAK,IAAmB,EAAE;YAC9D,MAAM,mCAAmC,GAAG,MAAM,IAAI,CAAC,8BAA8B,EAAE,CAAC,CAAC,uEAAuE;YAChK,IAAI,CAAC,mCAAmC;gBAAE,OAAO;YACjD,MAAM,IAAI,CAAC,qBAAqB,EAAE,CAAC,CAAC,2BAA2B;YAC/D,MAAM,IAAI,CAAC,mBAAmB,EAAE,CAAC,CAAC,6BAA6B;YAC/D,IAAI,CAAC,4BAA4B,EAAE,CAAC,CAAC,iCAAiC;QACxE,CAAC,CAAC;QAEM,mCAA8B,GAAG,KAAK,IAAsB,EAAE;YACpE,IAAI,CAAC,IAAI,CAAC,iCAAiC,EAAE;gBAAE,OAAO,IAAI,CAAC;YAC3D,MAAM,QAAQ,GAAG,CAAC,MAAM,i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C;QAEM,wBAAmB,GAAG,KAAK,IAAmB,EAAE;YACtD,MAAM,iBAAiB,GAAG,IAAI,CAAC,wBAAwB,EAAE,CAAC;YAC1D,MAAM,wBAAwB,GAAG,IAAI,CAAC,uBAAuB,EAAE,CAAC;YAChE,MAAM,iBAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,iBAAiB,EAAE,wBAAwB,CAAC,CAAC;YACzE,OAAO,CAAC,GAAG,CAAC,iDAAiD,iBAAiB,EAAE,CAAC,CAAC;QACpF,CAAC,CAAC;QAEM,4BAAuB,GAAG,GAAW,EAAE;YAC7C,MAAM,sBAAsB,GAAG,IAAA,oCAAyB,EACtD,IAAI,CAAC,YAAY,CAAC,oBAAoB,CACvC,CAAC;YAEF,MAAM,uBAAuB,GAAG;;sBAEd,sBAAsB;CAC3C,CAAC;YAEE,MAAM,uBAAuB,GAAG;;0BAEV,sBAAsB;CAC/C,CAAC;YAEE,MAAM,aAAa,GACjB,IAAI,CAAC,YAAY,CAAC,eAAe,KAAK,wBAAS,CAAC,UAAU;gBACxD,CAAC,CAAC,uBAAuB;gBACzB,CAAC,CAAC,uBAAuB,CAAC;YAE9B,MAAM,OAAO,GACX,aAAa;gBACb;;;;;;;;;;;CAWL,CAAC;YACE,OAAO,OAAO,CAAC;QACjB,CAAC,CAAC;QAEM,6BAAwB,GAAG,GAAW,EAAE;YAC9C,OAAO,2BAA2B,GAAG,yBAAU,CAAC,IAAI,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC;QACrF,CAAC,CAAC;QApGA,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;QAChC,IAAI,CAAC,eAAe,GAAG,IAAA,qCAAiB,GAAE,CAAC;IAC7C,CAAC;CAmGF;AA1GD,kEA0GC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { PromptObject } from \"prompts\";\nimport prompts from \"prompts\";\nimport fs from \"node:fs\";\nimport { Extensions, Languages, Messages } from \"./constants.js\";\nimport type {\n OverridePromptResponse,\n PackageManager,\n PlaywrightServiceInitConfig,\n} from \"./types.js\";\nimport { executeCommand, getFileReferenceForImport } from \"./utils.js\";\nimport { getPackageManager } from \"./packageManager.js\";\n\nconst questions: PromptObject[] = [\n {\n type: \"confirm\",\n name: \"canOverride\",\n message: Messages.CAN_OVERRIDE_MESSAGE,\n initial: true,\n },\n {\n type: (prev: boolean) => (prev ? null : \"confirm\"),\n name: \"confirmationForExit\",\n message: Messages.CONFIRMATION_FOR_EXIT_MESSAGE,\n initial: true,\n },\n];\n\nexport class PlaywrightServiceInitialize {\n private _setupConfig: PlaywrightServiceInitConfig;\n private _packageManager: PackageManager;\n\n constructor(setupConfig: PlaywrightServiceInitConfig) {\n this._setupConfig = setupConfig;\n this._packageManager = getPackageManager();\n }\n\n public addServiceSupportToTestSuite = async (): Promise<void> => {\n const canProceedWithServiceInitialization = await this.checkIfServiceConfigCanBeAdded(); // if service config already present, ask user for overwrite permission\n if (!canProceedWithServiceInitialization) return;\n await this.installServicePackage(); // install service packages\n await this.createServiceConfig(); // create service config file\n this.displayAdditionalInformation(); // display additional information\n };\n\n private checkIfServiceConfigCanBeAdded = async (): Promise<boolean> => {\n if (!this.isServiceConfigFileAlreadyPresent()) return true;\n const response = (await prompts.prompt(questions, {\n onCancel: this.promptOnCancel,\n })) as OverridePromptResponse;\n if (response.canOverride) return true;\n if (!response.confirmationForExit) return this.checkIfServiceConfigCanBeAdded();\n\n console.log(`\\n${Messages.SETUP_PROCESS_EXIT_MESSAGE}`);\n return false;\n };\n\n private promptOnCancel = (): never => {\n process.exit(0);\n };\n\n private isServiceConfigFileAlreadyPresent = (): boolean => {\n return fs.existsSync(this.getServiceConfigFileName());\n };\n\n private displayAdditionalInformation = (): void => {\n const runCommandParallelWorkers = this._packageManager.runCommand(\n \"playwright\",\n `test -c ${this.getServiceConfigFileName()} --workers=20`,\n );\n\n console.log(`\\n\\nTo run playwrights tests using Playwright Service\\n`);\n console.log(`\\t${runCommandParallelWorkers}\\n`);\n\n console.log(\"Getting Started - https://aka.ms/mpt/quickstart\\n\");\n\n console.log(\n \"If you're already using the Azure Playwright service, please review the quickstart guide [https://aka.ms/mpt/quickstart] to ensure your tests continue running smoothly.\",\n );\n };\n\n private installServicePackage = async (): Promise<void> => {\n const command = this._packageManager.installDevDependencyCommand(\"@azure/playwright\");\n console.log(`Installing Service package (${command})`);\n await executeCommand(command);\n };\n\n private createServiceConfig = async (): Promise<void> => {\n const serviceConfigFile = this.getServiceConfigFileName();\n const serviceConfigFileContent = this.getServiceConfigContent();\n await fs.promises.writeFile(serviceConfigFile, serviceConfigFileContent);\n console.log(`Success! Created service configuration file - ${serviceConfigFile}`);\n };\n\n private getServiceConfigContent = (): string => {\n const customerConfigFileName = getFileReferenceForImport(\n this._setupConfig.playwrightConfigFile,\n );\n\n const importCommandTypeScript = `import { defineConfig } from '@playwright/test';\nimport { getServiceConfig, ServiceOS } from '@azure/playwright';\nimport config from '${customerConfigFileName}';\n`;\n\n const importCommandJavaScript = `const { defineConfig } = require('@playwright/test');\nconst { getServiceConfig, ServiceOS } = require('@azure/playwright');\nconst config = require('${customerConfigFileName}');\n`;\n\n const importCommand =\n this._setupConfig.projectLanguage === Languages.TypeScript\n ? importCommandTypeScript\n : importCommandJavaScript;\n\n const content =\n importCommand +\n `\n/* Learn more about service configuration at https://aka.ms/mpt/config */\nexport default defineConfig(\n config,\n getServiceConfig(config, {\n exposeNetwork: '<loopback>',\n timeout: 30000,\n os: ServiceOS.LINUX,\n useCloudHostedBrowsers: true\n })\n);\n`;\n return content;\n };\n\n private getServiceConfigFileName = (): string => {\n return \"playwright.service.config\" + Extensions[this._setupConfig.projectLanguage];\n };\n}\n"]}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,17 @@
1
+ import type { PackageManager } from "./types.js";
2
+ export declare class NPM implements PackageManager {
3
+ installDevDependencyCommand: (packageName: string) => string;
4
+ runCommand: (command: string, args: string) => string;
5
+ }
6
+ export declare class PNPM implements PackageManager {
7
+ private useWorkspace;
8
+ constructor();
9
+ installDevDependencyCommand: (packageName: string) => string;
10
+ runCommand: (command: string, args: string) => string;
11
+ }
12
+ export declare class Yarn implements PackageManager {
13
+ installDevDependencyCommand: (packageName: string) => string;
14
+ runCommand: (command: string, args: string) => string;
15
+ }
16
+ export declare const getPackageManager: () => PackageManager;
17
+ //# sourceMappingURL=packageManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"packageManager.d.ts","sourceRoot":"","sources":["../../src/packageManager.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAIjD,qBAAa,GAAI,YAAW,cAAc;IACxC,2BAA2B,GAAI,aAAa,MAAM,KAAG,MAAM,CAEzD;IACF,UAAU,GAAI,SAAS,MAAM,EAAE,MAAM,MAAM,KAAG,MAAM,CAElD;CACH;AAED,qBAAa,IAAK,YAAW,cAAc;IACzC,OAAO,CAAC,YAAY,CAAkB;;IAMtC,2BAA2B,GAAI,aAAa,MAAM,KAAG,MAAM,CAEzD;IACF,UAAU,GAAI,SAAS,MAAM,EAAE,MAAM,MAAM,KAAG,MAAM,CAElD;CACH;AAED,qBAAa,IAAK,YAAW,cAAc;IACzC,2BAA2B,GAAI,aAAa,MAAM,KAAG,MAAM,CAEzD;IACF,UAAU,GAAI,SAAS,MAAM,EAAE,MAAM,MAAM,KAAG,MAAM,CAElD;CACH;AAGD,eAAO,MAAM,iBAAiB,QAAO,cAOpC,CAAC"}
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.getPackageManager = exports.Yarn = exports.PNPM = exports.NPM = void 0;
6
+ const node_fs_1 = require("node:fs");
7
+ const node_process_1 = require("node:process");
8
+ const node_path_1 = require("node:path");
9
+ class NPM {
10
+ constructor() {
11
+ this.installDevDependencyCommand = (packageName) => {
12
+ return `npm install --save-dev ${packageName}`;
13
+ };
14
+ this.runCommand = (command, args) => {
15
+ return `npx ${command} ${args}`;
16
+ };
17
+ }
18
+ }
19
+ exports.NPM = NPM;
20
+ class PNPM {
21
+ constructor() {
22
+ this.useWorkspace = false;
23
+ this.installDevDependencyCommand = (packageName) => {
24
+ return `pnpm add --save-dev ${this.useWorkspace ? "-w " : ""}${packageName}`;
25
+ };
26
+ this.runCommand = (command, args) => {
27
+ return `pnpm ${command} ${args}`;
28
+ };
29
+ this.useWorkspace = (0, node_fs_1.existsSync)((0, node_path_1.resolve)((0, node_process_1.cwd)(), "pnpm-workspace.yaml"));
30
+ }
31
+ }
32
+ exports.PNPM = PNPM;
33
+ class Yarn {
34
+ constructor() {
35
+ this.installDevDependencyCommand = (packageName) => {
36
+ return `yarn add --dev ${packageName}`;
37
+ };
38
+ this.runCommand = (command, args) => {
39
+ return `yarn ${command} ${args}`;
40
+ };
41
+ }
42
+ }
43
+ exports.Yarn = Yarn;
44
+ // https://stackoverflow.com/questions/68133683/is-there-a-cross-platform-way-to-get-the-name-of-the-parent-process-in-node-js
45
+ const getPackageManager = () => {
46
+ if (process.env["npm_config_user_agent"]) {
47
+ const userAgent = process.env["npm_config_user_agent"];
48
+ if (userAgent.includes("yarn"))
49
+ return new Yarn();
50
+ if (userAgent.includes("pnpm"))
51
+ return new PNPM();
52
+ }
53
+ return new NPM();
54
+ };
55
+ exports.getPackageManager = getPackageManager;
56
+ //# sourceMappingURL=packageManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"packageManager.js","sourceRoot":"","sources":["../../src/packageManager.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,qCAAqC;AAErC,+CAAmC;AACnC,yCAAoC;AAEpC,MAAa,GAAG;IAAhB;QACE,gCAA2B,GAAG,CAAC,WAAmB,EAAU,EAAE;YAC5D,OAAO,0BAA0B,WAAW,EAAE,CAAC;QACjD,CAAC,CAAC;QACF,eAAU,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M,CAAC;YAAE,OAAO,IAAI,IAAI,EAAE,CAAC;IACpD,CAAC;IACD,OAAO,IAAI,GAAG,EAAE,CAAC;AACnB,CAAC,CAAC;AAPW,QAAA,iBAAiB,qBAO5B","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { existsSync } from \"node:fs\";\nimport type { PackageManager } from \"./types.js\";\nimport { cwd } from \"node:process\";\nimport { resolve } from \"node:path\";\n\nexport class NPM implements PackageManager {\n installDevDependencyCommand = (packageName: string): string => {\n return `npm install --save-dev ${packageName}`;\n };\n runCommand = (command: string, args: string): string => {\n return `npx ${command} ${args}`;\n };\n}\n\nexport class PNPM implements PackageManager {\n private useWorkspace: boolean = false;\n\n constructor() {\n this.useWorkspace = existsSync(resolve(cwd(), \"pnpm-workspace.yaml\"));\n }\n\n installDevDependencyCommand = (packageName: string): string => {\n return `pnpm add --save-dev ${this.useWorkspace ? \"-w \" : \"\"}${packageName}`;\n };\n runCommand = (command: string, args: string): string => {\n return `pnpm ${command} ${args}`;\n };\n}\n\nexport class Yarn implements PackageManager {\n installDevDependencyCommand = (packageName: string): string => {\n return `yarn add --dev ${packageName}`;\n };\n runCommand = (command: string, args: string): string => {\n return `yarn ${command} ${args}`;\n };\n}\n\n// https://stackoverflow.com/questions/68133683/is-there-a-cross-platform-way-to-get-the-name-of-the-parent-process-in-node-js\nexport const getPackageManager = (): PackageManager => {\n if (process.env[\"npm_config_user_agent\"]) {\n const userAgent = process.env[\"npm_config_user_agent\"];\n if (userAgent.includes(\"yarn\")) return new Yarn();\n if (userAgent.includes(\"pnpm\")) return new PNPM();\n }\n return new NPM();\n};\n"]}
@@ -0,0 +1,17 @@
1
+ export type Language = "TypeScript" | "JavaScript";
2
+ export type PlaywrightServiceInitConfig = {
3
+ projectLanguage: Language;
4
+ playwrightConfigFile: string;
5
+ };
6
+ export type CLIArguments = {
7
+ config: string;
8
+ };
9
+ export type OverridePromptResponse = {
10
+ canOverride: boolean;
11
+ confirmationForExit: boolean;
12
+ };
13
+ export type PackageManager = {
14
+ installDevDependencyCommand: (packageName: string) => string;
15
+ runCommand: (command: string, args: string) => string;
16
+ };
17
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,QAAQ,GAAG,YAAY,GAAG,YAAY,CAAC;AAEnD,MAAM,MAAM,2BAA2B,GAAG;IACxC,eAAe,EAAE,QAAQ,CAAC;IAC1B,oBAAoB,EAAE,MAAM,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,WAAW,EAAE,OAAO,CAAC;IACrB,mBAAmB,EAAE,OAAO,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,2BAA2B,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,MAAM,CAAC;IAC7D,UAAU,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;CACvD,CAAC"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nexport type Language = \"TypeScript\" | \"JavaScript\";\n\nexport type PlaywrightServiceInitConfig = {\n projectLanguage: Language;\n playwrightConfigFile: string;\n};\n\nexport type CLIArguments = {\n config: string;\n};\n\nexport type OverridePromptResponse = {\n canOverride: boolean;\n confirmationForExit: boolean;\n};\n\nexport type PackageManager = {\n installDevDependencyCommand: (packageName: string) => string;\n runCommand: (command: string, args: string) => string;\n};\n"]}
@@ -0,0 +1,8 @@
1
+ import type { CLIArguments, PlaywrightServiceInitConfig } from "./types.js";
2
+ export declare const executeCommand: (command: string) => Promise<string>;
3
+ export declare const getLanguageAndConfigInfoFromDirectory: () => PlaywrightServiceInitConfig;
4
+ export declare const getLanguageAndConfigInfoFromConfigurationFile: (playwrightConfigFile: string) => PlaywrightServiceInitConfig;
5
+ export declare const getFileReferenceForImport: (filePath: string) => string;
6
+ export declare const showHelpForCLI: () => string;
7
+ export declare const parseCLIArguments: () => CLIArguments;
8
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAC;AAG5E,eAAO,MAAM,cAAc,GAAI,SAAS,MAAM,KAAG,OAAO,CAAC,MAAM,CAU9D,CAAC;AAEF,eAAO,MAAM,qCAAqC,QAAO,2BAcxD,CAAC;AAEF,eAAO,MAAM,6CAA6C,GACxD,sBAAsB,MAAM,KAC3B,2BAaF,CAAC;AAEF,eAAO,MAAM,yBAAyB,GAAI,UAAU,MAAM,KAAG,MAW5D,CAAC;AAEF,eAAO,MAAM,cAAc,QAAO,MAUjC,CAAC;AAEF,eAAO,MAAM,iBAAiB,QAAO,YAcpC,CAAC"}
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.parseCLIArguments = exports.showHelpForCLI = exports.getFileReferenceForImport = exports.getLanguageAndConfigInfoFromConfigurationFile = exports.getLanguageAndConfigInfoFromDirectory = exports.executeCommand = void 0;
6
+ const tslib_1 = require("tslib");
7
+ const node_child_process_1 = require("node:child_process");
8
+ const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
9
+ const node_path_1 = tslib_1.__importStar(require("node:path"));
10
+ const constants_js_1 = require("./constants.js");
11
+ const executeCommand = (command) => {
12
+ return new Promise((resolve, reject) => {
13
+ (0, node_child_process_1.exec)(command, (error, stdout, _) => {
14
+ if (error) {
15
+ reject(error);
16
+ }
17
+ else {
18
+ resolve(stdout);
19
+ }
20
+ });
21
+ });
22
+ };
23
+ exports.executeCommand = executeCommand;
24
+ const getLanguageAndConfigInfoFromDirectory = () => {
25
+ if (node_fs_1.default.existsSync("playwright.config.js")) {
26
+ return {
27
+ playwrightConfigFile: "playwright.config.js",
28
+ projectLanguage: constants_js_1.Languages.JavaScript,
29
+ };
30
+ }
31
+ else if (node_fs_1.default.existsSync("playwright.config.ts")) {
32
+ return {
33
+ playwrightConfigFile: "playwright.config.ts",
34
+ projectLanguage: constants_js_1.Languages.TypeScript,
35
+ };
36
+ }
37
+ else {
38
+ throw new Error(constants_js_1.ErrorMessages.NO_CONFIGURATION_FILE_FOUND);
39
+ }
40
+ };
41
+ exports.getLanguageAndConfigInfoFromDirectory = getLanguageAndConfigInfoFromDirectory;
42
+ const getLanguageAndConfigInfoFromConfigurationFile = (playwrightConfigFile) => {
43
+ const extension = (0, node_path_1.extname)(playwrightConfigFile);
44
+ if (extension === constants_js_1.Extensions.TypeScript) {
45
+ return {
46
+ playwrightConfigFile,
47
+ projectLanguage: constants_js_1.Languages.TypeScript,
48
+ };
49
+ }
50
+ else if (extension === constants_js_1.Extensions.JavaScript) {
51
+ return {
52
+ playwrightConfigFile,
53
+ projectLanguage: constants_js_1.Languages.JavaScript,
54
+ };
55
+ }
56
+ else
57
+ throw new Error(constants_js_1.ErrorMessages.UNSUPPORTED_CONFIGURATION_FILE);
58
+ };
59
+ exports.getLanguageAndConfigInfoFromConfigurationFile = getLanguageAndConfigInfoFromConfigurationFile;
60
+ const getFileReferenceForImport = (filePath) => {
61
+ const normalizedPath = filePath.split(node_path_1.default.sep).join("/");
62
+ const parsedPath = node_path_1.default.parse(normalizedPath);
63
+ const withoutExtension = node_path_1.default.posix.join(parsedPath.dir, parsedPath.name);
64
+ if (node_path_1.default.isAbsolute(filePath)) {
65
+ return withoutExtension;
66
+ }
67
+ if (!withoutExtension.startsWith("./") && !withoutExtension.startsWith("../")) {
68
+ return `./${withoutExtension}`;
69
+ }
70
+ return withoutExtension;
71
+ };
72
+ exports.getFileReferenceForImport = getFileReferenceForImport;
73
+ const showHelpForCLI = () => {
74
+ return `
75
+ Usage: index [options]
76
+
77
+ playwright configuration file
78
+
79
+ Options:
80
+ -c, --config <config>
81
+ -h, --help display help for command
82
+ `;
83
+ };
84
+ exports.showHelpForCLI = showHelpForCLI;
85
+ const parseCLIArguments = () => {
86
+ const args = process.argv.slice(2);
87
+ const cliArguments = {
88
+ config: "",
89
+ };
90
+ for (let i = 0; i < args.length; i++) {
91
+ if (args[i] === "-c" || args[i] === "--config") {
92
+ cliArguments.config = args[i + 1];
93
+ }
94
+ else if (args[i] === "-h" || args[i] === "--help") {
95
+ console.log((0, exports.showHelpForCLI)());
96
+ process.exit(0);
97
+ }
98
+ }
99
+ return cliArguments;
100
+ };
101
+ exports.parseCLIArguments = parseCLIArguments;
102
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;;AAElC,2DAA0C;AAC1C,8DAAyB;AACzB,+DAA0C;AAE1C,iDAAsE;AAE/D,MAAM,cAAc,GAAG,CAAC,OAAe,EAAmB,EAAE;IACjE,OAAO,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC7C,IAAA,yBAAI,EAAC,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE;YACjC,IAAI,KAAK,EAAE,CAAC;gBACV,MAAM,CAAC,KAAK,CAAC,CAAC;YAChB,CAAC;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CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE,CAAC;YACpD,OAAO,CAAC,GAAG,CAAC,IAAA,sBAAc,GAAE,CAAC,CAAC;YAC9B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC,CAAC;AAdW,QAAA,iBAAiB,qBAc5B","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { exec } from \"node:child_process\";\nimport fs from \"node:fs\";\nimport path, { extname } from \"node:path\";\nimport type { CLIArguments, PlaywrightServiceInitConfig } from \"./types.js\";\nimport { ErrorMessages, Extensions, Languages } from \"./constants.js\";\n\nexport const executeCommand = (command: string): Promise<string> => {\n return new Promise<string>((resolve, reject) => {\n exec(command, (error, stdout, _) => {\n if (error) {\n reject(error);\n } else {\n resolve(stdout);\n }\n });\n });\n};\n\nexport const getLanguageAndConfigInfoFromDirectory = (): PlaywrightServiceInitConfig => {\n if (fs.existsSync(\"playwright.config.js\")) {\n return {\n playwrightConfigFile: \"playwright.config.js\",\n projectLanguage: Languages.JavaScript,\n };\n } else if (fs.existsSync(\"playwright.config.ts\")) {\n return {\n playwrightConfigFile: \"playwright.config.ts\",\n projectLanguage: Languages.TypeScript,\n };\n } else {\n throw new Error(ErrorMessages.NO_CONFIGURATION_FILE_FOUND);\n }\n};\n\nexport const getLanguageAndConfigInfoFromConfigurationFile = (\n playwrightConfigFile: string,\n): PlaywrightServiceInitConfig => {\n const extension = extname(playwrightConfigFile);\n if (extension === Extensions.TypeScript) {\n return {\n playwrightConfigFile,\n projectLanguage: Languages.TypeScript,\n };\n } else if (extension === Extensions.JavaScript) {\n return {\n playwrightConfigFile,\n projectLanguage: Languages.JavaScript,\n };\n } else throw new Error(ErrorMessages.UNSUPPORTED_CONFIGURATION_FILE);\n};\n\nexport const getFileReferenceForImport = (filePath: string): string => {\n const normalizedPath = filePath.split(path.sep).join(\"/\");\n const parsedPath = path.parse(normalizedPath);\n const withoutExtension = path.posix.join(parsedPath.dir, parsedPath.name);\n if (path.isAbsolute(filePath)) {\n return withoutExtension;\n }\n if (!withoutExtension.startsWith(\"./\") && !withoutExtension.startsWith(\"../\")) {\n return `./${withoutExtension}`;\n }\n return withoutExtension;\n};\n\nexport const showHelpForCLI = (): string => {\n return `\nUsage: index [options]\n\nplaywright configuration file\n\nOptions:\n -c, --config <config>\n -h, --help display help for command\n`;\n};\n\nexport const parseCLIArguments = (): CLIArguments => {\n const args = process.argv.slice(2);\n const cliArguments: CLIArguments = {\n config: \"\",\n };\n for (let i = 0; i < args.length; i++) {\n if (args[i] === \"-c\" || args[i] === \"--config\") {\n cliArguments.config = args[i + 1];\n } else if (args[i] === \"-h\" || args[i] === \"--help\") {\n console.log(showHelpForCLI());\n process.exit(0);\n }\n }\n return cliArguments;\n};\n"]}
@@ -0,0 +1,2 @@
1
+ export declare const init: () => Promise<void>;
2
+ //# sourceMappingURL=init.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../src/bin/init.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,IAAI,QAAa,OAAO,CAAC,IAAI,CAkBzC,CAAC"}