@azure/create-microsoft-playwright-testing 1.0.0-beta.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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # Release History
2
+
3
+ ## 1.0.0-beta.1 (2024-09-09)
4
+
5
+ ### Features Added
6
+
7
+ - Added authentication using Entra ID for the service.
8
+ - Added reporting capabilities for the service. You can now publish the reports and artifacts generated by Playwright OSS to the service.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Microsoft
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
+ # Microsoft Playwright Testing preview
2
+
3
+ Microsoft Playwright Testing 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 Microsoft Playwright Testing service, you can release features faster and more confidently.
4
+
5
+ ## Usage
6
+
7
+ Get started with Microsoft Playwright Testing with a single command
8
+
9
+ ```sh
10
+ npm init @azure/microsoft-playwright-testing@latest
11
+ # Or for Yarn
12
+ yarn create @azure/microsoft-playwright-testing
13
+ # Or for pnpm
14
+ pnpm create @azure/microsoft-playwright-testing
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 Microsoft Playwright Testing 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_1 = require("../initialize");
7
+ const utils_1 = require("../utils");
8
+ const init = async () => {
9
+ const options = (0, utils_1.parseCLIArguments)();
10
+ const { config: playwrightConfigFile } = options;
11
+ let playwrightServiceInitConfig;
12
+ if (playwrightConfigFile) {
13
+ playwrightServiceInitConfig = Object.assign({}, (0, utils_1.getLanguageAndConfigInfoFromConfigurationFile)(playwrightConfigFile));
14
+ }
15
+ else {
16
+ playwrightServiceInitConfig = Object.assign({}, (0, utils_1.getLanguageAndConfigInfoFromDirectory)());
17
+ }
18
+ console.log("");
19
+ const playwrightServiceInitialize = new initialize_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,8CAA4D;AAC5D,oCAIkB;AAEX,MAAM,IAAI,GAAG,KAAK,IAAmB,EAAE;IAC5C,MAAM,OAAO,GAAG,IAAA,yBAAiB,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,qDAA6C,EAAC,oBAAoB,CAAC,CACvE,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,2BAA2B,qBACtB,IAAA,6CAAqC,GAAE,CAC3C,CAAC;IACJ,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChB,MAAM,2BAA2B,GAAG,IAAI,wCAA2B,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 { PlaywrightServiceInitConfig } from \"../types\";\nimport { PlaywrightServiceInitialize } from \"../initialize\";\nimport {\n getLanguageAndConfigInfoFromConfigurationFile,\n getLanguageAndConfigInfoFromDirectory,\n parseCLIArguments,\n} from \"../utils\";\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 { Language } from "./types";
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,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,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 { Language } from \"./types\";\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":""}
package/dist/index.js ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ // Copyright (c) Microsoft Corporation.
5
+ // Licensed under the MIT License.
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const init_1 = require("./bin/init");
8
+ (async () => {
9
+ await (0, init_1.init)();
10
+ })().catch((err) => {
11
+ console.error(err);
12
+ process.exit(1);
13
+ });
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["#!/usr/bin/env node\n\n// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { init } from \"./bin/init\";\n\n(async () => {\n await init();\n})().catch((err) => {\n console.error(err);\n process.exit(1);\n});\n"],"names":[],"mappings":";;;AAEA;AACA;;AAEA,MAAkC,MAAA,GAAA,OAAA,CAAA,YAAA,CAAA,CAAA;AAElC,CAAC,YAAW;IACV,MAAM,IAAA,MAAI,CAAA,IAAA,GAAE,CAAC;AACf,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,GAAG,KAAI;AACjB,IAAA,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;AACnB,IAAA,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC;;"}
@@ -0,0 +1,16 @@
1
+ import { PlaywrightServiceInitConfig } from "./types";
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":"AAMA,OAAO,EAA0C,2BAA2B,EAAE,MAAM,SAAS,CAAC;AAmB9F,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,CAGpB;IAEF,OAAO,CAAC,iCAAiC,CAEvC;IAEF,OAAO,CAAC,4BAA4B,CAkBlC;IAEF,OAAO,CAAC,qBAAqB,CAM3B;IAEF,OAAO,CAAC,mBAAmB,CAKzB;IAEF,OAAO,CAAC,uBAAuB,CA0C7B;IAEF,OAAO,CAAC,wBAAwB,CAE9B;CACH"}
@@ -0,0 +1,119 @@
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 fs_1 = tslib_1.__importDefault(require("fs"));
9
+ const constants_1 = require("./constants");
10
+ const utils_1 = require("./utils");
11
+ const packageManager_1 = require("./packageManager");
12
+ const questions = [
13
+ {
14
+ type: "confirm",
15
+ name: "canOverride",
16
+ message: constants_1.Messages.CAN_OVERRIDE_MESSAGE,
17
+ initial: true,
18
+ },
19
+ {
20
+ type: (prev) => (prev ? null : "confirm"),
21
+ name: "confirmationForExit",
22
+ message: constants_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_1.Messages.SETUP_PROCESS_EXIT_MESSAGE}`);
47
+ return false;
48
+ };
49
+ this.promptOnCancel = () => {
50
+ // eslint-disable-next-line n/no-process-exit
51
+ process.exit(0);
52
+ };
53
+ this.isServiceConfigFileAlreadyPresent = () => {
54
+ return fs_1.default.existsSync(this.getServiceConfigFileName());
55
+ };
56
+ this.displayAdditionalInformation = () => {
57
+ const runCommandParallelWorkers = this._packageManager.runCommand("playwright", `test -c ${this.getServiceConfigFileName()} --workers=20`);
58
+ console.log(`\n\nTo run playwrights tests using Playwright Service\n`);
59
+ console.log(`\t${runCommandParallelWorkers}\n`);
60
+ console.log("\nPlaywright Service Portal - https://playwright.microsoft.com/");
61
+ console.log("Getting Started - https://aka.ms/mpt/quickstart\n");
62
+ console.log("If you're already using the Microsoft Playwright Testing service, please review the quickstart guide [https://aka.ms/mpt/quickstart] to ensure your tests continue running smoothly.");
63
+ console.log("We've introduced changes related to authentication. You'll need to update the new config file to align with these changes.");
64
+ };
65
+ this.installServicePackage = async () => {
66
+ const command = this._packageManager.installDevDependencyCommand("@azure/microsoft-playwright-testing");
67
+ console.log(`Installing Service package (${command})`);
68
+ await (0, utils_1.executeCommand)(command);
69
+ };
70
+ this.createServiceConfig = async () => {
71
+ const serviceConfigFile = this.getServiceConfigFileName();
72
+ const serviceConfigFileContent = this.getServiceConfigContent();
73
+ await fs_1.default.promises.writeFile(serviceConfigFile, serviceConfigFileContent);
74
+ console.log(`Success! Created service configuration file - ${serviceConfigFile}`);
75
+ };
76
+ this.getServiceConfigContent = () => {
77
+ const customerConfigFileName = (0, utils_1.getFileReferenceForImport)(this._setupConfig.playwrightConfigFile);
78
+ const importCommandTypeScript = `import { defineConfig } from '@playwright/test';
79
+ import { getServiceConfig, ServiceOS } from '@azure/microsoft-playwright-testing';
80
+ import config from '${customerConfigFileName}';
81
+ `;
82
+ const importCommandJavaScript = `const { defineConfig } = require('@playwright/test');
83
+ const { getServiceConfig, ServiceOS } = require('@azure/microsoft-playwright-testing');
84
+ const config = require('${customerConfigFileName}');
85
+ `;
86
+ const importCommand = this._setupConfig.projectLanguage === constants_1.Languages.TypeScript
87
+ ? importCommandTypeScript
88
+ : importCommandJavaScript;
89
+ const content = importCommand +
90
+ `
91
+ /* Learn more about service configuration at https://aka.ms/mpt/config */
92
+ export default defineConfig(
93
+ config,
94
+ getServiceConfig(config, {
95
+ exposeNetwork: '<loopback>',
96
+ timeout: 30000,
97
+ os: ServiceOS.LINUX,
98
+ }),
99
+ {
100
+ /*
101
+ Playwright Testing service reporter is added by default.
102
+ This will override any reporter options specified in the base playwright config.
103
+ If you are using more reporters, please update your configuration accordingly.
104
+ */
105
+ reporter: [['list'], ['@azure/microsoft-playwright-testing/reporter']],
106
+ }
107
+ );
108
+ `;
109
+ return content;
110
+ };
111
+ this.getServiceConfigFileName = () => {
112
+ return "playwright.service.config" + constants_1.Extensions[this._setupConfig.projectLanguage];
113
+ };
114
+ this._setupConfig = setupConfig;
115
+ this._packageManager = (0, packageManager_1.getPackageManager)();
116
+ }
117
+ }
118
+ exports.PlaywrightServiceInitialize = PlaywrightServiceInitialize;
119
+ //# sourceMappingURL=initialize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initialize.js","sourceRoot":"","sources":["../src/initialize.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;;AAElC,8DAAgD;AAChD,oDAAoB;AACpB,2CAA8D;AAE9D,mCAAoE;AACpE,qDAAqD;AAErD,MAAM,SAAS,GAAmB;IAChC;QACE,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,aAAa;QACnB,OAAO,EAAE,oBAAQ,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,oBAAQ,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,iBAAO,CAAC,MAAM,CAAC,SAAS,EAAE;gBAChD,QAAQ,EAAE,IAAI,CAAC,cAAc;aAC9B,CAAC,CAA2B,C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C;QAChC,CAAC,CAAC;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,YAAE,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,iCAAyB,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,qBAAS,CAAC,UAAU;gBACxD,CAAC,CAAC,uBAAuB;gBACzB,CAAC,CAAC,uBAAuB,CAAC;YAE9B,MAAM,OAAO,GACX,aAAa;gBACb;;;;;;;;;;;;;;;;;;CAkBL,CAAC;YACE,OAAO,OAAO,CAAC;QACjB,CAAC,CAAC;QAEM,6BAAwB,GAAG,GAAW,EAAE;YAC9C,OAAO,2BAA2B,GAAG,sBAAU,CAAC,IAAI,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC;QACrF,CAAC,CAAC;QAlHA,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;QAChC,IAAI,CAAC,eAAe,GAAG,IAAA,kCAAiB,GAAE,CAAC;IAC7C,CAAC;CAiHF;AAxHD,kEAwHC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport prompts, { PromptObject } from \"prompts\";\nimport fs from \"fs\";\nimport { Extensions, Languages, Messages } from \"./constants\";\nimport { OverridePromptResponse, PackageManager, PlaywrightServiceInitConfig } from \"./types\";\nimport { executeCommand, getFileReferenceForImport } from \"./utils\";\nimport { getPackageManager } from \"./packageManager\";\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 // eslint-disable-next-line n/no-process-exit\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(\"\\nPlaywright Service Portal - https://playwright.microsoft.com/\");\n console.log(\"Getting Started - https://aka.ms/mpt/quickstart\\n\");\n\n console.log(\n \"If you're already using the Microsoft Playwright Testing service, please review the quickstart guide [https://aka.ms/mpt/quickstart] to ensure your tests continue running smoothly.\",\n );\n console.log(\n \"We've introduced changes related to authentication. You'll need to update the new config file to align with these changes.\",\n );\n };\n\n private installServicePackage = async (): Promise<void> => {\n const command = this._packageManager.installDevDependencyCommand(\n \"@azure/microsoft-playwright-testing\",\n );\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/microsoft-playwright-testing';\nimport config from '${customerConfigFileName}';\n`;\n\n const importCommandJavaScript = `const { defineConfig } = require('@playwright/test');\nconst { getServiceConfig, ServiceOS } = require('@azure/microsoft-playwright-testing');\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 }),\n {\n /* \n Playwright Testing service reporter is added by default.\n This will override any reporter options specified in the base playwright config.\n If you are using more reporters, please update your configuration accordingly.\n */\n reporter: [['list'], ['@azure/microsoft-playwright-testing/reporter']],\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,17 @@
1
+ import { PackageManager } from "./types";
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,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAIzC,qBAAa,GAAI,YAAW,cAAc;IACxC,2BAA2B,gBAAiB,MAAM,KAAG,MAAM,CAEzD;IACF,UAAU,YAAa,MAAM,QAAQ,MAAM,KAAG,MAAM,CAElD;CACH;AAED,qBAAa,IAAK,YAAW,cAAc;IACzC,OAAO,CAAC,YAAY,CAAkB;;IAMtC,2BAA2B,gBAAiB,MAAM,KAAG,MAAM,CAEzD;IACF,UAAU,YAAa,MAAM,QAAQ,MAAM,KAAG,MAAM,CAElD;CACH;AAED,qBAAa,IAAK,YAAW,cAAc;IACzC,2BAA2B,gBAAiB,MAAM,KAAG,MAAM,CAEzD;IACF,UAAU,YAAa,MAAM,QAAQ,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 fs_1 = require("fs");
7
+ const process_1 = require("process");
8
+ const path_1 = require("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, fs_1.existsSync)((0, path_1.resolve)((0, 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,2BAAgC;AAEhC,qCAA8B;AAC9B,+BAA+B;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AC,CAAC;QACvD,IAAI,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC;YAAE,OAAO,IAAI,IAAI,EAAE,CAAC;QAClD,IAAI,SAAS,CAAC,QAAQ,CAAC,MAAM,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 \"fs\";\nimport { PackageManager } from \"./types\";\nimport { cwd } from \"process\";\nimport { resolve } from \"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"}
package/dist/types.js ADDED
@@ -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 { CLIArguments, PlaywrightServiceInitConfig } from "./types";
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,EAAE,YAAY,EAAE,2BAA2B,EAAE,MAAM,SAAS,CAAC;AAGpE,eAAO,MAAM,cAAc,YAAa,MAAM,KAAG,OAAO,CAAC,MAAM,CAU9D,CAAC;AAEF,eAAO,MAAM,qCAAqC,QAAO,2BAcxD,CAAC;AAEF,eAAO,MAAM,6CAA6C,yBAClC,MAAM,KAC3B,2BAaF,CAAC;AAEF,eAAO,MAAM,yBAAyB,aAAc,MAAM,KAAG,MAW5D,CAAC;AAEF,eAAO,MAAM,cAAc,QAAO,MAUjC,CAAC;AAEF,eAAO,MAAM,iBAAiB,QAAO,YAcpC,CAAC"}
package/dist/utils.js ADDED
@@ -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 child_process_1 = require("child_process");
8
+ const fs_1 = tslib_1.__importDefault(require("fs"));
9
+ const path_1 = tslib_1.__importStar(require("path"));
10
+ const constants_1 = require("./constants");
11
+ const executeCommand = (command) => {
12
+ return new Promise((resolve, reject) => {
13
+ (0, 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 (fs_1.default.existsSync("playwright.config.js")) {
26
+ return {
27
+ playwrightConfigFile: "playwright.config.js",
28
+ projectLanguage: constants_1.Languages.JavaScript,
29
+ };
30
+ }
31
+ else if (fs_1.default.existsSync("playwright.config.ts")) {
32
+ return {
33
+ playwrightConfigFile: "playwright.config.ts",
34
+ projectLanguage: constants_1.Languages.TypeScript,
35
+ };
36
+ }
37
+ else {
38
+ throw new Error(constants_1.ErrorMessages.NO_CONFIGURATION_FILE_FOUND);
39
+ }
40
+ };
41
+ exports.getLanguageAndConfigInfoFromDirectory = getLanguageAndConfigInfoFromDirectory;
42
+ const getLanguageAndConfigInfoFromConfigurationFile = (playwrightConfigFile) => {
43
+ const extension = (0, path_1.extname)(playwrightConfigFile);
44
+ if (extension === constants_1.Extensions.TypeScript) {
45
+ return {
46
+ playwrightConfigFile,
47
+ projectLanguage: constants_1.Languages.TypeScript,
48
+ };
49
+ }
50
+ else if (extension === constants_1.Extensions.JavaScript) {
51
+ return {
52
+ playwrightConfigFile,
53
+ projectLanguage: constants_1.Languages.JavaScript,
54
+ };
55
+ }
56
+ else
57
+ throw new Error(constants_1.ErrorMessages.UNSUPPORTED_CONFIGURATION_FILE);
58
+ };
59
+ exports.getLanguageAndConfigInfoFromConfigurationFile = getLanguageAndConfigInfoFromConfigurationFile;
60
+ const getFileReferenceForImport = (filePath) => {
61
+ const normalizedPath = filePath.split(path_1.default.sep).join("/");
62
+ const parsedPath = path_1.default.parse(normalizedPath);
63
+ const withoutExtension = path_1.default.posix.join(parsedPath.dir, parsedPath.name);
64
+ if (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,iDAAqC;AACrC,oDAAoB;AACpB,qDAAqC;AAErC,2CAAmE;AAE5D,MAAM,cAAc,GAAG,CAAC,OAAe,EAAmB,EAAE;IACjE,OAAO,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC7C,IAAA,oBAAI,EAAC,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE;YACjC,IAAI,KA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,GAAG,CAAC,CAAC,CAAC;QACpC,CAAC;aAAM,IAAI,IAAI,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 \"child_process\";\nimport fs from \"fs\";\nimport path, { extname } from \"path\";\nimport { CLIArguments, PlaywrightServiceInitConfig } from \"./types\";\nimport { ErrorMessages, Extensions, Languages } from \"./constants\";\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"]}
package/package.json ADDED
@@ -0,0 +1,89 @@
1
+ {
2
+ "name": "@azure/create-microsoft-playwright-testing",
3
+ "version": "1.0.0-beta.1",
4
+ "description": "Package to setup @azure/microsoft-playwright-testing",
5
+ "homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/playwrighttesting/create-microsoft-playwright-testing/README.md",
6
+ "sdk-type": "client",
7
+ "repository": "github:Azure/azure-sdk-for-js",
8
+ "keywords": [
9
+ "azure",
10
+ "cloud",
11
+ "playwright",
12
+ "playwright service",
13
+ "reporting",
14
+ "playwright testing"
15
+ ],
16
+ "author": "Microsoft Corporation",
17
+ "license": "MIT",
18
+ "bugs": {
19
+ "url": "https://github.com/Azure/azure-sdk-for-js/issues"
20
+ },
21
+ "engines": {
22
+ "node": ">=18.0.0"
23
+ },
24
+ "sideEffects": false,
25
+ "main": "dist/index.js",
26
+ "module": "dist/index.js",
27
+ "types": "dist/index.d.ts",
28
+ "bin": {
29
+ "init": "dist/index.js"
30
+ },
31
+ "files": [
32
+ "dist",
33
+ "README.md",
34
+ "LICENSE",
35
+ "CHANGELOG.md"
36
+ ],
37
+ "scripts": {
38
+ "audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit",
39
+ "build": "npm run clean && tsc -p . && dev-tool run bundle && npm run extract-api",
40
+ "build:test": "tsc -p . && dev-tool run bundle",
41
+ "build:samples": "echo obsolete",
42
+ "check-format": "dev-tool run vendored prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
43
+ "clean": "rimraf --glob dist *.log dist-test temp types *.tgz *.xml samples/**/test-results/",
44
+ "execute:samples": "echo skipped",
45
+ "format": "dev-tool run vendored prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
46
+ "integration-test:browser": "echo skipped",
47
+ "integration-test:node": "echo skipped",
48
+ "integration-test": "npm run integration-test:node && npm run integration-test:browser",
49
+ "lint:fix": "eslint package.json CHANGELOG.md README.md src --fix --fix-type [problem,suggestion]",
50
+ "lint": "eslint package.json CHANGELOG.md README.md src",
51
+ "pack": "npm pack 2>&1",
52
+ "test:browser": "npm run build:test && npm run unit-test:browser && npm run integration-test:browser",
53
+ "test:node": "npm run build:test && npm run unit-test:node && npm run integration-test:node",
54
+ "test": "npm run build:test && npm run unit-test && npm run integration-test",
55
+ "unit-test:browser": "echo skipped",
56
+ "unit-test:node": "dev-tool run test:node-ts-input --no-test-proxy -- --timeout 12000 'test/**/*.spec.ts' --exit",
57
+ "unit-test": "npm run unit-test:node && npm run unit-test:browser",
58
+ "extract-api": "echo skipped"
59
+ },
60
+ "dependencies": {
61
+ "prompts": "^2.4.2",
62
+ "tslib": "^2.6.0"
63
+ },
64
+ "devDependencies": {
65
+ "@types/node": "^20.12.12",
66
+ "@types/prompts": "^2.4.9",
67
+ "@azure/dev-tool": "^1.0.0",
68
+ "rimraf": "^5.0.5",
69
+ "typescript": "^5.5.3",
70
+ "@azure/eslint-plugin-azure-sdk": "^3.0.0",
71
+ "eslint": "^9.9.0",
72
+ "sinon": "^17.0.0",
73
+ "@types/sinon": "^17.0.0",
74
+ "mocha": "^10.0.0",
75
+ "@types/mocha": "^10.0.0",
76
+ "cross-env": "^7.0.2",
77
+ "@azure-tools/test-utils": "^1.0.1"
78
+ },
79
+ "prettier": "@azure/eslint-plugin-azure-sdk/prettier.json",
80
+ "//sampleConfiguration": {
81
+ "productName": "Microsoft Playwright Testing",
82
+ "productSlugs": [
83
+ "azure"
84
+ ],
85
+ "requiredResources": {
86
+ "Microsoft Playwright Testing workspace": "https://learn.microsoft.com/azure/playwright-testing/"
87
+ }
88
+ }
89
+ }