@uuv/playwright 2.17.3 → 3.0.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/dist/cucumber/preprocessor/index.d.ts +0 -1
- package/dist/cucumber/preprocessor/index.js +0 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/lib/config.d.ts +1 -0
- package/dist/lib/config.js +16 -0
- package/dist/lib/runner-playwright.d.ts +2 -7
- package/dist/lib/runner-playwright.js +18 -35
- package/dist/lib/watch-test-files.js +6 -6
- package/dist/reporter/uuv-playwright-reporter-helper.d.ts +1 -3
- package/dist/reporter/uuv-playwright-reporter-helper.js +19 -8
- package/package.json +4 -4
- package/postinstall.js +0 -1
- package/target-config/playwright.config.ts +4 -1
- package/dist/cucumber/preprocessor/gen/formatter.d.ts +0 -9
- package/dist/cucumber/preprocessor/gen/formatter.js +0 -59
- package/dist/cucumber/preprocessor/gen/generate.d.ts +0 -28
- package/dist/cucumber/preprocessor/gen/generate.js +0 -168
- package/dist/cucumber/preprocessor/gen/i18n.d.ts +0 -2
- package/dist/cucumber/preprocessor/gen/i18n.js +0 -36
- package/dist/cucumber/preprocessor/gen/index.d.ts +0 -8
- package/dist/cucumber/preprocessor/gen/index.js +0 -60
- package/dist/cucumber/preprocessor/gen/load_sources.d.ts +0 -17
- package/dist/cucumber/preprocessor/gen/load_sources.js +0 -46
- package/dist/cucumber/preprocessor/gen/save.d.ts +0 -2
- package/dist/cucumber/preprocessor/gen/save.js +0 -27
- package/dist/cucumber/preprocessor/run/fixtures.d.ts +0 -3
- package/dist/cucumber/preprocessor/run/fixtures.js +0 -32
- package/dist/cucumber/preprocessor/run/invoke.d.ts +0 -2
- package/dist/cucumber/preprocessor/run/invoke.js +0 -28
- package/dist/cucumber/preprocessor/run/support.d.ts +0 -9
- package/dist/cucumber/preprocessor/run/support.js +0 -27
- package/target-config/cucumber.cjs +0 -9
|
@@ -14,5 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./run/fixtures"), exports);
|
|
18
17
|
__exportStar(require("./run/world"), exports);
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function buildConfig(inputsPaths: string[], imports?: string[], output?: string): string;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildConfig = void 0;
|
|
4
|
+
const playwright_bdd_1 = require("playwright-bdd");
|
|
5
|
+
function buildConfig(inputsPaths, imports = [
|
|
6
|
+
"cucumber/step_definitions/**/*.{js,ts}",
|
|
7
|
+
"../node_modules/@uuv/playwright/dist/cucumber/step_definitions/playwright/**/*.js"
|
|
8
|
+
], output = ".uuv-features-gen") {
|
|
9
|
+
return (0, playwright_bdd_1.defineBddConfig)({
|
|
10
|
+
paths: inputsPaths,
|
|
11
|
+
require: imports,
|
|
12
|
+
outputDir: output,
|
|
13
|
+
featuresRoot: "e2e"
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
exports.buildConfig = buildConfig;
|
|
@@ -12,11 +12,6 @@
|
|
|
12
12
|
* understanding English or French.
|
|
13
13
|
*/
|
|
14
14
|
import { UUVCliOptions, UUVCliRunner } from "@uuv/runner-commons";
|
|
15
|
-
export interface UUVPlaywrightCucumberMapItem {
|
|
16
|
-
originalFile: string;
|
|
17
|
-
generatedFile: string;
|
|
18
|
-
}
|
|
19
|
-
export declare const UUVPlaywrightCucumberMapFile = ".uuv-playwright-cucumber-map.json";
|
|
20
15
|
export declare class UUVCliPlaywrightRunner implements UUVCliRunner {
|
|
21
16
|
projectDir: any;
|
|
22
17
|
private tempDir;
|
|
@@ -30,7 +25,7 @@ export declare class UUVCliPlaywrightRunner implements UUVCliRunner {
|
|
|
30
25
|
executeOpenCommand(options: Partial<UUVCliOptions>): void;
|
|
31
26
|
private getTargetTestFileForPlaywright;
|
|
32
27
|
private runPlaywright;
|
|
33
|
-
private executeSystemCommand;
|
|
34
28
|
private buildCommand;
|
|
29
|
+
private executeSystemCommand;
|
|
35
30
|
}
|
|
36
|
-
export declare function executePreprocessor(
|
|
31
|
+
export declare function executePreprocessor(): void;
|
|
@@ -39,15 +39,13 @@ 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.executePreprocessor = exports.UUVCliPlaywrightRunner =
|
|
42
|
+
exports.executePreprocessor = exports.UUVCliPlaywrightRunner = void 0;
|
|
43
43
|
const fs_1 = __importDefault(require("fs"));
|
|
44
|
-
const gen_1 = require("../cucumber/preprocessor/gen");
|
|
45
44
|
const chalk_1 = __importDefault(require("chalk"));
|
|
46
45
|
const uuv_playwright_reporter_helper_1 = require("../reporter/uuv-playwright-reporter-helper");
|
|
47
46
|
const path_1 = __importDefault(require("path"));
|
|
48
47
|
const child_process_1 = __importStar(require("child_process"));
|
|
49
48
|
const lodash_1 = __importDefault(require("lodash"));
|
|
50
|
-
exports.UUVPlaywrightCucumberMapFile = ".uuv-playwright-cucumber-map.json";
|
|
51
49
|
class UUVCliPlaywrightRunner {
|
|
52
50
|
projectDir;
|
|
53
51
|
tempDir;
|
|
@@ -64,7 +62,9 @@ class UUVCliPlaywrightRunner {
|
|
|
64
62
|
return JSON.parse(pJsonStr).version;
|
|
65
63
|
}
|
|
66
64
|
async prepare(options) {
|
|
67
|
-
|
|
65
|
+
console.log("running preprocessor...");
|
|
66
|
+
this.executeSystemCommand(`npx bddgen -c ${this.projectDir}/playwright.config.ts`);
|
|
67
|
+
console.log("preprocessor executed\n");
|
|
68
68
|
this.setEnvironmentVariables(options);
|
|
69
69
|
}
|
|
70
70
|
setEnvironmentVariables(options) {
|
|
@@ -93,7 +93,7 @@ class UUVCliPlaywrightRunner {
|
|
|
93
93
|
return "";
|
|
94
94
|
}
|
|
95
95
|
return `${targetTestFile
|
|
96
|
-
.replaceAll("uuv/e2e/", ".uuv-features-gen/
|
|
96
|
+
.replaceAll("uuv/e2e/", ".uuv-features-gen/")
|
|
97
97
|
.replaceAll(".feature", ".feature.spec.js")}`;
|
|
98
98
|
}
|
|
99
99
|
runPlaywright(options) {
|
|
@@ -113,10 +113,6 @@ class UUVCliPlaywrightRunner {
|
|
|
113
113
|
process.exit(2);
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
|
-
executeSystemCommand(command) {
|
|
117
|
-
console.log(chalk_1.default.gray(`Running command: ${command}`));
|
|
118
|
-
(0, child_process_1.execSync)(command, { stdio: "inherit" });
|
|
119
|
-
}
|
|
120
116
|
buildCommand(options, configFile, reporter) {
|
|
121
117
|
return lodash_1.default.trimEnd([
|
|
122
118
|
"npx",
|
|
@@ -129,37 +125,24 @@ class UUVCliPlaywrightRunner {
|
|
|
129
125
|
options.command === "open" ? "--ui" : "",
|
|
130
126
|
reporter
|
|
131
127
|
].join(" ")),
|
|
132
|
-
|
|
128
|
+
lodash_1.default.trimStart([
|
|
129
|
+
this.getTargetTestFileForPlaywright(options.targetTestFile),
|
|
130
|
+
options.extraArgs.TAGS ? `--grep ${options.extraArgs.TAGS}` : ""
|
|
131
|
+
].join(" "))
|
|
133
132
|
].join(" "));
|
|
134
133
|
}
|
|
134
|
+
executeSystemCommand(command) {
|
|
135
|
+
executeSystemCommandHelper(command);
|
|
136
|
+
}
|
|
135
137
|
}
|
|
136
138
|
exports.UUVCliPlaywrightRunner = UUVCliPlaywrightRunner;
|
|
137
|
-
|
|
139
|
+
function executeSystemCommandHelper(command) {
|
|
140
|
+
console.log(chalk_1.default.gray(`Running command: ${command}`));
|
|
141
|
+
(0, child_process_1.execSync)(command, { stdio: "inherit" });
|
|
142
|
+
}
|
|
143
|
+
function executePreprocessor() {
|
|
138
144
|
console.log("running preprocessor...");
|
|
139
|
-
|
|
145
|
+
executeSystemCommandHelper("npx bddgen");
|
|
140
146
|
console.log("preprocessor executed\n");
|
|
141
147
|
}
|
|
142
148
|
exports.executePreprocessor = executePreprocessor;
|
|
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" });
|
|
159
|
-
}
|
|
160
|
-
catch (err) {
|
|
161
|
-
console.error(chalk_1.default.red("Something went wrong..."));
|
|
162
|
-
console.dir(err);
|
|
163
|
-
process.exit(2);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
@@ -29,18 +29,18 @@ if (!tempDir || !projectDir) {
|
|
|
29
29
|
chokidar_1.default.watch(`${projectDir}/e2e/**/*.feature`, {
|
|
30
30
|
ignoreInitial: true
|
|
31
31
|
})
|
|
32
|
-
.on("change",
|
|
32
|
+
.on("change", () => {
|
|
33
33
|
console.log(chalk_1.default.yellowBright("\nRefreshing test files..."));
|
|
34
|
-
|
|
34
|
+
(0, runner_playwright_1.executePreprocessor)();
|
|
35
35
|
console.log(chalk_1.default.yellowBright("Test files refreshed\n"));
|
|
36
36
|
})
|
|
37
|
-
.on("add",
|
|
37
|
+
.on("add", path => {
|
|
38
38
|
console.log(chalk_1.default.yellowBright(`\nFile ${path} has been added`));
|
|
39
|
-
|
|
39
|
+
(0, runner_playwright_1.executePreprocessor)();
|
|
40
40
|
console.log(chalk_1.default.yellowBright("Test files refreshed\n"));
|
|
41
41
|
})
|
|
42
|
-
.on("unlink",
|
|
42
|
+
.on("unlink", path => {
|
|
43
43
|
console.log(chalk_1.default.yellowBright(`\nFile ${path} has been removed`));
|
|
44
|
-
|
|
44
|
+
(0, runner_playwright_1.executePreprocessor)();
|
|
45
45
|
console.log(chalk_1.default.yellowBright("Test files refreshed\n"));
|
|
46
46
|
});
|
|
@@ -5,7 +5,6 @@ export declare enum GeneratedReportType {
|
|
|
5
5
|
HTML = "html"
|
|
6
6
|
}
|
|
7
7
|
declare class UuvPlaywrightReporterHelper {
|
|
8
|
-
private UUVPlaywrightCucumberMap;
|
|
9
8
|
testDir: string;
|
|
10
9
|
private queries;
|
|
11
10
|
envelopes: Envelope[];
|
|
@@ -48,13 +47,12 @@ declare class UuvPlaywrightReporterHelper {
|
|
|
48
47
|
seconds: number;
|
|
49
48
|
nanos: number;
|
|
50
49
|
};
|
|
51
|
-
getOriginalFeatureFile(
|
|
50
|
+
getOriginalFeatureFile(generatedFile: string): string | undefined;
|
|
52
51
|
getCurrentRunningScenario(test: TestCase, featureFile: string): string;
|
|
53
52
|
private addError;
|
|
54
53
|
private getStatus;
|
|
55
54
|
private createEnvelope;
|
|
56
55
|
private createCucumberNdJsonFile;
|
|
57
|
-
private loadUUVPlaywrightCucumberMap;
|
|
58
56
|
private initializeCucumberReportNdJson;
|
|
59
57
|
private populateTestCasesAndPickleIdMap;
|
|
60
58
|
private updateTestcaseStatus;
|
|
@@ -8,13 +8,13 @@ const gherkin_1 = require("@cucumber/gherkin");
|
|
|
8
8
|
const gherkin_utils_1 = require("@cucumber/gherkin-utils");
|
|
9
9
|
const messages_1 = require("@cucumber/messages");
|
|
10
10
|
const fs_1 = __importDefault(require("fs"));
|
|
11
|
-
const runner_playwright_1 = require("../lib/runner-playwright");
|
|
12
11
|
const multiple_cucumber_html_reporter_1 = __importDefault(require("multiple-cucumber-html-reporter"));
|
|
13
12
|
const nanoid_1 = require("nanoid");
|
|
14
13
|
const chalk_1 = __importDefault(require("chalk"));
|
|
15
14
|
const chalk_table_1 = __importDefault(require("chalk-table"));
|
|
16
15
|
const uuv_custom_formatter_1 = require("./uuv-custom-formatter");
|
|
17
16
|
const tag_expressions_1 = __importDefault(require("@cucumber/tag-expressions"));
|
|
17
|
+
const path_1 = __importDefault(require("path"));
|
|
18
18
|
const NANOS_IN_SECOND = 1000000000;
|
|
19
19
|
const NANOS_IN_MILLISSECOND = 1000000;
|
|
20
20
|
var GeneratedReportType;
|
|
@@ -39,7 +39,6 @@ class ReportOfFeature {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
class UuvPlaywrightReporterHelper {
|
|
42
|
-
UUVPlaywrightCucumberMap = [];
|
|
43
42
|
testDir;
|
|
44
43
|
queries = new Map();
|
|
45
44
|
envelopes = [];
|
|
@@ -53,7 +52,6 @@ class UuvPlaywrightReporterHelper {
|
|
|
53
52
|
currentFeatureFile;
|
|
54
53
|
createTestRunStartedEnvelope(config, suite, startTimestamp) {
|
|
55
54
|
this.testDir = config.projects[0].testDir;
|
|
56
|
-
this.loadUUVPlaywrightCucumberMap();
|
|
57
55
|
const featureFiles = this.getFeatureFiles(suite);
|
|
58
56
|
this.initializeCucumberReportNdJson(suite, featureFiles);
|
|
59
57
|
this.envelopes.push(this.createEnvelope({
|
|
@@ -292,8 +290,24 @@ class UuvPlaywrightReporterHelper {
|
|
|
292
290
|
nanos: Math.floor(durationInSecond * NANOS_IN_SECOND + durationInSecond)
|
|
293
291
|
};
|
|
294
292
|
}
|
|
295
|
-
getOriginalFeatureFile(
|
|
296
|
-
|
|
293
|
+
getOriginalFeatureFile(generatedFile) {
|
|
294
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
295
|
+
// @ts-ignore
|
|
296
|
+
const bddgenConfAsString = process.env.PLAYWRIGHT_BDD_CONFIGS;
|
|
297
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
298
|
+
// @ts-ignore
|
|
299
|
+
const projectDir = process.env.CONFIG_DIR;
|
|
300
|
+
if (bddgenConfAsString && projectDir) {
|
|
301
|
+
const bddgenConf = JSON.parse(bddgenConfAsString);
|
|
302
|
+
const foundPath = Object.keys(bddgenConf).find(key => generatedFile.startsWith(key));
|
|
303
|
+
if (foundPath) {
|
|
304
|
+
const foundConf = bddgenConf[foundPath];
|
|
305
|
+
return path_1.default.relative(process.cwd(), generatedFile
|
|
306
|
+
.replaceAll(foundConf.outputDir, foundConf.featuresRoot)
|
|
307
|
+
.replaceAll(".feature.spec.js", ".feature"));
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return;
|
|
297
311
|
}
|
|
298
312
|
getCurrentRunningScenario(test, featureFile) {
|
|
299
313
|
const counter = `[${test.parent.allTests().filter(test => test.results.length > 0).length}/${test.parent.allTests().length}]`;
|
|
@@ -326,9 +340,6 @@ class UuvPlaywrightReporterHelper {
|
|
|
326
340
|
console.log(err);
|
|
327
341
|
}
|
|
328
342
|
}
|
|
329
|
-
loadUUVPlaywrightCucumberMap() {
|
|
330
|
-
this.UUVPlaywrightCucumberMap = JSON.parse(fs_1.default.readFileSync(`${this.testDir}/${runner_playwright_1.UUVPlaywrightCucumberMapFile}`, { encoding: "utf8" }));
|
|
331
|
-
}
|
|
332
343
|
initializeCucumberReportNdJson(suite, featureFiles) {
|
|
333
344
|
featureFiles.forEach(featureFile => {
|
|
334
345
|
const originalFile = this.getOriginalFeatureFile(featureFile);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uuv/playwright",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
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",
|
|
@@ -42,10 +42,9 @@
|
|
|
42
42
|
"test": "npm run unit-test && npm run e2e-test:run"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@cucumber/cucumber": "9.6.0",
|
|
46
45
|
"@cucumber/tag-expressions": "^6.0.0",
|
|
47
|
-
"@playwright/test": "1.44.1",
|
|
48
|
-
"@uuv/runner-commons": "2.16.
|
|
46
|
+
"@playwright/test": "^1.44.1",
|
|
47
|
+
"@uuv/runner-commons": "2.16.3",
|
|
49
48
|
"axe-core": "4.9.1",
|
|
50
49
|
"axe-playwright": "2.0.1",
|
|
51
50
|
"chalk-table": "^1.0.2",
|
|
@@ -54,6 +53,7 @@
|
|
|
54
53
|
"lodash": "^4.17.21",
|
|
55
54
|
"multiple-cucumber-html-reporter": "3.6.2",
|
|
56
55
|
"nanoid": "^3.3.7",
|
|
56
|
+
"playwright-bdd": "^6.5.0",
|
|
57
57
|
"ts-node": "10.9.2",
|
|
58
58
|
"typescript": "5.4.5"
|
|
59
59
|
},
|
package/postinstall.js
CHANGED
|
@@ -41,7 +41,6 @@ function copyFileIfMissing(fileToCopy, originFolder, destFolder) {
|
|
|
41
41
|
function main () {
|
|
42
42
|
if (fs.existsSync(`${PROJECT_DIR}/package.json`) && !fs.existsSync(`${PROJECT_DIR}/.no-postinstall`)) {
|
|
43
43
|
copyFileIfMissing("playwright.config.ts", `${TARGET_CONFIG_DIR}`, `${PROJECT_DIR}/uuv`);
|
|
44
|
-
copyFileIfMissing("cucumber.cjs", `${TARGET_CONFIG_DIR}`, `${PROJECT_DIR}`);
|
|
45
44
|
execSync("npx playwright install", { stdio: "inherit" });
|
|
46
45
|
} else {
|
|
47
46
|
console.log("postinstall - Nothing to copy");
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { defineConfig, devices } from "@playwright/test";
|
|
2
|
+
import { buildConfig } from "@uuv/playwright";
|
|
2
3
|
|
|
3
4
|
export default defineConfig({
|
|
4
|
-
testDir:
|
|
5
|
+
testDir: buildConfig(
|
|
6
|
+
["e2e/*.feature"]
|
|
7
|
+
),
|
|
5
8
|
testMatch: ["**/*.spec.ts", "**/*.{ts,js}"],
|
|
6
9
|
fullyParallel: true,
|
|
7
10
|
forbidOnly: !!process.env.CI,
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Helpers to format Playwright test file.
|
|
3
|
-
*/
|
|
4
|
-
import { PickleStepArgument } from "@cucumber/messages";
|
|
5
|
-
export declare function fileHeader(uri?: string): string[];
|
|
6
|
-
export declare function suite(title: string, children: string[]): string[];
|
|
7
|
-
export declare function beforeEach(keywords: Set<string>, children: string[]): string[];
|
|
8
|
-
export declare function test(title: string, keywords: Set<string>, children: string[]): string[];
|
|
9
|
-
export declare function step(keyword: string, text: string, argument?: PickleStepArgument): string;
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Helpers to format Playwright test file.
|
|
4
|
-
*/
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.step = exports.test = exports.beforeEach = exports.suite = exports.fileHeader = void 0;
|
|
7
|
-
function fileHeader(uri) {
|
|
8
|
-
// prettier-ignore
|
|
9
|
-
return [
|
|
10
|
-
`/** Generated from: ${uri} */`,
|
|
11
|
-
"import { test } from \"@uuv/playwright\";",
|
|
12
|
-
"",
|
|
13
|
-
];
|
|
14
|
-
}
|
|
15
|
-
exports.fileHeader = fileHeader;
|
|
16
|
-
function suite(title, children) {
|
|
17
|
-
// prettier-ignore
|
|
18
|
-
return [
|
|
19
|
-
`test.describe(${JSON.stringify(title)}, () => {`,
|
|
20
|
-
"",
|
|
21
|
-
...children.map(indent),
|
|
22
|
-
"});",
|
|
23
|
-
"",
|
|
24
|
-
];
|
|
25
|
-
}
|
|
26
|
-
exports.suite = suite;
|
|
27
|
-
function beforeEach(keywords, children) {
|
|
28
|
-
const fixtures = [...keywords].join(", ");
|
|
29
|
-
// prettier-ignore
|
|
30
|
-
return [
|
|
31
|
-
`test.beforeEach(async ({ ${fixtures} }) => {`,
|
|
32
|
-
...children.map(indent),
|
|
33
|
-
"});",
|
|
34
|
-
"",
|
|
35
|
-
];
|
|
36
|
-
}
|
|
37
|
-
exports.beforeEach = beforeEach;
|
|
38
|
-
function test(title, keywords, children) {
|
|
39
|
-
const fixtures = [...keywords].join(", ");
|
|
40
|
-
// prettier-ignore
|
|
41
|
-
return [
|
|
42
|
-
`test(${JSON.stringify(title)}, async ({ ${fixtures} }) => {`,
|
|
43
|
-
...children.map(indent),
|
|
44
|
-
"});",
|
|
45
|
-
"",
|
|
46
|
-
];
|
|
47
|
-
}
|
|
48
|
-
exports.test = test;
|
|
49
|
-
function step(keyword, text, argument) {
|
|
50
|
-
const args = [text, argument]
|
|
51
|
-
.filter(Boolean)
|
|
52
|
-
.map((arg) => JSON.stringify(arg))
|
|
53
|
-
.join(", ");
|
|
54
|
-
return `await test.step('${keyword} ${text.replaceAll("'", "\\'")}', async () => {\n\t\tawait ${keyword}(${args});\n\t});`;
|
|
55
|
-
}
|
|
56
|
-
exports.step = step;
|
|
57
|
-
function indent(value) {
|
|
58
|
-
return value ? `${" "}${value}` : value;
|
|
59
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generate test code.
|
|
3
|
-
*/
|
|
4
|
-
import { GherkinDocument, Pickle } from "@cucumber/messages";
|
|
5
|
-
export declare class PWFile {
|
|
6
|
-
doc: GherkinDocument;
|
|
7
|
-
private pickles;
|
|
8
|
-
private readonly tags?;
|
|
9
|
-
private lines;
|
|
10
|
-
private keywordsMap?;
|
|
11
|
-
private tagsExpression;
|
|
12
|
-
constructor(doc: GherkinDocument, pickles: Pickle[], tags?: string | undefined);
|
|
13
|
-
get content(): string;
|
|
14
|
-
get language(): string;
|
|
15
|
-
build(): this;
|
|
16
|
-
private loadI18nKeywords;
|
|
17
|
-
private getRootSuite;
|
|
18
|
-
private getSuite;
|
|
19
|
-
private getSuiteChild;
|
|
20
|
-
private getScenarioLines;
|
|
21
|
-
private getBeforeEach;
|
|
22
|
-
private getOutlineSuite;
|
|
23
|
-
private getTest;
|
|
24
|
-
private getSteps;
|
|
25
|
-
private getStep;
|
|
26
|
-
private getPickleStep;
|
|
27
|
-
private getKeyword;
|
|
28
|
-
}
|
|
@@ -1,168 +0,0 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.PWFile = void 0;
|
|
30
|
-
const formatter = __importStar(require("./formatter"));
|
|
31
|
-
const i18n_1 = require("./i18n");
|
|
32
|
-
const tag_expressions_1 = __importDefault(require("@cucumber/tag-expressions"));
|
|
33
|
-
class PWFile {
|
|
34
|
-
doc;
|
|
35
|
-
pickles;
|
|
36
|
-
tags;
|
|
37
|
-
lines = [];
|
|
38
|
-
keywordsMap;
|
|
39
|
-
tagsExpression;
|
|
40
|
-
constructor(doc, pickles, tags) {
|
|
41
|
-
this.doc = doc;
|
|
42
|
-
this.pickles = pickles;
|
|
43
|
-
this.tags = tags;
|
|
44
|
-
if (tags) {
|
|
45
|
-
this.tagsExpression = (0, tag_expressions_1.default)(tags);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
get content() {
|
|
49
|
-
return this.lines.join("\n");
|
|
50
|
-
}
|
|
51
|
-
get language() {
|
|
52
|
-
return this.doc.feature?.language || "en";
|
|
53
|
-
}
|
|
54
|
-
build() {
|
|
55
|
-
this.loadI18nKeywords();
|
|
56
|
-
this.lines = [...formatter.fileHeader(this.doc.uri), ...this.getRootSuite()];
|
|
57
|
-
return this;
|
|
58
|
-
}
|
|
59
|
-
loadI18nKeywords() {
|
|
60
|
-
if (this.language !== "en") {
|
|
61
|
-
this.keywordsMap = (0, i18n_1.getKeywordsMap)(this.language);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
getRootSuite() {
|
|
65
|
-
if (!this.doc.feature) {
|
|
66
|
-
throw new Error("Document without feature.");
|
|
67
|
-
}
|
|
68
|
-
return this.getSuite(this.doc.feature);
|
|
69
|
-
}
|
|
70
|
-
getSuite({ name, children }) {
|
|
71
|
-
const lines = [];
|
|
72
|
-
children.forEach((child) => lines.push(...this.getSuiteChild(child)));
|
|
73
|
-
return formatter.suite(name, lines);
|
|
74
|
-
}
|
|
75
|
-
getSuiteChild(child) {
|
|
76
|
-
if ("rule" in child && child.rule) {
|
|
77
|
-
return this.getSuite(child.rule);
|
|
78
|
-
}
|
|
79
|
-
const { background, scenario } = child;
|
|
80
|
-
if (background) {
|
|
81
|
-
return this.getBeforeEach(background);
|
|
82
|
-
}
|
|
83
|
-
if (scenario) {
|
|
84
|
-
if (this.tagsExpression) {
|
|
85
|
-
if (this.tagsExpression.evaluate(scenario.tags.map(tag => tag.name))) {
|
|
86
|
-
return this.getScenarioLines(scenario);
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
return [];
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
return this.getScenarioLines(scenario);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
throw new Error(`Empty child: ${JSON.stringify(child)}`);
|
|
97
|
-
}
|
|
98
|
-
getScenarioLines(scenario) {
|
|
99
|
-
return isOutline(scenario) ? this.getOutlineSuite(scenario) : this.getTest(scenario);
|
|
100
|
-
}
|
|
101
|
-
getBeforeEach(bg) {
|
|
102
|
-
const { keywords, lines } = this.getSteps(bg);
|
|
103
|
-
return formatter.beforeEach(keywords, lines);
|
|
104
|
-
}
|
|
105
|
-
getOutlineSuite(scenario) {
|
|
106
|
-
const suiteLines = [];
|
|
107
|
-
let exampleIndex = 0;
|
|
108
|
-
scenario.examples.forEach((example) => {
|
|
109
|
-
example.tableBody.forEach((exampleRow) => {
|
|
110
|
-
const title = `Example #${++exampleIndex}`;
|
|
111
|
-
const { keywords, lines } = this.getSteps(scenario, exampleRow.id);
|
|
112
|
-
const testLines = formatter.test(title, keywords, lines);
|
|
113
|
-
suiteLines.push(...testLines);
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
return formatter.suite(scenario.name, suiteLines);
|
|
117
|
-
}
|
|
118
|
-
getTest(scenario) {
|
|
119
|
-
const { keywords, lines } = this.getSteps(scenario);
|
|
120
|
-
return formatter.test(scenario.name, keywords, lines);
|
|
121
|
-
}
|
|
122
|
-
getSteps(scenario, outlineExampleRowId) {
|
|
123
|
-
const keywords = new Set();
|
|
124
|
-
const lines = scenario.steps.map((step) => {
|
|
125
|
-
const pickleStep = this.getPickleStep(step, outlineExampleRowId);
|
|
126
|
-
const { keyword, line } = this.getStep(step, pickleStep);
|
|
127
|
-
keywords.add(keyword);
|
|
128
|
-
return line;
|
|
129
|
-
});
|
|
130
|
-
return { keywords, lines };
|
|
131
|
-
}
|
|
132
|
-
getStep(step, { text, argument }) {
|
|
133
|
-
const keyword = this.getKeyword(step);
|
|
134
|
-
const line = formatter.step(keyword, text, argument);
|
|
135
|
-
return { keyword, line };
|
|
136
|
-
}
|
|
137
|
-
getPickleStep(step, outlineExampleRowId) {
|
|
138
|
-
for (const pickle of this.pickles) {
|
|
139
|
-
const pickleStep = pickle.steps.find(({ astNodeIds }) => {
|
|
140
|
-
const hasStepId = astNodeIds.includes(step.id);
|
|
141
|
-
const hasRowId = !outlineExampleRowId || astNodeIds.includes(outlineExampleRowId);
|
|
142
|
-
return hasStepId && hasRowId;
|
|
143
|
-
});
|
|
144
|
-
if (pickleStep) {
|
|
145
|
-
return pickleStep;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
throw new Error(`Pickle step not found for step: ${step.text}`);
|
|
149
|
-
}
|
|
150
|
-
getKeyword(step) {
|
|
151
|
-
const origKeyword = step.keyword.trim();
|
|
152
|
-
if (origKeyword === "*") {
|
|
153
|
-
return "And";
|
|
154
|
-
}
|
|
155
|
-
if (!this.keywordsMap) {
|
|
156
|
-
return origKeyword;
|
|
157
|
-
}
|
|
158
|
-
const enKeyword = this.keywordsMap.get(origKeyword);
|
|
159
|
-
if (!enKeyword) {
|
|
160
|
-
throw new Error(`Keyword not found: ${origKeyword}`);
|
|
161
|
-
}
|
|
162
|
-
return enKeyword;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
exports.PWFile = PWFile;
|
|
166
|
-
function isOutline(scenario) {
|
|
167
|
-
return scenario.keyword === "Scenario Outline";
|
|
168
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getKeywordsMap = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Get i18n keywords.
|
|
6
|
-
* See: https://github.com/cucumber/cucumber-js/blob/main/src/cli/i18n.ts
|
|
7
|
-
*/
|
|
8
|
-
const gherkin_1 = require("@cucumber/gherkin");
|
|
9
|
-
function getKeywordsMap(language) {
|
|
10
|
-
const origMap = gherkin_1.dialects[language];
|
|
11
|
-
if (!origMap) {
|
|
12
|
-
throw new Error(`Language not found: ${language}`);
|
|
13
|
-
}
|
|
14
|
-
const targetMap = new Map();
|
|
15
|
-
const enKeywords = Object.keys(origMap);
|
|
16
|
-
enKeywords.forEach((enKeyword) => handleKeyword(enKeyword, origMap, targetMap));
|
|
17
|
-
return targetMap;
|
|
18
|
-
}
|
|
19
|
-
exports.getKeywordsMap = getKeywordsMap;
|
|
20
|
-
function handleKeyword(enKeyword, origMap, targetMap) {
|
|
21
|
-
const nativeKeywords = origMap[enKeyword];
|
|
22
|
-
// Array.isArray converts to any[]
|
|
23
|
-
if (typeof nativeKeywords === "string") {
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
nativeKeywords.forEach((nativeKeyword) => {
|
|
27
|
-
nativeKeyword = nativeKeyword.trim();
|
|
28
|
-
if (!nativeKeyword || nativeKeyword === "*") {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
targetMap.set(nativeKeyword, capitalizeFirstLetter(enKeyword));
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
function capitalizeFirstLetter(s) {
|
|
35
|
-
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
36
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { GherkinDocument } from "@cucumber/messages";
|
|
2
|
-
export type GenOptions = {
|
|
3
|
-
outputDir?: string;
|
|
4
|
-
cucumberConfig?: string;
|
|
5
|
-
cwd?: string;
|
|
6
|
-
tags?: string;
|
|
7
|
-
};
|
|
8
|
-
export declare function generateTestFiles(inputOptions?: GenOptions): Promise<Map<string, GherkinDocument>>;
|
|
@@ -1,60 +0,0 @@
|
|
|
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.generateTestFiles = void 0;
|
|
7
|
-
/**
|
|
8
|
-
* Generate playwright tests from Gherkin documents.
|
|
9
|
-
*/
|
|
10
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
11
|
-
const api_1 = require("@cucumber/cucumber/api");
|
|
12
|
-
const load_sources_1 = require("./load_sources");
|
|
13
|
-
const generate_1 = require("./generate");
|
|
14
|
-
const save_1 = require("./save");
|
|
15
|
-
const defaults = {
|
|
16
|
-
outputDir: ".features-gen",
|
|
17
|
-
cwd: process.cwd(),
|
|
18
|
-
};
|
|
19
|
-
async function generateTestFiles(inputOptions) {
|
|
20
|
-
const { outputDir, cwd, cucumberConfig, tags } = Object.assign({}, defaults, inputOptions);
|
|
21
|
-
const features = await loadFeatures({ file: cucumberConfig }, { cwd });
|
|
22
|
-
const files = buildFiles(features, tags);
|
|
23
|
-
const paths = (0, save_1.saveFiles)(files, node_path_1.default.join(cwd, outputDir));
|
|
24
|
-
const mapOfFile = new Map();
|
|
25
|
-
paths.forEach((path, index) => mapOfFile.set(path, Array.from(features.keys())[index]));
|
|
26
|
-
return mapOfFile;
|
|
27
|
-
}
|
|
28
|
-
exports.generateTestFiles = generateTestFiles;
|
|
29
|
-
async function loadFeatures(options, environment) {
|
|
30
|
-
const { runConfiguration } = await (0, api_1.loadConfiguration)(options, environment);
|
|
31
|
-
const { filteredPickles, parseErrors } = await (0, load_sources_1.loadSources)(runConfiguration.sources, environment);
|
|
32
|
-
handleParseErrors(parseErrors);
|
|
33
|
-
return groupByDocument(filteredPickles);
|
|
34
|
-
}
|
|
35
|
-
function buildFiles(features, tags) {
|
|
36
|
-
const files = [];
|
|
37
|
-
features.forEach((pickles, doc) => files.push(new generate_1.PWFile(doc, pickles, tags).build()));
|
|
38
|
-
return files;
|
|
39
|
-
}
|
|
40
|
-
function groupByDocument(filteredPickles) {
|
|
41
|
-
const features = new Map();
|
|
42
|
-
filteredPickles.forEach(({ pickle, gherkinDocument }) => {
|
|
43
|
-
let pickles = features.get(gherkinDocument);
|
|
44
|
-
if (!pickles) {
|
|
45
|
-
pickles = [];
|
|
46
|
-
features.set(gherkinDocument, pickles);
|
|
47
|
-
}
|
|
48
|
-
pickles.push(pickle);
|
|
49
|
-
});
|
|
50
|
-
return features;
|
|
51
|
-
}
|
|
52
|
-
function handleParseErrors(parseErrors) {
|
|
53
|
-
if (parseErrors.length) {
|
|
54
|
-
parseErrors.forEach((parseError) => {
|
|
55
|
-
// eslint-disable-next-line no-console
|
|
56
|
-
console.error(`Parse error in "${parseError.source.uri}" ${parseError.message}`);
|
|
57
|
-
});
|
|
58
|
-
process.exit(1);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copied from original load_sources, but returns full Pickles.
|
|
3
|
-
* See: https://github.com/cucumber/cucumber-js/blob/main/src/api/load_sources.ts
|
|
4
|
-
*/
|
|
5
|
-
/// <reference types="packages/runner-playwright/src/cucumber/preprocessor/gen/gherkin" />
|
|
6
|
-
import { IRunEnvironment, ISourcesCoordinates } from "@cucumber/cucumber/lib/api/types";
|
|
7
|
-
/**
|
|
8
|
-
* Load and parse features, produce a filtered and ordered test plan and/or parse errors.
|
|
9
|
-
*
|
|
10
|
-
* @public
|
|
11
|
-
* @param coordinates - Coordinates required to find features
|
|
12
|
-
* @param environment - Project environment.
|
|
13
|
-
*/
|
|
14
|
-
export declare function loadSources(coordinates: ISourcesCoordinates, environment?: IRunEnvironment): Promise<{
|
|
15
|
-
filteredPickles: import("@cucumber/cucumber/lib/api/gherkin").PickleWithDocument[];
|
|
16
|
-
parseErrors: import("@cucumber/messages").ParseError[];
|
|
17
|
-
}>;
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Copied from original load_sources, but returns full Pickles.
|
|
4
|
-
* See: https://github.com/cucumber/cucumber-js/blob/main/src/api/load_sources.ts
|
|
5
|
-
*/
|
|
6
|
-
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
|
|
7
|
-
/// <reference path="./gherkin.d.ts" />
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.loadSources = void 0;
|
|
10
|
-
const paths_1 = require("@cucumber/cucumber/lib/api/paths");
|
|
11
|
-
const messages_1 = require("@cucumber/messages");
|
|
12
|
-
const environment_1 = require("@cucumber/cucumber/lib/api/environment");
|
|
13
|
-
const gherkin_1 = require("@cucumber/cucumber/lib/api/gherkin");
|
|
14
|
-
const console_logger_1 = require("@cucumber/cucumber/lib/api/console_logger");
|
|
15
|
-
/**
|
|
16
|
-
* Load and parse features, produce a filtered and ordered test plan and/or parse errors.
|
|
17
|
-
*
|
|
18
|
-
* @public
|
|
19
|
-
* @param coordinates - Coordinates required to find features
|
|
20
|
-
* @param environment - Project environment.
|
|
21
|
-
*/
|
|
22
|
-
async function loadSources(coordinates, environment = {}) {
|
|
23
|
-
const { cwd, stderr, debug } = (0, environment_1.mergeEnvironment)(environment);
|
|
24
|
-
const logger = new console_logger_1.ConsoleLogger(stderr, debug);
|
|
25
|
-
const newId = messages_1.IdGenerator.uuid();
|
|
26
|
-
const { unexpandedFeaturePaths, featurePaths } = await (0, paths_1.resolvePaths)(logger, cwd, coordinates);
|
|
27
|
-
if (featurePaths.length === 0) {
|
|
28
|
-
return {
|
|
29
|
-
filteredPickles: [],
|
|
30
|
-
parseErrors: [],
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
const { filteredPickles, parseErrors } = await (0, gherkin_1.getFilteredPicklesAndErrors)({
|
|
34
|
-
newId,
|
|
35
|
-
cwd,
|
|
36
|
-
logger,
|
|
37
|
-
unexpandedFeaturePaths,
|
|
38
|
-
featurePaths,
|
|
39
|
-
coordinates,
|
|
40
|
-
});
|
|
41
|
-
return {
|
|
42
|
-
filteredPickles,
|
|
43
|
-
parseErrors,
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
exports.loadSources = loadSources;
|
|
@@ -1,27 +0,0 @@
|
|
|
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.saveFiles = void 0;
|
|
7
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
-
const node_fs_1 = __importDefault(require("node:fs"));
|
|
9
|
-
function saveFiles(files, outputDir) {
|
|
10
|
-
clearDir(outputDir);
|
|
11
|
-
const paths = files.map((file) => {
|
|
12
|
-
const filePath = node_path_1.default.join(outputDir, `${file.doc.uri}.spec.js`);
|
|
13
|
-
const dir = node_path_1.default.dirname(filePath);
|
|
14
|
-
if (!node_fs_1.default.existsSync(dir)) {
|
|
15
|
-
node_fs_1.default.mkdirSync(dir, { recursive: true });
|
|
16
|
-
}
|
|
17
|
-
node_fs_1.default.writeFileSync(filePath, file.content);
|
|
18
|
-
return filePath;
|
|
19
|
-
});
|
|
20
|
-
return paths;
|
|
21
|
-
}
|
|
22
|
-
exports.saveFiles = saveFiles;
|
|
23
|
-
function clearDir(dir) {
|
|
24
|
-
if (node_fs_1.default.existsSync(dir)) {
|
|
25
|
-
node_fs_1.default.rmSync(dir, { recursive: true });
|
|
26
|
-
}
|
|
27
|
-
}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
export declare const test: import("@playwright/test").TestType<import("@playwright/test").PlaywrightTestArgs & import("@playwright/test").PlaywrightTestOptions & {
|
|
2
|
-
[key: string]: any;
|
|
3
|
-
}, import("@playwright/test").PlaywrightWorkerArgs & import("@playwright/test").PlaywrightWorkerOptions>;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.test = void 0;
|
|
4
|
-
const test_1 = require("@playwright/test");
|
|
5
|
-
const support_1 = require("./support");
|
|
6
|
-
const invoke_1 = require("./invoke");
|
|
7
|
-
exports.test = test_1.test.extend({
|
|
8
|
-
world: async ({ page, context, browser, browserName, request }, use, testInfo) => {
|
|
9
|
-
const { runConfiguration, supportCodeLibrary } = await (0, support_1.loadCucumber)();
|
|
10
|
-
const World = (0, support_1.getWorldConstructor)(supportCodeLibrary);
|
|
11
|
-
const world = new World({
|
|
12
|
-
page,
|
|
13
|
-
context,
|
|
14
|
-
browser,
|
|
15
|
-
browserName,
|
|
16
|
-
request,
|
|
17
|
-
testInfo,
|
|
18
|
-
parameters: runConfiguration.runtime.worldParameters || {},
|
|
19
|
-
log: () => { }, // eslint-disable-line @typescript-eslint/no-empty-function
|
|
20
|
-
attach: async () => { }, // eslint-disable-line @typescript-eslint/no-empty-function
|
|
21
|
-
});
|
|
22
|
-
await world.init();
|
|
23
|
-
await use(world);
|
|
24
|
-
await world.destroy();
|
|
25
|
-
},
|
|
26
|
-
invokeStep: ({ world }, use) => use(invoke_1.invokeStep.bind(null, world)),
|
|
27
|
-
Given: ({ invokeStep }, use) => use(invokeStep),
|
|
28
|
-
When: ({ invokeStep }, use) => use(invokeStep),
|
|
29
|
-
Then: ({ invokeStep }, use) => use(invokeStep),
|
|
30
|
-
And: ({ invokeStep }, use) => use(invokeStep),
|
|
31
|
-
But: ({ invokeStep }, use) => use(invokeStep),
|
|
32
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.invokeStep = void 0;
|
|
4
|
-
const support_1 = require("./support");
|
|
5
|
-
async function invokeStep(world, text, argument) {
|
|
6
|
-
const stepDefinition = await findStepDefinition(text);
|
|
7
|
-
const { parameters } = await stepDefinition.getInvocationParameters({
|
|
8
|
-
hookParameter: {},
|
|
9
|
-
step: { text, argument },
|
|
10
|
-
world,
|
|
11
|
-
});
|
|
12
|
-
return stepDefinition.code.apply(world, parameters);
|
|
13
|
-
}
|
|
14
|
-
exports.invokeStep = invokeStep;
|
|
15
|
-
async function findStepDefinition(stepText) {
|
|
16
|
-
const { supportCodeLibrary } = await (0, support_1.loadCucumber)();
|
|
17
|
-
const stepDefinitions = supportCodeLibrary.stepDefinitions.filter((step) => {
|
|
18
|
-
return step.matchesStepName(stepText);
|
|
19
|
-
});
|
|
20
|
-
if (!stepDefinitions.length) {
|
|
21
|
-
throw new Error(`Unknown step: ${stepText}`);
|
|
22
|
-
}
|
|
23
|
-
if (stepDefinitions.length > 1) {
|
|
24
|
-
throw new Error([`Several steps found for text: ${stepText}`, ...stepDefinitions.map((s) => `- ${s.pattern}`)].join("\n"));
|
|
25
|
-
}
|
|
26
|
-
// todo: check stepDefinition.keyword with PickleStepType
|
|
27
|
-
return stepDefinitions[0];
|
|
28
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { IRunConfiguration } from "@cucumber/cucumber/api";
|
|
2
|
-
import { ISupportCodeLibrary } from "@cucumber/cucumber/lib/support_code_library_builder/types";
|
|
3
|
-
import { World } from "./world";
|
|
4
|
-
export type LoadedCucumber = {
|
|
5
|
-
runConfiguration: IRunConfiguration;
|
|
6
|
-
supportCodeLibrary: ISupportCodeLibrary;
|
|
7
|
-
};
|
|
8
|
-
export declare function loadCucumber(): Promise<LoadedCucumber>;
|
|
9
|
-
export declare function getWorldConstructor(supportCodeLibrary: ISupportCodeLibrary): typeof World;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getWorldConstructor = exports.loadCucumber = void 0;
|
|
4
|
-
const api_1 = require("@cucumber/cucumber/api");
|
|
5
|
-
const cucumber_1 = require("@cucumber/cucumber");
|
|
6
|
-
const world_1 = require("./world");
|
|
7
|
-
let loadedCucumber;
|
|
8
|
-
async function loadCucumber() {
|
|
9
|
-
if (!loadedCucumber) {
|
|
10
|
-
const { runConfiguration } = await (0, api_1.loadConfiguration)();
|
|
11
|
-
const supportCodeLibrary = await (0, api_1.loadSupport)(runConfiguration);
|
|
12
|
-
loadedCucumber = { runConfiguration, supportCodeLibrary };
|
|
13
|
-
}
|
|
14
|
-
return loadedCucumber;
|
|
15
|
-
}
|
|
16
|
-
exports.loadCucumber = loadCucumber;
|
|
17
|
-
function getWorldConstructor(supportCodeLibrary) {
|
|
18
|
-
// setWorldConstructor was not called
|
|
19
|
-
if (supportCodeLibrary.World === cucumber_1.World) {
|
|
20
|
-
return world_1.World;
|
|
21
|
-
}
|
|
22
|
-
if (!Object.prototype.isPrototypeOf.call(world_1.World, supportCodeLibrary.World)) {
|
|
23
|
-
throw new Error("CustomWorld should inherit from playwright-bdd World");
|
|
24
|
-
}
|
|
25
|
-
return supportCodeLibrary.World;
|
|
26
|
-
}
|
|
27
|
-
exports.getWorldConstructor = getWorldConstructor;
|