@zohodesk/testinglibrary 0.1.8-exp-bdd-v3 → 0.1.8-exp-bdd-v4
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/.eslintrc.js +5 -1
- package/build/bdd-framework/cli/commands/env.js +42 -0
- package/build/bdd-framework/cli/commands/export.js +47 -0
- package/build/bdd-framework/cli/commands/test.js +64 -0
- package/build/bdd-framework/cli/index.js +11 -0
- package/build/bdd-framework/cli/options.js +19 -0
- package/build/bdd-framework/cli/worker.js +13 -0
- package/build/bdd-framework/config/dir.js +27 -0
- package/build/bdd-framework/config/env.js +50 -0
- package/build/bdd-framework/config/index.js +90 -0
- package/build/bdd-framework/config/lang.js +14 -0
- package/build/bdd-framework/cucumber/buildStepDefinition.js +43 -0
- package/build/bdd-framework/cucumber/gherkin.d.js +5 -0
- package/build/bdd-framework/cucumber/loadConfig.js +17 -0
- package/build/bdd-framework/cucumber/loadFeatures.js +39 -0
- package/build/bdd-framework/cucumber/loadSnippetBuilder.js +20 -0
- package/build/bdd-framework/cucumber/loadSources.js +57 -0
- package/build/bdd-framework/cucumber/loadSteps.js +40 -0
- package/build/bdd-framework/decorators.js +18 -0
- package/build/bdd-framework/gen/fixtures.js +48 -0
- package/build/bdd-framework/gen/formatter.js +135 -0
- package/build/bdd-framework/gen/i18n.js +39 -0
- package/build/bdd-framework/gen/index.js +164 -0
- package/build/bdd-framework/gen/testFile.js +422 -0
- package/build/bdd-framework/gen/testNode.js +61 -0
- package/build/bdd-framework/gen/testPoms.js +133 -0
- package/build/bdd-framework/hooks/scenario.js +107 -0
- package/build/bdd-framework/hooks/worker.js +83 -0
- package/build/bdd-framework/index.js +45 -0
- package/build/bdd-framework/playwright/fixtureParameterNames.js +93 -0
- package/build/bdd-framework/playwright/getLocationInFile.js +52 -0
- package/build/bdd-framework/playwright/loadConfig.js +42 -0
- package/build/bdd-framework/playwright/testTypeImpl.js +61 -0
- package/build/bdd-framework/playwright/transform.js +84 -0
- package/build/bdd-framework/playwright/types.js +5 -0
- package/build/bdd-framework/playwright/utils.js +34 -0
- package/build/bdd-framework/run/StepInvoker.js +73 -0
- package/build/bdd-framework/run/bddFixtures.js +170 -0
- package/build/bdd-framework/run/bddWorld.js +76 -0
- package/build/bdd-framework/snippets/index.js +136 -0
- package/build/bdd-framework/snippets/snippetSyntax.js +43 -0
- package/build/bdd-framework/snippets/snippetSyntaxDecorators.js +26 -0
- package/build/bdd-framework/snippets/snippetSyntaxTs.js +18 -0
- package/build/bdd-framework/stepDefinitions/createBdd.js +66 -0
- package/build/bdd-framework/stepDefinitions/decorators/class.js +68 -0
- package/build/bdd-framework/stepDefinitions/decorators/steps.js +99 -0
- package/build/bdd-framework/stepDefinitions/defineStep.js +62 -0
- package/build/bdd-framework/stepDefinitions/stepConfig.js +24 -0
- package/build/bdd-framework/utils/exit.js +58 -0
- package/build/bdd-framework/utils/index.js +70 -0
- package/build/bdd-framework/utils/jsStringWrap.js +44 -0
- package/build/bdd-framework/utils/logger.js +30 -0
- package/build/bdd-poc/core-runner/main.js +10 -0
- package/build/bdd-poc/core-runner/stepDefinitions.js +0 -1
- package/build/bdd-poc/index.js +26 -0
- package/build/bdd-poc/test/stepGenerate/stepFileGenerate.js +6 -6
- package/build/bdd-poc/test/stepGenerate/stepsnippets.js +1 -2
- package/build/bdd-poc/test/testDataMap.js +5 -5
- package/build/core/jest/preprocessor/jsPreprocessor.js +2 -3
- package/build/core/playwright/builtInFixtures/addTags.js +19 -0
- package/build/core/playwright/builtInFixtures/cacheLayer.js +13 -0
- package/build/core/playwright/builtInFixtures/context.js +15 -0
- package/build/core/playwright/builtInFixtures/index.js +26 -0
- package/build/core/playwright/builtInFixtures/page.js +51 -0
- package/build/core/playwright/clear-caches.js +29 -0
- package/build/core/playwright/custom-commands.js +1 -2
- package/build/core/playwright/index.js +10 -79
- package/build/core/playwright/readConfigFile.js +12 -6
- package/build/core/playwright/report-generator.js +2 -1
- package/build/core/playwright/setup/config-creator.js +23 -17
- package/build/core/playwright/setup/config-utils.js +32 -1
- package/build/core/playwright/setup/custom-reporter.js +109 -0
- package/build/core/playwright/tag-processor.js +68 -0
- package/build/core/playwright/test-runner.js +10 -10
- package/build/index.d.ts +59 -4
- package/build/index.js +10 -9
- package/build/lib/cli.js +10 -1
- package/build/parser/parser.js +0 -1
- package/build/setup-folder-structure/helper.js +34 -0
- package/build/setup-folder-structure/reportEnhancement/addonScript.html +25 -0
- package/build/setup-folder-structure/reportEnhancement/reportAlteration.js +25 -0
- package/build/setup-folder-structure/samples/git-ignore.sample.js +8 -4
- package/build/setup-folder-structure/samples/uat-config-sample.js +3 -2
- package/build/setup-folder-structure/setupProject.js +10 -5
- package/build/utils/fileUtils.js +15 -4
- package/build/utils/logger.js +1 -2
- package/build/utils/stepDefinitionsFormatter.js +1 -2
- package/changelog.md +57 -0
- package/npm-shrinkwrap.json +1426 -2172
- package/package.json +5 -4
- package/build/bdd-poc/main.js +0 -10
- /package/build/bdd-poc/{runner.js → core-runner/runner.js} +0 -0
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.TestFile = void 0;
|
|
8
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
9
|
+
var _path = _interopRequireDefault(require("path"));
|
|
10
|
+
var _formatter = require("./formatter");
|
|
11
|
+
var _i18n = require("./i18n");
|
|
12
|
+
var _loadSteps = require("../cucumber/loadSteps");
|
|
13
|
+
var _index = require("@cucumber/cucumber/lib/formatter/helpers/index");
|
|
14
|
+
var _utils = require("../utils");
|
|
15
|
+
var _testPoms = require("./testPoms");
|
|
16
|
+
var _testNode = require("./testNode");
|
|
17
|
+
var _stepConfig = require("../stepDefinitions/stepConfig");
|
|
18
|
+
var _exit = require("../utils/exit");
|
|
19
|
+
var _fixtures = require("./fixtures");
|
|
20
|
+
var _scenario = require("../hooks/scenario");
|
|
21
|
+
var _worker = require("../hooks/worker");
|
|
22
|
+
var _lang = require("../config/lang");
|
|
23
|
+
/**
|
|
24
|
+
* Generate test code.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
class TestFile {
|
|
28
|
+
options;
|
|
29
|
+
lines = [];
|
|
30
|
+
i18nKeywordsMap;
|
|
31
|
+
formatter;
|
|
32
|
+
hasCucumberStyle = false;
|
|
33
|
+
testNodes = [];
|
|
34
|
+
hasCustomTest = false;
|
|
35
|
+
undefinedSteps = [];
|
|
36
|
+
constructor(options) {
|
|
37
|
+
this.options = options;
|
|
38
|
+
this.formatter = new _formatter.Formatter(options.config);
|
|
39
|
+
}
|
|
40
|
+
get sourceFile() {
|
|
41
|
+
const {
|
|
42
|
+
uri
|
|
43
|
+
} = this.options.doc;
|
|
44
|
+
if (!uri) {
|
|
45
|
+
throw new Error(`Document without uri`);
|
|
46
|
+
}
|
|
47
|
+
return uri;
|
|
48
|
+
}
|
|
49
|
+
get content() {
|
|
50
|
+
return this.lines.join('\n');
|
|
51
|
+
}
|
|
52
|
+
get language() {
|
|
53
|
+
var _this$options$doc$fea;
|
|
54
|
+
return ((_this$options$doc$fea = this.options.doc.feature) === null || _this$options$doc$fea === void 0 ? void 0 : _this$options$doc$fea.language) || _lang.LANG_EN;
|
|
55
|
+
}
|
|
56
|
+
get isEnglish() {
|
|
57
|
+
return (0, _lang.isEnglish)(this.language);
|
|
58
|
+
}
|
|
59
|
+
get config() {
|
|
60
|
+
return this.options.config;
|
|
61
|
+
}
|
|
62
|
+
get outputPath() {
|
|
63
|
+
return this.options.outputPath;
|
|
64
|
+
}
|
|
65
|
+
build() {
|
|
66
|
+
this.loadI18nKeywords();
|
|
67
|
+
this.lines = [...this.getFileHeader(),
|
|
68
|
+
// prettier-ignore
|
|
69
|
+
...this.getRootSuite(), ...this.getFileFixtures()];
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
save() {
|
|
73
|
+
const dir = _path.default.dirname(this.outputPath);
|
|
74
|
+
if (!_fs.default.existsSync(dir)) {
|
|
75
|
+
_fs.default.mkdirSync(dir, {
|
|
76
|
+
recursive: true
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
_fs.default.writeFileSync(this.outputPath, this.content);
|
|
80
|
+
}
|
|
81
|
+
getFileHeader() {
|
|
82
|
+
const importTestFrom = this.getRelativeImportTestFrom();
|
|
83
|
+
return this.formatter.fileHeader(this.sourceFile, importTestFrom);
|
|
84
|
+
}
|
|
85
|
+
loadI18nKeywords() {
|
|
86
|
+
if (!this.isEnglish) {
|
|
87
|
+
this.i18nKeywordsMap = (0, _i18n.getKeywordsMap)(this.language);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
getRelativeImportTestFrom() {
|
|
91
|
+
const {
|
|
92
|
+
importTestFrom
|
|
93
|
+
} = this.config;
|
|
94
|
+
if (!importTestFrom) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const {
|
|
98
|
+
file,
|
|
99
|
+
varName
|
|
100
|
+
} = importTestFrom;
|
|
101
|
+
const dir = _path.default.dirname(this.outputPath);
|
|
102
|
+
return {
|
|
103
|
+
file: _path.default.relative(dir, file),
|
|
104
|
+
varName
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
getFileFixtures() {
|
|
108
|
+
return this.formatter.useFixtures([...this.formatter.testFixture(), ...(!this.isEnglish ? this.formatter.langFixture(this.language) : []), ...((0, _scenario.hasScenarioHooks)() || this.hasCucumberStyle ? this.formatter.bddWorldFixtures() : []), ...this.formatter.scenarioHookFixtures((0, _scenario.getScenarioHooksFixtures)()), ...this.formatter.workerHookFixtures((0, _worker.getWorkerHooksFixtures)()), ...this.formatter.tagsFixture(this.testNodes)]);
|
|
109
|
+
}
|
|
110
|
+
getRootSuite() {
|
|
111
|
+
const {
|
|
112
|
+
feature
|
|
113
|
+
} = this.options.doc;
|
|
114
|
+
if (!feature) {
|
|
115
|
+
throw new Error(`Document without feature.`);
|
|
116
|
+
}
|
|
117
|
+
return this.getSuite(feature);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Generate test.describe suite for root Feature or Rule
|
|
121
|
+
*/
|
|
122
|
+
getSuite(feature, parent) {
|
|
123
|
+
const node = new _testNode.TestNode(feature, parent);
|
|
124
|
+
if (node.isSkipped()) {
|
|
125
|
+
return this.formatter.suite(node, []);
|
|
126
|
+
}
|
|
127
|
+
const lines = [];
|
|
128
|
+
feature.children.forEach(child => lines.push(...this.getSuiteChild(child, node)));
|
|
129
|
+
return this.formatter.suite(node, lines);
|
|
130
|
+
}
|
|
131
|
+
getSuiteChild(child, parent) {
|
|
132
|
+
if ('rule' in child && child.rule) {
|
|
133
|
+
return this.getSuite(child.rule, parent);
|
|
134
|
+
}
|
|
135
|
+
if (child.background) {
|
|
136
|
+
return this.getBeforeEach(child.background, parent);
|
|
137
|
+
}
|
|
138
|
+
if (child.scenario) {
|
|
139
|
+
return this.getScenarioLines(child.scenario, parent);
|
|
140
|
+
}
|
|
141
|
+
throw new Error(`Empty child: ${JSON.stringify(child)}`);
|
|
142
|
+
}
|
|
143
|
+
getScenarioLines(scenario, parent) {
|
|
144
|
+
return this.isOutline(scenario) ? this.getOutlineSuite(scenario, parent) : this.getTest(scenario, parent);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Generate test.beforeEach for Background
|
|
148
|
+
*/
|
|
149
|
+
getBeforeEach(bg, parent) {
|
|
150
|
+
const node = new _testNode.TestNode({
|
|
151
|
+
name: 'background',
|
|
152
|
+
tags: []
|
|
153
|
+
}, parent);
|
|
154
|
+
const {
|
|
155
|
+
fixtures,
|
|
156
|
+
lines
|
|
157
|
+
} = this.getSteps(bg, node.tags);
|
|
158
|
+
return this.formatter.beforeEach(fixtures, lines);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Generate test.describe suite for Scenario Outline
|
|
162
|
+
*/
|
|
163
|
+
getOutlineSuite(scenario, parent) {
|
|
164
|
+
const node = new _testNode.TestNode(scenario, parent);
|
|
165
|
+
if (node.isSkipped()) {
|
|
166
|
+
return this.formatter.suite(node, []);
|
|
167
|
+
}
|
|
168
|
+
const lines = [];
|
|
169
|
+
let exampleIndex = 0;
|
|
170
|
+
scenario.examples.forEach(examples => {
|
|
171
|
+
const titleFormat = this.getExamplesTitleFormat(scenario, examples);
|
|
172
|
+
examples.tableBody.forEach(exampleRow => {
|
|
173
|
+
const testTitle = this.getOutlineTestTitle(titleFormat, examples, exampleRow, ++exampleIndex);
|
|
174
|
+
const testLines = this.getOutlineTest(scenario, examples, exampleRow, testTitle, node);
|
|
175
|
+
lines.push(...testLines);
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
return this.formatter.suite(node, lines);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Generate test from Examples row of Scenario Outline
|
|
182
|
+
*/
|
|
183
|
+
// eslint-disable-next-line max-params
|
|
184
|
+
getOutlineTest(scenario, examples, exampleRow, title, parent) {
|
|
185
|
+
const node = new _testNode.TestNode({
|
|
186
|
+
name: title,
|
|
187
|
+
tags: examples.tags
|
|
188
|
+
}, parent);
|
|
189
|
+
if (this.skipByTagsExpression(node)) {
|
|
190
|
+
return [];
|
|
191
|
+
}
|
|
192
|
+
if (node.isSkipped()) {
|
|
193
|
+
return this.formatter.test(node, new Set(), []);
|
|
194
|
+
}
|
|
195
|
+
this.testNodes.push(node);
|
|
196
|
+
const {
|
|
197
|
+
fixtures,
|
|
198
|
+
lines
|
|
199
|
+
} = this.getSteps(scenario, node.tags, exampleRow.id);
|
|
200
|
+
return this.formatter.test(node, fixtures, lines);
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Generate test from Scenario
|
|
204
|
+
*/
|
|
205
|
+
getTest(scenario, parent) {
|
|
206
|
+
const node = new _testNode.TestNode(scenario, parent);
|
|
207
|
+
if (this.skipByTagsExpression(node)) {
|
|
208
|
+
return [];
|
|
209
|
+
}
|
|
210
|
+
if (node.isSkipped()) {
|
|
211
|
+
return this.formatter.test(node, new Set(), []);
|
|
212
|
+
}
|
|
213
|
+
this.testNodes.push(node);
|
|
214
|
+
const {
|
|
215
|
+
fixtures,
|
|
216
|
+
lines
|
|
217
|
+
} = this.getSteps(scenario, node.tags);
|
|
218
|
+
return this.formatter.test(node, fixtures, lines);
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Generate test steps
|
|
222
|
+
*/
|
|
223
|
+
getSteps(scenario, tags, outlineExampleRowId) {
|
|
224
|
+
const testFixtureNames = new Set();
|
|
225
|
+
const testPoms = new _testPoms.TestPoms(scenario.name || 'Background');
|
|
226
|
+
const decoratorSteps = [];
|
|
227
|
+
let previousKeywordType = undefined;
|
|
228
|
+
const lines = scenario.steps.map((step, index) => {
|
|
229
|
+
const {
|
|
230
|
+
keyword,
|
|
231
|
+
keywordType,
|
|
232
|
+
fixtureNames: stepFixtureNames,
|
|
233
|
+
line,
|
|
234
|
+
pickleStep,
|
|
235
|
+
stepConfig
|
|
236
|
+
} = this.getStep(step, previousKeywordType, outlineExampleRowId);
|
|
237
|
+
previousKeywordType = keywordType;
|
|
238
|
+
testFixtureNames.add(keyword);
|
|
239
|
+
stepFixtureNames.forEach(fixtureName => testFixtureNames.add(fixtureName));
|
|
240
|
+
if ((0, _stepConfig.isDecorator)(stepConfig)) {
|
|
241
|
+
testPoms.addByStep(stepConfig.pomNode);
|
|
242
|
+
decoratorSteps.push({
|
|
243
|
+
index,
|
|
244
|
+
keyword,
|
|
245
|
+
pickleStep,
|
|
246
|
+
pomNode: stepConfig.pomNode
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
return line;
|
|
250
|
+
});
|
|
251
|
+
// decorator steps handled in second pass to guess fixtures
|
|
252
|
+
if (decoratorSteps.length) {
|
|
253
|
+
testFixtureNames.forEach(fixtureName => testPoms.addByFixtureName(fixtureName));
|
|
254
|
+
tags === null || tags === void 0 || tags.forEach(tag => testPoms.addByTag(tag));
|
|
255
|
+
testPoms.resolveFixtures();
|
|
256
|
+
decoratorSteps.forEach(step => {
|
|
257
|
+
const {
|
|
258
|
+
line,
|
|
259
|
+
fixtureName
|
|
260
|
+
} = this.getDecoratorStep(step, testPoms);
|
|
261
|
+
lines[step.index] = line;
|
|
262
|
+
testFixtureNames.add(fixtureName);
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
return {
|
|
266
|
+
fixtures: testFixtureNames,
|
|
267
|
+
lines
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Generate step for Given, When, Then
|
|
272
|
+
*/
|
|
273
|
+
// eslint-disable-next-line max-statements, complexity
|
|
274
|
+
getStep(step, previousKeywordType, outlineExampleRowId) {
|
|
275
|
+
const pickleStep = this.getPickleStep(step, outlineExampleRowId);
|
|
276
|
+
const stepDefinition = (0, _loadSteps.findStepDefinition)(this.options.supportCodeLibrary, pickleStep.text, this.sourceFile);
|
|
277
|
+
const keywordType = (0, _index.getStepKeywordType)({
|
|
278
|
+
keyword: step.keyword,
|
|
279
|
+
language: this.language,
|
|
280
|
+
previousKeywordType
|
|
281
|
+
});
|
|
282
|
+
const enKeyword = this.getStepEnglishKeyword(step);
|
|
283
|
+
if (!stepDefinition) {
|
|
284
|
+
this.undefinedSteps.push({
|
|
285
|
+
keywordType,
|
|
286
|
+
step,
|
|
287
|
+
pickleStep
|
|
288
|
+
});
|
|
289
|
+
return this.getMissingStep(enKeyword, keywordType, pickleStep);
|
|
290
|
+
}
|
|
291
|
+
// for cucumber-style stepConfig is undefined
|
|
292
|
+
const stepConfig = (0, _stepConfig.getStepConfig)(stepDefinition);
|
|
293
|
+
if (stepConfig !== null && stepConfig !== void 0 && stepConfig.hasCustomTest) {
|
|
294
|
+
this.hasCustomTest = true;
|
|
295
|
+
}
|
|
296
|
+
if (!(0, _stepConfig.isPlaywrightStyle)(stepConfig)) {
|
|
297
|
+
this.hasCucumberStyle = true;
|
|
298
|
+
}
|
|
299
|
+
const fixtureNames = this.getStepFixtureNames(stepDefinition);
|
|
300
|
+
const line = (0, _stepConfig.isDecorator)(stepConfig) ? '' : this.formatter.step(enKeyword, pickleStep.text, pickleStep.argument, fixtureNames);
|
|
301
|
+
return {
|
|
302
|
+
keyword: enKeyword,
|
|
303
|
+
keywordType,
|
|
304
|
+
fixtureNames,
|
|
305
|
+
line,
|
|
306
|
+
pickleStep,
|
|
307
|
+
stepConfig
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
getMissingStep(keyword, keywordType, pickleStep) {
|
|
311
|
+
return {
|
|
312
|
+
keyword,
|
|
313
|
+
keywordType,
|
|
314
|
+
fixtureNames: [],
|
|
315
|
+
line: this.formatter.missingStep(keyword, pickleStep.text),
|
|
316
|
+
pickleStep,
|
|
317
|
+
stepConfig: undefined
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
getPickleStep(step, outlineExampleRowId) {
|
|
321
|
+
for (const pickle of this.options.pickles) {
|
|
322
|
+
const pickleStep = pickle.steps.find(({
|
|
323
|
+
astNodeIds
|
|
324
|
+
}) => {
|
|
325
|
+
const hasStepId = astNodeIds.includes(step.id);
|
|
326
|
+
const hasRowId = !outlineExampleRowId || astNodeIds.includes(outlineExampleRowId);
|
|
327
|
+
return hasStepId && hasRowId;
|
|
328
|
+
});
|
|
329
|
+
if (pickleStep) {
|
|
330
|
+
return pickleStep;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
throw new Error(`Pickle step not found for step: ${step.text}`);
|
|
334
|
+
}
|
|
335
|
+
getStepEnglishKeyword(step) {
|
|
336
|
+
const nativeKeyword = step.keyword.trim();
|
|
337
|
+
const enKeyword = nativeKeyword === '*' ? 'And' : this.getEnglishKeyword(nativeKeyword);
|
|
338
|
+
if (!enKeyword) {
|
|
339
|
+
throw new Error(`Keyword not found: ${nativeKeyword}`);
|
|
340
|
+
}
|
|
341
|
+
return enKeyword;
|
|
342
|
+
}
|
|
343
|
+
getStepFixtureNames(stepDefinition) {
|
|
344
|
+
const stepConfig = (0, _stepConfig.getStepConfig)(stepDefinition);
|
|
345
|
+
if ((0, _stepConfig.isPlaywrightStyle)(stepConfig)) {
|
|
346
|
+
// for decorator steps fixtureNames are defined later in second pass
|
|
347
|
+
return (0, _stepConfig.isDecorator)(stepConfig) ? [] : (0, _fixtures.extractFixtureNames)(stepConfig.fn);
|
|
348
|
+
} else {
|
|
349
|
+
return (0, _fixtures.extractFixtureNamesFromFnBodyMemo)(stepDefinition.code);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
getDecoratorStep(step, testPoms) {
|
|
353
|
+
const {
|
|
354
|
+
keyword,
|
|
355
|
+
pickleStep,
|
|
356
|
+
pomNode
|
|
357
|
+
} = step;
|
|
358
|
+
const resolvedFixtures = testPoms.getResolvedFixtures(pomNode);
|
|
359
|
+
if (resolvedFixtures.length !== 1) {
|
|
360
|
+
const suggestedTags = resolvedFixtures.filter(f => !f.byTag).map(f => (0, _testPoms.buildFixtureTag)(f.name)).join(', ');
|
|
361
|
+
const suggestedTagsStr = suggestedTags.length ? ` or set one of the following tags: ${suggestedTags}` : '.';
|
|
362
|
+
(0, _exit.exit)(`Can't guess fixture for decorator step "${pickleStep.text}" in file: ${this.sourceFile}.`, `Please refactor your Page Object classes${suggestedTagsStr}`);
|
|
363
|
+
}
|
|
364
|
+
const fixtureName = resolvedFixtures[0].name;
|
|
365
|
+
return {
|
|
366
|
+
fixtureName,
|
|
367
|
+
line: this.formatter.step(keyword, pickleStep.text, pickleStep.argument, [fixtureName])
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
getOutlineTestTitle(titleFormat, examples, exampleRow, exampleIndex) {
|
|
371
|
+
const params = {
|
|
372
|
+
_index_: exampleIndex
|
|
373
|
+
};
|
|
374
|
+
exampleRow.cells.forEach((cell, index) => {
|
|
375
|
+
var _examples$tableHeader;
|
|
376
|
+
const colName = (_examples$tableHeader = examples.tableHeader) === null || _examples$tableHeader === void 0 || (_examples$tableHeader = _examples$tableHeader.cells[index]) === null || _examples$tableHeader === void 0 ? void 0 : _examples$tableHeader.value;
|
|
377
|
+
if (colName) {
|
|
378
|
+
params[colName] = cell.value;
|
|
379
|
+
}
|
|
380
|
+
});
|
|
381
|
+
return (0, _utils.template)(titleFormat, params);
|
|
382
|
+
}
|
|
383
|
+
getExamplesTitleFormat(scenario, examples) {
|
|
384
|
+
return this.getExamplesTitleFormatFromComment(examples) || this.getExamplesTitleFormatFromScenarioName(scenario, examples) || this.config.examplesTitleFormat;
|
|
385
|
+
}
|
|
386
|
+
getExamplesTitleFormatFromComment(examples) {
|
|
387
|
+
var _comment$text;
|
|
388
|
+
const {
|
|
389
|
+
line
|
|
390
|
+
} = examples.location;
|
|
391
|
+
const titleFormatCommentLine = line - 1;
|
|
392
|
+
const comment = this.options.doc.comments.find(c => {
|
|
393
|
+
return c.location.line === titleFormatCommentLine;
|
|
394
|
+
});
|
|
395
|
+
const commentText = comment === null || comment === void 0 || (_comment$text = comment.text) === null || _comment$text === void 0 ? void 0 : _comment$text.trim();
|
|
396
|
+
const prefix = '# title-format:';
|
|
397
|
+
return commentText !== null && commentText !== void 0 && commentText.startsWith(prefix) ? commentText.replace(prefix, '').trim() : '';
|
|
398
|
+
}
|
|
399
|
+
getExamplesTitleFormatFromScenarioName(scenario, examples) {
|
|
400
|
+
var _examples$tableHeader2;
|
|
401
|
+
const columnsInScenarioName = (0, _utils.extractTemplateParams)(scenario.name);
|
|
402
|
+
const hasColumnsFromExamples = columnsInScenarioName.length && ((_examples$tableHeader2 = examples.tableHeader) === null || _examples$tableHeader2 === void 0 || (_examples$tableHeader2 = _examples$tableHeader2.cells) === null || _examples$tableHeader2 === void 0 ? void 0 : _examples$tableHeader2.some(cell => {
|
|
403
|
+
return cell.value && columnsInScenarioName.includes(cell.value);
|
|
404
|
+
}));
|
|
405
|
+
return hasColumnsFromExamples ? scenario.name : '';
|
|
406
|
+
}
|
|
407
|
+
skipByTagsExpression(node) {
|
|
408
|
+
// see: https://github.com/cucumber/tag-expressions/tree/main/javascript
|
|
409
|
+
const {
|
|
410
|
+
tagsExpression
|
|
411
|
+
} = this.options;
|
|
412
|
+
return tagsExpression && !tagsExpression.evaluate(node.tags);
|
|
413
|
+
}
|
|
414
|
+
isOutline(scenario) {
|
|
415
|
+
const keyword = this.getEnglishKeyword(scenario.keyword);
|
|
416
|
+
return keyword === 'ScenarioOutline' || keyword === 'Scenario Outline' || keyword === 'Scenario Template';
|
|
417
|
+
}
|
|
418
|
+
getEnglishKeyword(keyword) {
|
|
419
|
+
return this.i18nKeywordsMap ? this.i18nKeywordsMap.get(keyword) : keyword;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
exports.TestFile = TestFile;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.TestNode = void 0;
|
|
7
|
+
var _utils = require("../utils");
|
|
8
|
+
/**
|
|
9
|
+
* Universal TestNode class of parent-child relations in test file structure.
|
|
10
|
+
* Holds tags and titles path.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const SPECIAL_TAGS = ['@only', '@skip', '@fixme'];
|
|
14
|
+
class TestNode {
|
|
15
|
+
title;
|
|
16
|
+
titlePath;
|
|
17
|
+
ownTags = [];
|
|
18
|
+
tags = [];
|
|
19
|
+
flags = {};
|
|
20
|
+
constructor(gherkinNode, parent) {
|
|
21
|
+
this.initOwnTags(gherkinNode);
|
|
22
|
+
this.tags = (0, _utils.removeDuplicates)(((parent === null || parent === void 0 ? void 0 : parent.tags) || []).concat(this.ownTags));
|
|
23
|
+
this.title = gherkinNode.name;
|
|
24
|
+
this.titlePath = ((parent === null || parent === void 0 ? void 0 : parent.titlePath) || []).concat([this.title]);
|
|
25
|
+
}
|
|
26
|
+
isSkipped() {
|
|
27
|
+
return this.flags.skip || this.flags.fixme;
|
|
28
|
+
}
|
|
29
|
+
initOwnTags(gherkinNode) {
|
|
30
|
+
const tagNames = (0, _utils.removeDuplicates)(getTagNames(gherkinNode.tags));
|
|
31
|
+
tagNames.forEach(tag => {
|
|
32
|
+
if (isSpecialTag(tag)) {
|
|
33
|
+
this.setFlag(tag);
|
|
34
|
+
} else {
|
|
35
|
+
this.ownTags.push(tag);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
// eslint-disable-next-line complexity
|
|
40
|
+
setFlag(tag) {
|
|
41
|
+
// in case of several system tags, @only takes precendence
|
|
42
|
+
if (tag === '@only') {
|
|
43
|
+
this.flags = {
|
|
44
|
+
only: true
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
if (tag === '@skip' && !this.flags.only) {
|
|
48
|
+
this.flags.skip = true;
|
|
49
|
+
}
|
|
50
|
+
if (tag === '@fixme' && !this.flags.only) {
|
|
51
|
+
this.flags.fixme = true;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.TestNode = TestNode;
|
|
56
|
+
function getTagNames(tags) {
|
|
57
|
+
return tags.map(tag => tag.name);
|
|
58
|
+
}
|
|
59
|
+
function isSpecialTag(tag) {
|
|
60
|
+
return SPECIAL_TAGS.includes(tag);
|
|
61
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.TestPoms = void 0;
|
|
7
|
+
exports.buildFixtureTag = buildFixtureTag;
|
|
8
|
+
var _class = require("../stepDefinitions/decorators/class");
|
|
9
|
+
var _exit = require("../utils/exit");
|
|
10
|
+
/**
|
|
11
|
+
* Track PomNodes used in the particular test.
|
|
12
|
+
* To select correct fixture for decorator steps.
|
|
13
|
+
*
|
|
14
|
+
* Idea: try to use the deepest child fixture for parent steps.
|
|
15
|
+
*
|
|
16
|
+
* Example inheritance tree:
|
|
17
|
+
* A
|
|
18
|
+
* / \
|
|
19
|
+
* B C
|
|
20
|
+
* / \ \
|
|
21
|
+
* D E F
|
|
22
|
+
*
|
|
23
|
+
* If test uses steps from classes A and D:
|
|
24
|
+
* -> resolved fixture will be D, even for steps from A.
|
|
25
|
+
*
|
|
26
|
+
* If test uses steps from classes A, D and C:
|
|
27
|
+
* -> error, b/c A has 2 possible fixtures.
|
|
28
|
+
*
|
|
29
|
+
* If test uses steps from classes A and C, but @fixture tag is D:
|
|
30
|
+
* -> error, b/c A has 2 possible fixtures.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
const FIXTURE_TAG_PREFIX = '@fixture:';
|
|
34
|
+
class TestPoms {
|
|
35
|
+
title;
|
|
36
|
+
// map of poms used in test
|
|
37
|
+
usedPoms = new Map();
|
|
38
|
+
constructor(title) {
|
|
39
|
+
this.title = title;
|
|
40
|
+
}
|
|
41
|
+
addByStep(pomNode) {
|
|
42
|
+
this.addUsedPom(pomNode, {
|
|
43
|
+
byTag: false
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
addByFixtureName(fixtureName) {
|
|
47
|
+
const pomNode = (0, _class.getPomNodeByFixtureName)(fixtureName);
|
|
48
|
+
this.addUsedPom(pomNode, {
|
|
49
|
+
byTag: false
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
addByTag(tag) {
|
|
53
|
+
const fixtureName = extractFixtureName(tag);
|
|
54
|
+
if (fixtureName) {
|
|
55
|
+
const pomNode = (0, _class.getPomNodeByFixtureName)(fixtureName);
|
|
56
|
+
this.addUsedPom(pomNode, {
|
|
57
|
+
byTag: true
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Resolve all used pomNodes to fixtures.
|
|
63
|
+
* This is needed to handle @fixture: tagged pomNodes
|
|
64
|
+
* that does not have steps in the test, but should be considered.
|
|
65
|
+
*/
|
|
66
|
+
resolveFixtures() {
|
|
67
|
+
this.usedPoms.forEach((_, pomNode) => {
|
|
68
|
+
this.getResolvedFixtures(pomNode);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Returns fixtures suitable for particular pomNode (actually for step)
|
|
73
|
+
*/
|
|
74
|
+
getResolvedFixtures(pomNode) {
|
|
75
|
+
const usedPom = this.usedPoms.get(pomNode);
|
|
76
|
+
if (usedPom !== null && usedPom !== void 0 && usedPom.fixtures) {
|
|
77
|
+
return usedPom.fixtures;
|
|
78
|
+
}
|
|
79
|
+
// Recursively resolve children fixtures, used in test.
|
|
80
|
+
let childFixtures = [...pomNode.children].map(child => this.getResolvedFixtures(child)).flat();
|
|
81
|
+
if (!usedPom) {
|
|
82
|
+
return childFixtures;
|
|
83
|
+
}
|
|
84
|
+
if (childFixtures.length) {
|
|
85
|
+
this.verifyChildFixtures(pomNode, usedPom, childFixtures);
|
|
86
|
+
usedPom.fixtures = childFixtures;
|
|
87
|
+
} else {
|
|
88
|
+
usedPom.fixtures = [{
|
|
89
|
+
name: pomNode.fixtureName,
|
|
90
|
+
byTag: usedPom.byTag
|
|
91
|
+
}];
|
|
92
|
+
}
|
|
93
|
+
return usedPom.fixtures;
|
|
94
|
+
}
|
|
95
|
+
addUsedPom(pomNode, {
|
|
96
|
+
byTag
|
|
97
|
+
}) {
|
|
98
|
+
if (!pomNode) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const usedPom = this.usedPoms.get(pomNode);
|
|
102
|
+
if (usedPom) {
|
|
103
|
+
if (byTag && !usedPom.byTag) {
|
|
104
|
+
usedPom.byTag = true;
|
|
105
|
+
}
|
|
106
|
+
} else {
|
|
107
|
+
this.usedPoms.set(pomNode, {
|
|
108
|
+
byTag
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* For scenarios with @fixture:xxx tags verify that there are no steps from fixtures,
|
|
114
|
+
* deeper than xxx.
|
|
115
|
+
* @fixture:xxx tag provides maximum fixture that can be used in the scenario.
|
|
116
|
+
*/
|
|
117
|
+
verifyChildFixtures(pomNode, usedPom, childFixtures) {
|
|
118
|
+
if (!usedPom.byTag) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const childFixturesBySteps = childFixtures.filter(f => !f.byTag);
|
|
122
|
+
if (childFixturesBySteps.length) {
|
|
123
|
+
(0, _exit.exit)(`Scenario "${this.title}" contains ${childFixturesBySteps.length} step(s)`, `not compatible with required fixture "${pomNode.fixtureName}"`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
exports.TestPoms = TestPoms;
|
|
128
|
+
function extractFixtureName(tag) {
|
|
129
|
+
return tag.startsWith(FIXTURE_TAG_PREFIX) ? tag.replace(FIXTURE_TAG_PREFIX, '') : '';
|
|
130
|
+
}
|
|
131
|
+
function buildFixtureTag(fixtureName) {
|
|
132
|
+
return `${FIXTURE_TAG_PREFIX}${fixtureName}`;
|
|
133
|
+
}
|