@uuv/playwright 2.11.1 → 2.12.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.
|
@@ -11,10 +11,26 @@
|
|
|
11
11
|
* Software description: Make test writing fast, understandable by any human
|
|
12
12
|
* understanding English or French.
|
|
13
13
|
*/
|
|
14
|
+
import { UUVCliOptions, UUVCliRunner } from "@uuv/runner-commons";
|
|
14
15
|
export interface UUVPlaywrightCucumberMapItem {
|
|
15
16
|
originalFile: string;
|
|
16
17
|
generatedFile: string;
|
|
17
18
|
}
|
|
18
19
|
export declare const UUVPlaywrightCucumberMapFile = ".uuv-playwright-cucumber-map.json";
|
|
19
|
-
export declare
|
|
20
|
-
|
|
20
|
+
export declare class UUVCliPlaywrightRunner implements UUVCliRunner {
|
|
21
|
+
projectDir: any;
|
|
22
|
+
private tempDir;
|
|
23
|
+
name: string;
|
|
24
|
+
defaultBrowser: string;
|
|
25
|
+
constructor(projectDir: any, tempDir: any);
|
|
26
|
+
getCurrentVersion(): string;
|
|
27
|
+
prepare(options: Partial<UUVCliOptions>): Promise<void>;
|
|
28
|
+
private setEnvironmentVariables;
|
|
29
|
+
executeE2eCommand(options: Partial<UUVCliOptions>): void;
|
|
30
|
+
executeOpenCommand(options: Partial<UUVCliOptions>): void;
|
|
31
|
+
private getTargetTestFileForPlaywright;
|
|
32
|
+
private runPlaywright;
|
|
33
|
+
private executeSystemCommand;
|
|
34
|
+
private buildCommand;
|
|
35
|
+
}
|
|
36
|
+
export declare function executePreprocessor(tempDir: string, tags: string): Promise<void>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Software Name : UUV
|
|
3
4
|
*
|
|
@@ -11,7 +12,6 @@
|
|
|
11
12
|
* Software description: Make test writing fast, understandable by any human
|
|
12
13
|
* understanding English or French.
|
|
13
14
|
*/
|
|
14
|
-
"use strict";
|
|
15
15
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
16
16
|
if (k2 === undefined) k2 = k;
|
|
17
17
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -39,106 +39,127 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
39
39
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
40
|
};
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.
|
|
43
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
44
|
-
const gen_1 = require("../cucumber/preprocessor/gen");
|
|
42
|
+
exports.executePreprocessor = exports.UUVCliPlaywrightRunner = exports.UUVPlaywrightCucumberMapFile = void 0;
|
|
45
43
|
const fs_1 = __importDefault(require("fs"));
|
|
46
|
-
const
|
|
44
|
+
const gen_1 = require("../cucumber/preprocessor/gen");
|
|
45
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
47
46
|
const uuv_playwright_reporter_helper_1 = require("../reporter/uuv-playwright-reporter-helper");
|
|
48
47
|
const path_1 = __importDefault(require("path"));
|
|
48
|
+
const child_process_1 = __importStar(require("child_process"));
|
|
49
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
49
50
|
exports.UUVPlaywrightCucumberMapFile = ".uuv-playwright-cucumber-map.json";
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
});
|
|
63
|
-
}
|
|
51
|
+
class UUVCliPlaywrightRunner {
|
|
52
|
+
projectDir;
|
|
53
|
+
tempDir;
|
|
54
|
+
name = "Playwright";
|
|
55
|
+
defaultBrowser = "chromium";
|
|
56
|
+
constructor(projectDir, tempDir) {
|
|
57
|
+
this.projectDir = projectDir;
|
|
58
|
+
this.tempDir = tempDir;
|
|
59
|
+
}
|
|
60
|
+
getCurrentVersion() {
|
|
61
|
+
const pJsonStr = fs_1.default.readFileSync(`${__dirname}/../../package.json`, {
|
|
62
|
+
encoding: "utf8", flag: "r"
|
|
64
63
|
});
|
|
65
|
-
|
|
64
|
+
return JSON.parse(pJsonStr).version;
|
|
66
65
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
process.exit(-1);
|
|
66
|
+
async prepare(options) {
|
|
67
|
+
await executePreprocessor(this.tempDir, options.extraArgs.TAGS);
|
|
68
|
+
this.setEnvironmentVariables(options);
|
|
71
69
|
}
|
|
72
|
-
|
|
73
|
-
function runPlaywright(mode, configDir, browser = "chromium", generateHtmlReport = false, generateJunitReport = false, env, targetTestFile) {
|
|
74
|
-
const configFile = `${configDir}/playwright.config.ts`;
|
|
75
|
-
const reportType = generateHtmlReport ? uuv_playwright_reporter_helper_1.GeneratedReportType.HTML : uuv_playwright_reporter_helper_1.GeneratedReportType.CONSOLE;
|
|
76
|
-
try {
|
|
70
|
+
setEnvironmentVariables(options) {
|
|
77
71
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
78
72
|
// @ts-ignore
|
|
79
|
-
process.env.REPORT_TYPE =
|
|
73
|
+
process.env.REPORT_TYPE = options.report?.html.enabled ? uuv_playwright_reporter_helper_1.GeneratedReportType.HTML : uuv_playwright_reporter_helper_1.GeneratedReportType.CONSOLE;
|
|
80
74
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
81
75
|
// @ts-ignore
|
|
82
|
-
process.env.CONFIG_DIR =
|
|
76
|
+
process.env.CONFIG_DIR = this.projectDir;
|
|
83
77
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
84
78
|
// @ts-ignore
|
|
85
|
-
process.env.browser = browser;
|
|
86
|
-
if (
|
|
87
|
-
Object.keys(
|
|
79
|
+
process.env.browser = options.browser;
|
|
80
|
+
if (options.extraArgs) {
|
|
81
|
+
Object.keys(options.extraArgs).forEach(key => process.env[key] = options.extraArgs[key]);
|
|
88
82
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
83
|
+
}
|
|
84
|
+
executeE2eCommand(options) {
|
|
85
|
+
this.runPlaywright(options);
|
|
86
|
+
}
|
|
87
|
+
executeOpenCommand(options) {
|
|
88
|
+
child_process_1.default.fork(path_1.default.join(__dirname, "watch-test-files"), [this.tempDir, this.projectDir, options.extraArgs.TAGS]);
|
|
89
|
+
this.runPlaywright(options);
|
|
90
|
+
}
|
|
91
|
+
getTargetTestFileForPlaywright(targetTestFile) {
|
|
92
|
+
if (!targetTestFile) {
|
|
93
|
+
return "";
|
|
95
94
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
(0, child_process_1.execSync)(command, { stdio: "inherit" });
|
|
95
|
+
return `${targetTestFile
|
|
96
|
+
.replaceAll("uuv/e2e/", ".uuv-features-gen/uuv/e2e/")
|
|
97
|
+
.replaceAll(".feature", ".feature.spec.js")}`;
|
|
100
98
|
}
|
|
101
|
-
|
|
102
|
-
|
|
99
|
+
runPlaywright(options) {
|
|
100
|
+
const configFile = `${this.projectDir}/playwright.config.ts`;
|
|
101
|
+
try {
|
|
102
|
+
let reporter = "--reporter=@uuv/playwright/uuv-playwright-reporter";
|
|
103
|
+
if (options.report?.junit.enabled) {
|
|
104
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
105
|
+
// @ts-ignore
|
|
106
|
+
process.env.PLAYWRIGHT_JUNIT_OUTPUT_NAME = options.report?.junit.outputFile;
|
|
107
|
+
reporter = `${reporter},junit`;
|
|
108
|
+
}
|
|
109
|
+
const command = this.buildCommand(options, configFile, reporter);
|
|
110
|
+
this.executeSystemCommand(command);
|
|
111
|
+
}
|
|
112
|
+
catch (err) {
|
|
113
|
+
process.exit(2);
|
|
114
|
+
}
|
|
103
115
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
116
|
+
executeSystemCommand(command) {
|
|
117
|
+
console.log(chalk_1.default.gray(`Running command: ${command}`));
|
|
118
|
+
(0, child_process_1.execSync)(command, { stdio: "inherit" });
|
|
119
|
+
}
|
|
120
|
+
buildCommand(options, configFile, reporter) {
|
|
121
|
+
return lodash_1.default.trimEnd([
|
|
122
|
+
"npx",
|
|
123
|
+
"playwright",
|
|
124
|
+
"test",
|
|
125
|
+
`--project=${options.browser}`,
|
|
126
|
+
"-c",
|
|
127
|
+
configFile,
|
|
128
|
+
lodash_1.default.trimStart([
|
|
129
|
+
options.command === "open" ? "--ui" : "",
|
|
130
|
+
reporter
|
|
131
|
+
].join(" ")),
|
|
132
|
+
this.getTargetTestFileForPlaywright(options.targetTestFile)
|
|
133
|
+
].join(" "));
|
|
108
134
|
}
|
|
109
|
-
return ` ${targetTestFile
|
|
110
|
-
.replaceAll("uuv/e2e/", ".uuv-features-gen/uuv/e2e/")
|
|
111
|
-
.replaceAll(".feature", ".feature.spec.js")}`;
|
|
112
135
|
}
|
|
113
|
-
|
|
136
|
+
exports.UUVCliPlaywrightRunner = UUVCliPlaywrightRunner;
|
|
137
|
+
async function executePreprocessor(tempDir, tags) {
|
|
114
138
|
console.log("running preprocessor...");
|
|
115
|
-
await bddGen(tempDir,
|
|
116
|
-
console.log("preprocessor executed");
|
|
139
|
+
await bddGen(tempDir, tags);
|
|
140
|
+
console.log("preprocessor executed\n");
|
|
117
141
|
}
|
|
118
142
|
exports.executePreprocessor = executePreprocessor;
|
|
119
|
-
async function
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if (baseUrl) {
|
|
136
|
-
console.debug(` -> baseUrl: ${baseUrl}`);
|
|
143
|
+
async function bddGen(tempDir, tags) {
|
|
144
|
+
try {
|
|
145
|
+
const mapOfFile = await (0, gen_1.generateTestFiles)({
|
|
146
|
+
outputDir: tempDir,
|
|
147
|
+
tags
|
|
148
|
+
});
|
|
149
|
+
const content = [];
|
|
150
|
+
mapOfFile.forEach((value, key) => {
|
|
151
|
+
if (value.uri) {
|
|
152
|
+
content.push({
|
|
153
|
+
originalFile: value.uri,
|
|
154
|
+
generatedFile: key
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
fs_1.default.writeFileSync(`${tempDir}/${exports.UUVPlaywrightCucumberMapFile}`, JSON.stringify(content, null, 4), { encoding: "utf8" });
|
|
137
159
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
160
|
+
catch (err) {
|
|
161
|
+
console.error(chalk_1.default.red("Something went wrong..."));
|
|
162
|
+
console.dir(err);
|
|
163
|
+
process.exit(2);
|
|
142
164
|
}
|
|
143
|
-
return { browser, env, targetTestFile };
|
|
144
165
|
}
|
package/dist/lib/uuv-cli.d.ts
CHANGED
package/dist/lib/uuv-cli.js
CHANGED
|
@@ -13,72 +13,12 @@
|
|
|
13
13
|
* Software description: Make test writing fast, understandable by any human
|
|
14
14
|
* understanding English or French.
|
|
15
15
|
*/
|
|
16
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
-
};
|
|
19
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
17
|
exports.main = void 0;
|
|
21
|
-
const
|
|
22
|
-
const figlet_1 = __importDefault(require("figlet"));
|
|
23
|
-
const minimist_1 = __importDefault(require("minimist"));
|
|
18
|
+
const runner_commons_1 = require("@uuv/runner-commons");
|
|
24
19
|
const runner_playwright_1 = require("./runner-playwright");
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const FEATURE_GEN_DIR = `${PROJECT_DIR}/.uuv-features-gen`;
|
|
29
|
-
printBanner(getCurrentVersion);
|
|
30
|
-
const argv = (0, minimist_1.default)(process.argv.slice(2));
|
|
31
|
-
const command = findTargetCommand(argv);
|
|
32
|
-
console.info(chalk_1.default.blueBright(`Executing UUV command ${command}...`));
|
|
33
|
-
switch (command) {
|
|
34
|
-
case "open":
|
|
35
|
-
await openPlaywright(argv);
|
|
36
|
-
break;
|
|
37
|
-
case "e2e":
|
|
38
|
-
await runE2ETests(argv);
|
|
39
|
-
break;
|
|
40
|
-
default:
|
|
41
|
-
console.error(chalk_1.default.red("Unknown command"));
|
|
42
|
-
process.exit(1);
|
|
43
|
-
}
|
|
44
|
-
console.info(`UUV command ${command} executed`);
|
|
45
|
-
function openPlaywright(argv) {
|
|
46
|
-
return (0, runner_playwright_1.run)("open", FEATURE_GEN_DIR, PROJECT_DIR, argv);
|
|
47
|
-
}
|
|
48
|
-
function runE2ETests(argv) {
|
|
49
|
-
// Running Tests
|
|
50
|
-
return (0, runner_playwright_1.run)("e2e", FEATURE_GEN_DIR, PROJECT_DIR, argv)
|
|
51
|
-
.then(async (result) => {
|
|
52
|
-
console.log(`Status ${chalk_1.default.green("success")}`);
|
|
53
|
-
})
|
|
54
|
-
.catch((err) => {
|
|
55
|
-
console.error(chalk_1.default.red(err));
|
|
56
|
-
process.exit(-1);
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
function findTargetCommand(argv) {
|
|
60
|
-
if (argv._.length < 1) {
|
|
61
|
-
console.error(chalk_1.default.red("No command specified"));
|
|
62
|
-
process.exit(1);
|
|
63
|
-
}
|
|
64
|
-
const command = argv._[0];
|
|
65
|
-
return command;
|
|
66
|
-
}
|
|
67
|
-
function printBanner(getCurrentVersion) {
|
|
68
|
-
console.log(chalk_1.default.blueBright(figlet_1.default.textSync("UUV - Playwright", {
|
|
69
|
-
font: "Big",
|
|
70
|
-
horizontalLayout: "default",
|
|
71
|
-
verticalLayout: "default",
|
|
72
|
-
width: 80,
|
|
73
|
-
whitespaceBreak: true
|
|
74
|
-
})));
|
|
75
|
-
console.info(chalk_1.default.blueBright(`Version: ${getCurrentVersion()}\n\n`));
|
|
76
|
-
}
|
|
77
|
-
function getCurrentVersion() {
|
|
78
|
-
const pJsonStr = fs_1.default.readFileSync(`${__dirname}/../../package.json`, {
|
|
79
|
-
encoding: "utf8", flag: "r"
|
|
80
|
-
});
|
|
81
|
-
return JSON.parse(pJsonStr).version;
|
|
82
|
-
}
|
|
20
|
+
async function main(projectDir = "./uuv", tempDir = "uuv/.uuv-features-gen") {
|
|
21
|
+
const engine = new runner_commons_1.UUVCliEngine(new runner_playwright_1.UUVCliPlaywrightRunner(projectDir, tempDir));
|
|
22
|
+
engine.execute();
|
|
83
23
|
}
|
|
84
24
|
exports.main = main;
|
|
@@ -20,27 +20,27 @@ const runner_playwright_1 = require("./runner-playwright");
|
|
|
20
20
|
const chokidar_1 = __importDefault(require("chokidar"));
|
|
21
21
|
const chalk_1 = __importDefault(require("chalk"));
|
|
22
22
|
const tempDir = process.argv[2];
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
if (!tempDir || !
|
|
23
|
+
const projectDir = process.argv[3];
|
|
24
|
+
const tags = process.argv[4];
|
|
25
|
+
if (!tempDir || !projectDir) {
|
|
26
26
|
console.log(chalk_1.default.redBright("An error occurred during test files watching"));
|
|
27
27
|
process.exit(-1);
|
|
28
28
|
}
|
|
29
|
-
chokidar_1.default.watch(`${
|
|
29
|
+
chokidar_1.default.watch(`${projectDir}/e2e/**/*.feature`, {
|
|
30
30
|
ignoreInitial: true
|
|
31
31
|
})
|
|
32
32
|
.on("change", async (event, path) => {
|
|
33
33
|
console.log(chalk_1.default.yellowBright("\nRefreshing test files..."));
|
|
34
|
-
await (0, runner_playwright_1.executePreprocessor)(tempDir,
|
|
34
|
+
await (0, runner_playwright_1.executePreprocessor)(tempDir, tags);
|
|
35
35
|
console.log(chalk_1.default.yellowBright("Test files refreshed\n"));
|
|
36
36
|
})
|
|
37
37
|
.on("add", async (path) => {
|
|
38
38
|
console.log(chalk_1.default.yellowBright(`\nFile ${path} has been added`));
|
|
39
|
-
await (0, runner_playwright_1.executePreprocessor)(tempDir,
|
|
39
|
+
await (0, runner_playwright_1.executePreprocessor)(tempDir, tags);
|
|
40
40
|
console.log(chalk_1.default.yellowBright("Test files refreshed\n"));
|
|
41
41
|
})
|
|
42
42
|
.on("unlink", async (path) => {
|
|
43
43
|
console.log(chalk_1.default.yellowBright(`\nFile ${path} has been removed`));
|
|
44
|
-
await (0, runner_playwright_1.executePreprocessor)(tempDir,
|
|
44
|
+
await (0, runner_playwright_1.executePreprocessor)(tempDir, tags);
|
|
45
45
|
console.log(chalk_1.default.yellowBright("Test files refreshed\n"));
|
|
46
46
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uuv/playwright",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.12.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 solution to facilitate the writing and execution of E2E tests understandable by any human being using cucumber(BDD) and playwright",
|
|
@@ -36,23 +36,22 @@
|
|
|
36
36
|
"generate:step-definitions": "ts-node generate-step-definitions.ts",
|
|
37
37
|
"package": "npm pack --pack-destination=\"../../dist/packages\"",
|
|
38
38
|
"postinstall": "node postinstall.js",
|
|
39
|
-
"test
|
|
40
|
-
"test:
|
|
41
|
-
"test": "
|
|
39
|
+
"unit-test": "jest --runInBand --coverage --config=./jest.config.ts",
|
|
40
|
+
"e2e-test:run": "ts-node test.ts e2e",
|
|
41
|
+
"e2e-test:open": "ts-node test.ts open --",
|
|
42
|
+
"test": "npm run unit-test && npm run e2e-test:run"
|
|
42
43
|
},
|
|
43
44
|
"dependencies": {
|
|
44
45
|
"@cucumber/cucumber": "9.6.0",
|
|
45
46
|
"@cucumber/tag-expressions": "^6.0.0",
|
|
46
47
|
"@playwright/test": "1.43.1",
|
|
47
|
-
"@uuv/runner-commons": "2.
|
|
48
|
+
"@uuv/runner-commons": "2.11.0",
|
|
48
49
|
"axe-core": "4.9.0",
|
|
49
50
|
"axe-playwright": "2.0.1",
|
|
50
|
-
"chalk": "4.1.2",
|
|
51
51
|
"chalk-table": "^1.0.2",
|
|
52
52
|
"chokidar": "3.5.3",
|
|
53
53
|
"cucumber-json-report-formatter": "0.1.4",
|
|
54
|
-
"
|
|
55
|
-
"minimist": "1.2.8",
|
|
54
|
+
"lodash": "^4.17.21",
|
|
56
55
|
"multiple-cucumber-html-reporter": "3.6.2",
|
|
57
56
|
"nanoid": "^3.3.7",
|
|
58
57
|
"ts-node": "10.9.2",
|
|
@@ -88,7 +87,8 @@
|
|
|
88
87
|
},
|
|
89
88
|
"devDependencies": {
|
|
90
89
|
"@types/minimist": "1.2.5",
|
|
91
|
-
"@types/node": "20.
|
|
90
|
+
"@types/node": "20.12.7",
|
|
91
|
+
"chalk": "^4.1.2",
|
|
92
92
|
"cross-env": "7.0.3",
|
|
93
93
|
"eslint-plugin-cucumber": "2.0.0",
|
|
94
94
|
"eslint-plugin-jest": "27.9.0",
|