@uuv/runner-commons 2.10.1 → 2.11.0

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 CHANGED
@@ -1,3 +1,11 @@
1
+ # [2.11.0](https://github.com/Orange-OpenSource/uuv/compare/runner-commons-v2.10.1...runner-commons-v2.11.0) (2024-04-22)
2
+
3
+
4
+ ### Features
5
+
6
+ * (refactor) introduce uuv-cli engine from runner-commons, [#576](https://github.com/Orange-OpenSource/uuv/issues/576) ([6de2feb](https://github.com/Orange-OpenSource/uuv/commit/6de2feb2b2d74eddf1244694dfb7d697af28baf8))
7
+ * add unit tests for uuv-cli implementations, [#576](https://github.com/Orange-OpenSource/uuv/issues/576) ([7e67f13](https://github.com/Orange-OpenSource/uuv/commit/7e67f13b9929577162bce84c5e8b5c08a4396a09))
8
+
1
9
  ## [2.10.1](https://github.com/Orange-OpenSource/uuv/compare/runner-commons-v2.10.0...runner-commons-v2.10.1) (2024-04-14)
2
10
 
3
11
 
@@ -0,0 +1,7 @@
1
+ import { UUVCliRunner } from "./runner";
2
+ export declare class UUVCliEngine {
3
+ private runner;
4
+ constructor(runner: UUVCliRunner);
5
+ execute(): Promise<void>;
6
+ private checkArguments;
7
+ }
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.UUVCliEngine = void 0;
7
+ const helper_1 = require("./helper");
8
+ const chalk_1 = __importDefault(require("chalk"));
9
+ class UUVCliEngine {
10
+ runner;
11
+ constructor(runner) {
12
+ this.runner = runner;
13
+ }
14
+ async execute() {
15
+ try {
16
+ helper_1.UUVCliHelper.printBanner(this.runner.name, this.runner.getCurrentVersion());
17
+ this.checkArguments();
18
+ const options = helper_1.UUVCliHelper.extractArgs(this.runner.projectDir, this.runner.defaultBrowser);
19
+ helper_1.UUVCliHelper.printVariables(options);
20
+ await this.runner.prepare(options);
21
+ console.info(chalk_1.default.blueBright(`Executing UUV command ${options.command}...`));
22
+ switch (options.command) {
23
+ case "open":
24
+ await this.runner.executeOpenCommand(options);
25
+ break;
26
+ case "e2e":
27
+ await this.runner.executeE2eCommand(options);
28
+ break;
29
+ default:
30
+ throw new Error("Unknown command");
31
+ }
32
+ console.info(`UUV command ${options.command} executed`);
33
+ }
34
+ catch (e) {
35
+ console.error(chalk_1.default.red(e));
36
+ process.exit(1);
37
+ }
38
+ }
39
+ checkArguments() {
40
+ helper_1.UUVCliHelper.checkTargetCommand();
41
+ helper_1.UUVCliHelper.checkTargetTestFiles();
42
+ }
43
+ }
44
+ exports.UUVCliEngine = UUVCliEngine;
@@ -0,0 +1,12 @@
1
+ import { UUVCliOptions } from "./options";
2
+ export declare class UUVCliHelper {
3
+ /**
4
+ * Print runner banner
5
+ */
6
+ static printBanner(runnerName: string, currentVersion: string): void;
7
+ static checkTargetCommand(): void;
8
+ static checkTargetTestFiles(): void;
9
+ private static getTargetCommand;
10
+ static extractArgs(projectDir: string, defaultBrowser: any): Partial<UUVCliOptions>;
11
+ static printVariables(options: Partial<UUVCliOptions>): void;
12
+ }
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.UUVCliHelper = void 0;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const figlet_1 = __importDefault(require("figlet"));
9
+ const minimist_1 = __importDefault(require("minimist"));
10
+ const path_1 = __importDefault(require("path"));
11
+ const lodash_1 = require("lodash");
12
+ class UUVCliHelper {
13
+ /**
14
+ * Print runner banner
15
+ */
16
+ static printBanner(runnerName, currentVersion) {
17
+ console.log(chalk_1.default.blueBright(figlet_1.default.textSync(`UUV - ${runnerName}`, {
18
+ font: "Big",
19
+ horizontalLayout: "default",
20
+ verticalLayout: "default",
21
+ width: 80,
22
+ whitespaceBreak: true
23
+ })));
24
+ console.info(chalk_1.default.blueBright(`Version: ${currentVersion}\n\n`));
25
+ }
26
+ static checkTargetCommand() {
27
+ const argv = (0, minimist_1.default)(process.argv.slice(2));
28
+ if (argv._.length < 1) {
29
+ throw new Error("No command specified");
30
+ }
31
+ }
32
+ static checkTargetTestFiles() {
33
+ const argv = (0, minimist_1.default)(process.argv.slice(2));
34
+ const targetTestFile = argv.targetTestFile;
35
+ if (!(0, lodash_1.isEmpty)(targetTestFile)) {
36
+ try {
37
+ new RegExp(targetTestFile, "gi");
38
+ }
39
+ catch (e) {
40
+ throw new Error("Invalid targetTestFile argument, this args should respect Glob pattern");
41
+ }
42
+ }
43
+ }
44
+ static getTargetCommand(argv) {
45
+ return argv._[0];
46
+ }
47
+ static extractArgs(projectDir, defaultBrowser) {
48
+ const argv = (0, minimist_1.default)(process.argv.slice(2));
49
+ const browser = argv.browser ? argv.browser : defaultBrowser;
50
+ const env = argv.env ? JSON.parse(argv.env.replace(/'/g, "\"")) : {};
51
+ const targetTestFile = argv.targetTestFile ? argv.targetTestFile : null;
52
+ const reportDir = path_1.default.join(projectDir, "reports");
53
+ return {
54
+ // eslint-disable-next-line dot-notation
55
+ baseUrl: process.env["UUV_BASE_URL"],
56
+ browser,
57
+ extraArgs: env,
58
+ targetTestFile,
59
+ command: this.getTargetCommand(argv),
60
+ report: {
61
+ outputDir: reportDir,
62
+ a11y: {
63
+ enabled: argv.generateA11yReport,
64
+ outputFile: path_1.default.join(process.cwd(), reportDir, "a11y-report.json")
65
+ },
66
+ html: {
67
+ enabled: argv.generateHtmlReport,
68
+ outputDir: path_1.default.join(reportDir, "e2e/html")
69
+ },
70
+ junit: {
71
+ enabled: argv.generateJunitReport,
72
+ outputFile: path_1.default.join(reportDir, "e2e/junit-report.xml")
73
+ }
74
+ }
75
+ };
76
+ }
77
+ static printVariables(options) {
78
+ console.debug(chalk_1.default.yellowBright("Variables: "));
79
+ if (options.baseUrl) {
80
+ console.debug(` -> baseUrl: ${options.baseUrl}`);
81
+ }
82
+ console.debug(` -> browser: ${options.browser}`);
83
+ console.debug(` -> report: ${JSON.stringify(options.report)}`);
84
+ console.debug(` -> env: ${JSON.stringify(options.extraArgs)}`);
85
+ if (options.targetTestFile) {
86
+ console.debug(` -> targetTestFile: ${options.targetTestFile}`);
87
+ }
88
+ console.debug("\n");
89
+ }
90
+ }
91
+ exports.UUVCliHelper = UUVCliHelper;
@@ -0,0 +1,4 @@
1
+ export * from "./engine";
2
+ export * from "./helper";
3
+ export * from "./options";
4
+ export * from "./runner";
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./engine"), exports);
18
+ __exportStar(require("./helper"), exports);
19
+ __exportStar(require("./options"), exports);
20
+ __exportStar(require("./runner"), exports);
@@ -0,0 +1,22 @@
1
+ export type UUVCliOptions = {
2
+ baseUrl: string;
3
+ command: "open" | "e2e";
4
+ browser: string;
5
+ targetTestFile: string;
6
+ report: {
7
+ outputDir: string;
8
+ a11y: {
9
+ enabled: boolean;
10
+ outputFile: string;
11
+ };
12
+ html: {
13
+ enabled: boolean;
14
+ outputDir: string;
15
+ };
16
+ junit: {
17
+ enabled: boolean;
18
+ outputFile: string;
19
+ };
20
+ };
21
+ extraArgs: any;
22
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,34 @@
1
+ import { UUVCliOptions } from "./options";
2
+ export interface UUVCliRunner {
3
+ /**
4
+ * Runner name e.g: Cypress, Playwright
5
+ */
6
+ name: string;
7
+ /**
8
+ * Project directory
9
+ */
10
+ projectDir: string;
11
+ /**
12
+ * Default browser
13
+ */
14
+ defaultBrowser: string;
15
+ /**
16
+ * Return runner current version
17
+ */
18
+ getCurrentVersion(): string;
19
+ /**
20
+ * Prepare runner to execute command
21
+ * @param options
22
+ */
23
+ prepare(options: Partial<UUVCliOptions>): any;
24
+ /**
25
+ * Execute "e2e" command
26
+ * @param options
27
+ */
28
+ executeE2eCommand(options: Partial<UUVCliOptions>): any;
29
+ /**
30
+ * Execute "open" command
31
+ * @param options
32
+ */
33
+ executeOpenCommand(options: Partial<UUVCliOptions>): any;
34
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/dist/index.d.ts CHANGED
@@ -7,3 +7,4 @@ import key from "./assets/i18n/web/template.json";
7
7
  export { key };
8
8
  export { AccessibleRole } from "./step-definition-generator/accessible-role";
9
9
  export * from "./assets/i18n/web/en";
10
+ export * from "./cli";
package/dist/index.js CHANGED
@@ -28,3 +28,4 @@ exports.key = template_json_1.default;
28
28
  var accessible_role_1 = require("./step-definition-generator/accessible-role");
29
29
  Object.defineProperty(exports, "AccessibleRole", { enumerable: true, get: function () { return accessible_role_1.AccessibleRole; } });
30
30
  __exportStar(require("./assets/i18n/web/en"), exports);
31
+ __exportStar(require("./cli"), exports);
@@ -46,4 +46,5 @@ export declare class Common {
46
46
  static cleanGeneratedFilesIfExists(generatedFile: string): void;
47
47
  static cleanFolderIfExists(folder: string): void;
48
48
  static writeWordingFile(generatedFile: string, data: string): void;
49
+ static deleteAllFileOfDirectory(dirPath: any): void;
49
50
  }
@@ -114,5 +114,13 @@ class Common {
114
114
  fs_1.default.writeFileSync(generatedFile, data);
115
115
  console.log(`[WRITE] ${generatedFile} written successfully`);
116
116
  }
117
+ static deleteAllFileOfDirectory(dirPath) {
118
+ for (const file of fs_1.default.readdirSync(dirPath)) {
119
+ const filePath = path.join(dirPath, file);
120
+ if (fs_1.default.lstatSync(filePath).isFile()) {
121
+ fs_1.default.rmSync(filePath);
122
+ }
123
+ }
124
+ }
117
125
  }
118
126
  exports.Common = Common;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uuv/runner-commons",
3
- "version": "2.10.1",
3
+ "version": "2.11.0",
4
4
  "type": "commonjs",
5
5
  "author": "Louis Fredice NJAKO MOLOM (https://github.com/luifr10) & Stanley SERVICAL (https://github.com/stanlee974)",
6
6
  "description": "A common lib for uuv",
@@ -32,7 +32,8 @@
32
32
  "scripts": {
33
33
  "package": "npm pack --pack-destination=\"../../dist/packages\"",
34
34
  "lint": "npx eslint . --ext .js,.ts,.feature --fix",
35
- "test": "jest"
35
+ "test": "npm run unit-test --",
36
+ "unit-test": "jest --coverage"
36
37
  },
37
38
  "devDependencies": {
38
39
  "@typescript-eslint/eslint-plugin": "5.62.0",
@@ -47,6 +48,7 @@
47
48
  "dist/assets/**/*",
48
49
  "src/assets/i18n/*/*/*.json",
49
50
  "dist/runner/**/*",
51
+ "dist/cli/**/*",
50
52
  "*.md"
51
53
  ],
52
54
  "exports": {
@@ -65,5 +67,11 @@
65
67
  "require": "./dist/assets/i18n/web/en/index.js",
66
68
  "types": "./dist/assets/i18n/web/en/index.d.ts"
67
69
  }
70
+ },
71
+ "dependencies": {
72
+ "chalk": "^4.1.2",
73
+ "figlet": "1.7.0",
74
+ "lodash": "^4.17.21",
75
+ "minimist": "1.2.8"
68
76
  }
69
77
  }