@zohodesk/testinglibrary 2.9.2 → 3.0.2
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/.gitlab-ci.yml +1 -1
- package/README.md +27 -1
- package/build/core/playwright/fixtures.js +24 -0
- package/build/core/playwright/index.js +10 -23
- package/build/core/playwright/setup/config-creator.js +3 -3
- package/build/core/playwright/setup/config-utils.js +8 -25
- package/build/core/playwright/test-runner.js +1 -1
- package/build/decorators.d.ts +1 -1
- package/build/decorators.js +1 -1
- package/build/setup-folder-structure/samples/actors-index.js +2 -0
- package/build/setup-folder-structure/samples/auth-setup-sample.js +14 -66
- package/build/setup-folder-structure/samples/editions-index.js +3 -0
- package/build/setup-folder-structure/samples/free-sample.json +25 -0
- package/build/setup-folder-structure/samples/settings.json +7 -0
- package/build/setup-folder-structure/setupProject.js +18 -5
- package/nobdd/uat/conf/nobdd/uat.config.js +1 -2
- package/nobdd/uat.config.js +1 -2
- package/package.json +7 -7
- package/build/bdd-framework/cli/commands/env.js +0 -42
- package/build/bdd-framework/cli/commands/export.js +0 -62
- package/build/bdd-framework/cli/commands/test.js +0 -64
- package/build/bdd-framework/cli/index.js +0 -11
- package/build/bdd-framework/cli/options.js +0 -19
- package/build/bdd-framework/cli/worker.js +0 -13
- package/build/bdd-framework/config/configDir.js +0 -35
- package/build/bdd-framework/config/enrichReporterData.js +0 -23
- package/build/bdd-framework/config/env.js +0 -50
- package/build/bdd-framework/config/index.js +0 -94
- package/build/bdd-framework/config/lang.js +0 -14
- package/build/bdd-framework/cucumber/buildStepDefinition.js +0 -43
- package/build/bdd-framework/cucumber/createTestStep.js +0 -43
- package/build/bdd-framework/cucumber/formatter/EventDataCollector.js +0 -126
- package/build/bdd-framework/cucumber/formatter/GherkinDocumentParser.js +0 -72
- package/build/bdd-framework/cucumber/formatter/PickleParser.js +0 -25
- package/build/bdd-framework/cucumber/formatter/durationHelpers.js +0 -13
- package/build/bdd-framework/cucumber/formatter/getColorFns.js +0 -57
- package/build/bdd-framework/cucumber/formatter/index.js +0 -16
- package/build/bdd-framework/cucumber/formatter/locationHelpers.js +0 -16
- package/build/bdd-framework/cucumber/loadConfig.js +0 -17
- package/build/bdd-framework/cucumber/loadFeatures.js +0 -70
- package/build/bdd-framework/cucumber/loadSnippetBuilder.js +0 -20
- package/build/bdd-framework/cucumber/loadSteps.js +0 -47
- package/build/bdd-framework/cucumber/resolveFeaturePaths.js +0 -62
- package/build/bdd-framework/cucumber/stepArguments.js +0 -21
- package/build/bdd-framework/cucumber/types.js +0 -5
- package/build/bdd-framework/cucumber/valueChecker.js +0 -23
- package/build/bdd-framework/decorators.js +0 -18
- package/build/bdd-framework/gen/fixtures.js +0 -48
- package/build/bdd-framework/gen/formatter.js +0 -167
- package/build/bdd-framework/gen/i18n.js +0 -39
- package/build/bdd-framework/gen/index.js +0 -197
- package/build/bdd-framework/gen/specialTags.js +0 -70
- package/build/bdd-framework/gen/testFile.js +0 -470
- package/build/bdd-framework/gen/testMeta.js +0 -60
- package/build/bdd-framework/gen/testNode.js +0 -35
- package/build/bdd-framework/gen/testPoms.js +0 -133
- package/build/bdd-framework/hooks/scenario.js +0 -130
- package/build/bdd-framework/hooks/worker.js +0 -89
- package/build/bdd-framework/index.js +0 -52
- package/build/bdd-framework/playwright/fixtureParameterNames.js +0 -93
- package/build/bdd-framework/playwright/getLocationInFile.js +0 -79
- package/build/bdd-framework/playwright/loadConfig.js +0 -42
- package/build/bdd-framework/playwright/loadUtils.js +0 -33
- package/build/bdd-framework/playwright/testTypeImpl.js +0 -79
- package/build/bdd-framework/playwright/transform.js +0 -88
- package/build/bdd-framework/playwright/types.js +0 -12
- package/build/bdd-framework/playwright/utils.js +0 -56
- package/build/bdd-framework/reporter/cucumber/base.js +0 -52
- package/build/bdd-framework/reporter/cucumber/custom.js +0 -73
- package/build/bdd-framework/reporter/cucumber/helper.js +0 -12
- package/build/bdd-framework/reporter/cucumber/html.js +0 -40
- package/build/bdd-framework/reporter/cucumber/index.js +0 -74
- package/build/bdd-framework/reporter/cucumber/json.js +0 -312
- package/build/bdd-framework/reporter/cucumber/junit.js +0 -205
- package/build/bdd-framework/reporter/cucumber/message.js +0 -20
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/AttachmentMapper.js +0 -82
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/Builder.js +0 -197
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/GherkinDocument.js +0 -43
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/GherkinDocumentClone.js +0 -52
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/GherkinDocuments.js +0 -105
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/Hook.js +0 -70
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/Meta.js +0 -45
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/Pickles.js +0 -27
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/Projects.js +0 -38
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestCase.js +0 -128
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestCaseRun.js +0 -154
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestCaseRunHooks.js +0 -123
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestStepAttachments.js +0 -67
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestStepRun.js +0 -114
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/index.js +0 -30
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/pwStepUtils.js +0 -70
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/timing.js +0 -35
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/types.js +0 -5
- package/build/bdd-framework/run/StepInvoker.js +0 -69
- package/build/bdd-framework/run/bddData/index.js +0 -59
- package/build/bdd-framework/run/bddData/types.js +0 -5
- package/build/bdd-framework/run/bddFixtures.js +0 -192
- package/build/bdd-framework/run/bddWorld.js +0 -79
- package/build/bdd-framework/run/bddWorldInternal.js +0 -11
- package/build/bdd-framework/snippets/index.js +0 -132
- package/build/bdd-framework/snippets/snippetSyntax.js +0 -43
- package/build/bdd-framework/snippets/snippetSyntaxDecorators.js +0 -26
- package/build/bdd-framework/snippets/snippetSyntaxTs.js +0 -18
- package/build/bdd-framework/stepDefinitions/createBdd.js +0 -66
- package/build/bdd-framework/stepDefinitions/decorators/class.js +0 -68
- package/build/bdd-framework/stepDefinitions/decorators/steps.js +0 -99
- package/build/bdd-framework/stepDefinitions/defineStep.js +0 -62
- package/build/bdd-framework/stepDefinitions/stepConfig.js +0 -24
- package/build/bdd-framework/steps/createBdd.js +0 -78
- package/build/bdd-framework/steps/decorators/class.js +0 -68
- package/build/bdd-framework/steps/decorators/steps.js +0 -98
- package/build/bdd-framework/steps/defineStep.js +0 -62
- package/build/bdd-framework/steps/stepConfig.js +0 -24
- package/build/bdd-framework/utils/AutofillMap.js +0 -20
- package/build/bdd-framework/utils/exit.js +0 -62
- package/build/bdd-framework/utils/index.js +0 -93
- package/build/bdd-framework/utils/jsStringWrap.js +0 -44
- package/build/bdd-framework/utils/logger.js +0 -30
- package/build/bdd-framework/utils/stripAnsiEscapes.js +0 -20
- package/build/setup-folder-structure/samples/authUsers-sample.json +0 -9
- package/build/setup-folder-structure/samples/env-config-sample.json +0 -21
- package/npm-shrinkwrap.json +0 -6475
|
@@ -1,470 +0,0 @@
|
|
|
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("../steps/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
|
-
var _testMeta = require("./testMeta");
|
|
24
|
-
/**
|
|
25
|
-
* Generate Playwright test file for feature.
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
class TestFile {
|
|
29
|
-
options;
|
|
30
|
-
lines = [];
|
|
31
|
-
i18nKeywordsMap;
|
|
32
|
-
formatter;
|
|
33
|
-
testMetaBuilder;
|
|
34
|
-
hasCucumberStyle = false;
|
|
35
|
-
hasCustomTest = false;
|
|
36
|
-
undefinedSteps = [];
|
|
37
|
-
featureUri;
|
|
38
|
-
usedStepDefinitions = new Set();
|
|
39
|
-
constructor(options) {
|
|
40
|
-
this.options = options;
|
|
41
|
-
this.formatter = new _formatter.Formatter(options.config);
|
|
42
|
-
this.testMetaBuilder = new _testMeta.TestMetaBuilder();
|
|
43
|
-
this.featureUri = this.getFeatureUri();
|
|
44
|
-
}
|
|
45
|
-
get gherkinDocument() {
|
|
46
|
-
return this.options.gherkinDocument;
|
|
47
|
-
}
|
|
48
|
-
get pickles() {
|
|
49
|
-
return this.gherkinDocument.pickles;
|
|
50
|
-
}
|
|
51
|
-
get content() {
|
|
52
|
-
return this.lines.join('\n');
|
|
53
|
-
}
|
|
54
|
-
get language() {
|
|
55
|
-
var _this$gherkinDocument;
|
|
56
|
-
return ((_this$gherkinDocument = this.gherkinDocument.feature) === null || _this$gherkinDocument === void 0 ? void 0 : _this$gherkinDocument.language) || _lang.LANG_EN;
|
|
57
|
-
}
|
|
58
|
-
get isEnglish() {
|
|
59
|
-
return (0, _lang.isEnglish)(this.language);
|
|
60
|
-
}
|
|
61
|
-
get config() {
|
|
62
|
-
return this.options.config;
|
|
63
|
-
}
|
|
64
|
-
get outputPath() {
|
|
65
|
-
return this.options.outputPath;
|
|
66
|
-
}
|
|
67
|
-
get testCount() {
|
|
68
|
-
return this.testMetaBuilder.testCount;
|
|
69
|
-
}
|
|
70
|
-
build() {
|
|
71
|
-
if (!this.pickles.length) {
|
|
72
|
-
return this;
|
|
73
|
-
}
|
|
74
|
-
this.loadI18nKeywords();
|
|
75
|
-
this.lines = [...this.getFileHeader(),
|
|
76
|
-
// prettier-ignore
|
|
77
|
-
...this.getRootSuite(), ...this.getTechnicalSection()];
|
|
78
|
-
return this;
|
|
79
|
-
}
|
|
80
|
-
save() {
|
|
81
|
-
const dir = _path.default.dirname(this.outputPath);
|
|
82
|
-
if (!_fs.default.existsSync(dir)) {
|
|
83
|
-
_fs.default.mkdirSync(dir, {
|
|
84
|
-
recursive: true
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
_fs.default.writeFileSync(this.outputPath, this.content);
|
|
88
|
-
}
|
|
89
|
-
getFileHeader() {
|
|
90
|
-
const importTestFrom = this.getRelativeImportTestFrom();
|
|
91
|
-
return this.formatter.fileHeader(this.featureUri, importTestFrom);
|
|
92
|
-
}
|
|
93
|
-
loadI18nKeywords() {
|
|
94
|
-
if (!this.isEnglish) {
|
|
95
|
-
this.i18nKeywordsMap = (0, _i18n.getKeywordsMap)(this.language);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
getFeatureUri() {
|
|
99
|
-
const {
|
|
100
|
-
uri
|
|
101
|
-
} = this.gherkinDocument;
|
|
102
|
-
if (!uri) {
|
|
103
|
-
var _this$gherkinDocument2;
|
|
104
|
-
throw new Error(`Document without uri: ${(_this$gherkinDocument2 = this.gherkinDocument.feature) === null || _this$gherkinDocument2 === void 0 ? void 0 : _this$gherkinDocument2.name}`);
|
|
105
|
-
}
|
|
106
|
-
return uri;
|
|
107
|
-
}
|
|
108
|
-
getRelativeImportTestFrom() {
|
|
109
|
-
const {
|
|
110
|
-
importTestFrom
|
|
111
|
-
} = this.config;
|
|
112
|
-
if (!importTestFrom) {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
const {
|
|
116
|
-
file,
|
|
117
|
-
varName
|
|
118
|
-
} = importTestFrom;
|
|
119
|
-
const dir = _path.default.dirname(this.outputPath);
|
|
120
|
-
return {
|
|
121
|
-
file: _path.default.relative(dir, file),
|
|
122
|
-
varName
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
getTechnicalSection() {
|
|
126
|
-
return this.formatter.technicalSection(this.testMetaBuilder, this.featureUri, [...(!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)())]);
|
|
127
|
-
}
|
|
128
|
-
getRootSuite() {
|
|
129
|
-
const {
|
|
130
|
-
feature
|
|
131
|
-
} = this.gherkinDocument;
|
|
132
|
-
if (!feature) {
|
|
133
|
-
throw new Error(`Document without feature.`);
|
|
134
|
-
}
|
|
135
|
-
return this.getSuite(feature);
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Generate test.describe suite for root Feature or Rule
|
|
139
|
-
*/
|
|
140
|
-
getSuite(feature, parent) {
|
|
141
|
-
const node = new _testNode.TestNode(feature, parent);
|
|
142
|
-
if (node.isSkipped()) {
|
|
143
|
-
return this.formatter.describe(node, []);
|
|
144
|
-
}
|
|
145
|
-
const lines = [];
|
|
146
|
-
feature.children.forEach(child => lines.push(...this.getSuiteChild(child, node)));
|
|
147
|
-
return this.formatter.describe(node, lines);
|
|
148
|
-
}
|
|
149
|
-
getSuiteChild(child, parent) {
|
|
150
|
-
if ('rule' in child && child.rule) {
|
|
151
|
-
return this.getSuite(child.rule, parent);
|
|
152
|
-
}
|
|
153
|
-
if (child.background) {
|
|
154
|
-
return this.getBeforeEach(child.background, parent);
|
|
155
|
-
}
|
|
156
|
-
if (child.scenario) {
|
|
157
|
-
return this.getScenarioLines(child.scenario, parent);
|
|
158
|
-
}
|
|
159
|
-
throw new Error(`Empty child: ${JSON.stringify(child)}`);
|
|
160
|
-
}
|
|
161
|
-
getScenarioLines(scenario, parent) {
|
|
162
|
-
return this.isOutline(scenario) ? this.getOutlineSuite(scenario, parent) : this.getTest(scenario, parent);
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Generate test.beforeEach for Background
|
|
166
|
-
*/
|
|
167
|
-
getBeforeEach(bg, parent) {
|
|
168
|
-
const node = new _testNode.TestNode({
|
|
169
|
-
name: 'background',
|
|
170
|
-
tags: []
|
|
171
|
-
}, parent);
|
|
172
|
-
const {
|
|
173
|
-
fixtures,
|
|
174
|
-
lines
|
|
175
|
-
} = this.getSteps(bg, node.tags);
|
|
176
|
-
return this.formatter.beforeEach(fixtures, lines);
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Generate test.describe suite for Scenario Outline
|
|
180
|
-
*/
|
|
181
|
-
getOutlineSuite(scenario, parent) {
|
|
182
|
-
const node = new _testNode.TestNode(scenario, parent);
|
|
183
|
-
if (node.isSkipped()) {
|
|
184
|
-
return this.formatter.describe(node, []);
|
|
185
|
-
}
|
|
186
|
-
const lines = [];
|
|
187
|
-
let exampleIndex = 0;
|
|
188
|
-
scenario.examples.forEach(examples => {
|
|
189
|
-
const titleFormat = this.getExamplesTitleFormat(scenario, examples);
|
|
190
|
-
examples.tableBody.forEach(exampleRow => {
|
|
191
|
-
const testTitle = this.getOutlineTestTitle(titleFormat, examples, exampleRow, ++exampleIndex);
|
|
192
|
-
const testLines = this.getOutlineTest(scenario, examples, exampleRow, testTitle, node);
|
|
193
|
-
lines.push(...testLines);
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
return this.formatter.describe(node, lines);
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* Generate test from Examples row of Scenario Outline
|
|
200
|
-
*/
|
|
201
|
-
// eslint-disable-next-line max-params
|
|
202
|
-
getOutlineTest(scenario, examples, exampleRow, title, parent) {
|
|
203
|
-
const node = new _testNode.TestNode({
|
|
204
|
-
name: title,
|
|
205
|
-
tags: examples.tags
|
|
206
|
-
}, parent);
|
|
207
|
-
if (this.skipByTagsExpression(node)) {
|
|
208
|
-
return [];
|
|
209
|
-
}
|
|
210
|
-
const pickle = this.findPickle(scenario, exampleRow);
|
|
211
|
-
this.testMetaBuilder.registerTest(node, pickle);
|
|
212
|
-
if (node.isSkipped()) {
|
|
213
|
-
return this.formatter.test(node, new Set(), []);
|
|
214
|
-
}
|
|
215
|
-
const {
|
|
216
|
-
fixtures,
|
|
217
|
-
lines
|
|
218
|
-
} = this.getSteps(scenario, node.tags, exampleRow.id);
|
|
219
|
-
return this.formatter.test(node, fixtures, lines);
|
|
220
|
-
}
|
|
221
|
-
/**
|
|
222
|
-
* Generate test from Scenario
|
|
223
|
-
*/
|
|
224
|
-
getTest(scenario, parent) {
|
|
225
|
-
const node = new _testNode.TestNode(scenario, parent);
|
|
226
|
-
if (this.skipByTagsExpression(node)) {
|
|
227
|
-
return [];
|
|
228
|
-
}
|
|
229
|
-
const pickle = this.findPickle(scenario);
|
|
230
|
-
this.testMetaBuilder.registerTest(node, pickle);
|
|
231
|
-
if (node.isSkipped()) {
|
|
232
|
-
return this.formatter.test(node, new Set(), []);
|
|
233
|
-
}
|
|
234
|
-
const {
|
|
235
|
-
fixtures,
|
|
236
|
-
lines
|
|
237
|
-
} = this.getSteps(scenario, node.tags);
|
|
238
|
-
return this.formatter.test(node, fixtures, lines);
|
|
239
|
-
}
|
|
240
|
-
/**
|
|
241
|
-
* Generate test steps
|
|
242
|
-
*/
|
|
243
|
-
getSteps(scenario, tags, outlineExampleRowId) {
|
|
244
|
-
const testFixtureNames = new Set();
|
|
245
|
-
const testPoms = new _testPoms.TestPoms(scenario.name || 'Background');
|
|
246
|
-
const decoratorSteps = [];
|
|
247
|
-
let previousKeywordType = undefined;
|
|
248
|
-
const lines = scenario.steps.map((step, index) => {
|
|
249
|
-
const {
|
|
250
|
-
keyword,
|
|
251
|
-
keywordType,
|
|
252
|
-
fixtureNames: stepFixtureNames,
|
|
253
|
-
line,
|
|
254
|
-
pickleStep,
|
|
255
|
-
stepConfig
|
|
256
|
-
} = this.getStep(step, previousKeywordType, outlineExampleRowId);
|
|
257
|
-
previousKeywordType = keywordType;
|
|
258
|
-
testFixtureNames.add(keyword);
|
|
259
|
-
stepFixtureNames.forEach(fixtureName => testFixtureNames.add(fixtureName));
|
|
260
|
-
if ((0, _stepConfig.isDecorator)(stepConfig)) {
|
|
261
|
-
testPoms.addByStep(stepConfig.pomNode);
|
|
262
|
-
decoratorSteps.push({
|
|
263
|
-
index,
|
|
264
|
-
keyword,
|
|
265
|
-
pickleStep,
|
|
266
|
-
pomNode: stepConfig.pomNode
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
return line;
|
|
270
|
-
});
|
|
271
|
-
// decorator steps handled in second pass to guess fixtures
|
|
272
|
-
if (decoratorSteps.length) {
|
|
273
|
-
testFixtureNames.forEach(fixtureName => testPoms.addByFixtureName(fixtureName));
|
|
274
|
-
tags === null || tags === void 0 || tags.forEach(tag => testPoms.addByTag(tag));
|
|
275
|
-
testPoms.resolveFixtures();
|
|
276
|
-
decoratorSteps.forEach(step => {
|
|
277
|
-
const {
|
|
278
|
-
line,
|
|
279
|
-
fixtureName
|
|
280
|
-
} = this.getDecoratorStep(step, testPoms);
|
|
281
|
-
lines[step.index] = line;
|
|
282
|
-
testFixtureNames.add(fixtureName);
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
|
-
return {
|
|
286
|
-
fixtures: testFixtureNames,
|
|
287
|
-
lines
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
/**
|
|
291
|
-
* Generate step for Given, When, Then
|
|
292
|
-
*/
|
|
293
|
-
// eslint-disable-next-line max-statements, complexity
|
|
294
|
-
getStep(step, previousKeywordType, outlineExampleRowId) {
|
|
295
|
-
const pickleStep = this.findPickleStep(step, outlineExampleRowId);
|
|
296
|
-
const stepDefinition = (0, _loadSteps.findStepDefinition)(this.options.supportCodeLibrary, pickleStep.text, this.featureUri);
|
|
297
|
-
const keywordType = (0, _index.getStepKeywordType)({
|
|
298
|
-
keyword: step.keyword,
|
|
299
|
-
language: this.language,
|
|
300
|
-
previousKeywordType
|
|
301
|
-
});
|
|
302
|
-
const enKeyword = this.getStepEnglishKeyword(step);
|
|
303
|
-
if (!stepDefinition) {
|
|
304
|
-
this.undefinedSteps.push({
|
|
305
|
-
keywordType,
|
|
306
|
-
step,
|
|
307
|
-
pickleStep
|
|
308
|
-
});
|
|
309
|
-
return this.getMissingStep(enKeyword, keywordType, pickleStep);
|
|
310
|
-
}
|
|
311
|
-
this.usedStepDefinitions.add(stepDefinition);
|
|
312
|
-
// for cucumber-style stepConfig is undefined
|
|
313
|
-
const stepConfig = (0, _stepConfig.getStepConfig)(stepDefinition);
|
|
314
|
-
if (stepConfig !== null && stepConfig !== void 0 && stepConfig.hasCustomTest) {
|
|
315
|
-
this.hasCustomTest = true;
|
|
316
|
-
}
|
|
317
|
-
if (!(0, _stepConfig.isPlaywrightStyle)(stepConfig)) {
|
|
318
|
-
this.hasCucumberStyle = true;
|
|
319
|
-
}
|
|
320
|
-
const fixtureNames = this.getStepFixtureNames(stepDefinition);
|
|
321
|
-
const line = (0, _stepConfig.isDecorator)(stepConfig) ? '' : this.formatter.step(enKeyword, pickleStep.text, pickleStep.argument, fixtureNames);
|
|
322
|
-
return {
|
|
323
|
-
keyword: enKeyword,
|
|
324
|
-
keywordType,
|
|
325
|
-
fixtureNames,
|
|
326
|
-
line,
|
|
327
|
-
pickleStep,
|
|
328
|
-
stepConfig
|
|
329
|
-
};
|
|
330
|
-
}
|
|
331
|
-
getMissingStep(keyword, keywordType, pickleStep) {
|
|
332
|
-
return {
|
|
333
|
-
keyword,
|
|
334
|
-
keywordType,
|
|
335
|
-
fixtureNames: [],
|
|
336
|
-
line: this.formatter.missingStep(keyword, pickleStep.text),
|
|
337
|
-
pickleStep,
|
|
338
|
-
stepConfig: undefined
|
|
339
|
-
};
|
|
340
|
-
}
|
|
341
|
-
/**
|
|
342
|
-
* Returns pickle for scenario.
|
|
343
|
-
* Pickle is executable entity including background and steps with example values.
|
|
344
|
-
*/
|
|
345
|
-
findPickle(scenario, exampleRow) {
|
|
346
|
-
const pickle = this.pickles.find(pickle => {
|
|
347
|
-
const hasScenarioId = pickle.astNodeIds.includes(scenario.id);
|
|
348
|
-
const hasExampleRowId = !exampleRow || pickle.astNodeIds.includes(exampleRow.id);
|
|
349
|
-
return hasScenarioId && hasExampleRowId;
|
|
350
|
-
});
|
|
351
|
-
if (!pickle) {
|
|
352
|
-
throw new Error(`Pickle not found for scenario: ${scenario.name}`);
|
|
353
|
-
}
|
|
354
|
-
return pickle;
|
|
355
|
-
}
|
|
356
|
-
/**
|
|
357
|
-
* Returns pickleStep for ast step.
|
|
358
|
-
* PickleStep contains step text with inserted example values.
|
|
359
|
-
*
|
|
360
|
-
* Note:
|
|
361
|
-
* When searching for pickleStep iterate all pickles in a file
|
|
362
|
-
* b/c for background steps there is no own pickle.
|
|
363
|
-
* This can be optimized: pass optional 'pickle' parameter
|
|
364
|
-
* and search only inside it if it exists.
|
|
365
|
-
* But this increases code complexity, and performance impact seems to be minimal
|
|
366
|
-
* b/c number of pickles inside feature file is not very big.
|
|
367
|
-
*/
|
|
368
|
-
findPickleStep(step, exampleRowId) {
|
|
369
|
-
for (const pickle of this.pickles) {
|
|
370
|
-
const pickleStep = pickle.steps.find(({
|
|
371
|
-
astNodeIds
|
|
372
|
-
}) => {
|
|
373
|
-
const hasStepId = astNodeIds.includes(step.id);
|
|
374
|
-
const hasRowId = !exampleRowId || astNodeIds.includes(exampleRowId);
|
|
375
|
-
return hasStepId && hasRowId;
|
|
376
|
-
});
|
|
377
|
-
if (pickleStep) {
|
|
378
|
-
return pickleStep;
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
throw new Error(`Pickle step not found for step: ${step.text}`);
|
|
382
|
-
}
|
|
383
|
-
getStepEnglishKeyword(step) {
|
|
384
|
-
const nativeKeyword = step.keyword.trim();
|
|
385
|
-
const enKeyword = nativeKeyword === '*' ? 'And' : this.getEnglishKeyword(nativeKeyword);
|
|
386
|
-
if (!enKeyword) {
|
|
387
|
-
throw new Error(`Keyword not found: ${nativeKeyword}`);
|
|
388
|
-
}
|
|
389
|
-
return enKeyword;
|
|
390
|
-
}
|
|
391
|
-
getStepFixtureNames(stepDefinition) {
|
|
392
|
-
const stepConfig = (0, _stepConfig.getStepConfig)(stepDefinition);
|
|
393
|
-
if ((0, _stepConfig.isPlaywrightStyle)(stepConfig)) {
|
|
394
|
-
// for decorator steps fixtureNames are defined later in second pass
|
|
395
|
-
return (0, _stepConfig.isDecorator)(stepConfig) ? [] : (0, _fixtures.extractFixtureNames)(stepConfig.fn);
|
|
396
|
-
} else {
|
|
397
|
-
return (0, _fixtures.extractFixtureNamesFromFnBodyMemo)(stepDefinition.code);
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
getDecoratorStep(step, testPoms) {
|
|
401
|
-
const {
|
|
402
|
-
keyword,
|
|
403
|
-
pickleStep,
|
|
404
|
-
pomNode
|
|
405
|
-
} = step;
|
|
406
|
-
const resolvedFixtures = testPoms.getResolvedFixtures(pomNode);
|
|
407
|
-
if (resolvedFixtures.length !== 1) {
|
|
408
|
-
const suggestedTags = resolvedFixtures.filter(f => !f.byTag).map(f => (0, _testPoms.buildFixtureTag)(f.name)).join(', ');
|
|
409
|
-
const suggestedTagsStr = suggestedTags.length ? ` or set one of the following tags: ${suggestedTags}` : '.';
|
|
410
|
-
(0, _exit.exit)(`Can't guess fixture for decorator step "${pickleStep.text}" in file: ${this.featureUri}.`, `Please refactor your Page Object classes${suggestedTagsStr}`);
|
|
411
|
-
}
|
|
412
|
-
const fixtureName = resolvedFixtures[0].name;
|
|
413
|
-
return {
|
|
414
|
-
fixtureName,
|
|
415
|
-
line: this.formatter.step(keyword, pickleStep.text, pickleStep.argument, [fixtureName])
|
|
416
|
-
};
|
|
417
|
-
}
|
|
418
|
-
getOutlineTestTitle(titleFormat, examples, exampleRow, exampleIndex) {
|
|
419
|
-
const params = {
|
|
420
|
-
_index_: exampleIndex
|
|
421
|
-
};
|
|
422
|
-
exampleRow.cells.forEach((cell, index) => {
|
|
423
|
-
var _examples$tableHeader;
|
|
424
|
-
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;
|
|
425
|
-
if (colName) {
|
|
426
|
-
params[colName] = cell.value;
|
|
427
|
-
}
|
|
428
|
-
});
|
|
429
|
-
return (0, _utils.template)(titleFormat, params);
|
|
430
|
-
}
|
|
431
|
-
getExamplesTitleFormat(scenario, examples) {
|
|
432
|
-
return this.getExamplesTitleFormatFromComment(examples) || this.getExamplesTitleFormatFromScenarioName(scenario, examples) || this.config.examplesTitleFormat;
|
|
433
|
-
}
|
|
434
|
-
getExamplesTitleFormatFromComment(examples) {
|
|
435
|
-
var _comment$text;
|
|
436
|
-
const {
|
|
437
|
-
line
|
|
438
|
-
} = examples.location;
|
|
439
|
-
const titleFormatCommentLine = line - 1;
|
|
440
|
-
const comment = this.gherkinDocument.comments.find(c => {
|
|
441
|
-
return c.location.line === titleFormatCommentLine;
|
|
442
|
-
});
|
|
443
|
-
const commentText = comment === null || comment === void 0 || (_comment$text = comment.text) === null || _comment$text === void 0 ? void 0 : _comment$text.trim();
|
|
444
|
-
const prefix = '# title-format:';
|
|
445
|
-
return commentText !== null && commentText !== void 0 && commentText.startsWith(prefix) ? commentText.replace(prefix, '').trim() : '';
|
|
446
|
-
}
|
|
447
|
-
getExamplesTitleFormatFromScenarioName(scenario, examples) {
|
|
448
|
-
var _examples$tableHeader2;
|
|
449
|
-
const columnsInScenarioName = (0, _utils.extractTemplateParams)(scenario.name);
|
|
450
|
-
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 => {
|
|
451
|
-
return cell.value && columnsInScenarioName.includes(cell.value);
|
|
452
|
-
}));
|
|
453
|
-
return hasColumnsFromExamples ? scenario.name : '';
|
|
454
|
-
}
|
|
455
|
-
skipByTagsExpression(node) {
|
|
456
|
-
// see: https://github.com/cucumber/tag-expressions/tree/main/javascript
|
|
457
|
-
const {
|
|
458
|
-
tagsExpression
|
|
459
|
-
} = this.options;
|
|
460
|
-
return tagsExpression && !tagsExpression.evaluate(node.tags);
|
|
461
|
-
}
|
|
462
|
-
isOutline(scenario) {
|
|
463
|
-
const keyword = this.getEnglishKeyword(scenario.keyword);
|
|
464
|
-
return keyword === 'ScenarioOutline' || keyword === 'Scenario Outline' || keyword === 'Scenario Template';
|
|
465
|
-
}
|
|
466
|
-
getEnglishKeyword(keyword) {
|
|
467
|
-
return this.i18nKeywordsMap ? this.i18nKeywordsMap.get(keyword) : keyword;
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
exports.TestFile = TestFile;
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.TestMetaBuilder = void 0;
|
|
7
|
-
exports.getTestMeta = getTestMeta;
|
|
8
|
-
var _utils = require("../utils");
|
|
9
|
-
/**
|
|
10
|
-
* Class to build and print testMeta object containing meta info about each test.
|
|
11
|
-
* Tests are identified by special key constructed from title path.
|
|
12
|
-
*
|
|
13
|
-
* Example:
|
|
14
|
-
* const testMeta = {
|
|
15
|
-
* "Simple scenario": { pickleLocation: "3:10", tags: ["@foo"] },
|
|
16
|
-
* "Scenario with examples|Example #1": { pickleLocation: "8:26", tags: [] },
|
|
17
|
-
* "Rule 1|Scenario with examples|Example #1": { pickleLocation: "9:42", tags: [] },
|
|
18
|
-
* };
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
const TEST_KEY_SEPARATOR = '|';
|
|
22
|
-
class TestMetaBuilder {
|
|
23
|
-
tests = [];
|
|
24
|
-
get testCount() {
|
|
25
|
-
return this.tests.length;
|
|
26
|
-
}
|
|
27
|
-
registerTest(node, pickle) {
|
|
28
|
-
const testMeta = {
|
|
29
|
-
pickleLocation: (0, _utils.stringifyLocation)(pickle.location),
|
|
30
|
-
tags: node.tags.length ? node.tags : undefined
|
|
31
|
-
};
|
|
32
|
-
this.tests.push({
|
|
33
|
-
node,
|
|
34
|
-
testMeta
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
getObjectLines() {
|
|
38
|
-
// build object line by line to have each test on a separate line,
|
|
39
|
-
// but value should be in one line.
|
|
40
|
-
return this.tests.map(test => {
|
|
41
|
-
const testKey = this.getTestKey(test.node);
|
|
42
|
-
return `${JSON.stringify(testKey)}: ${JSON.stringify(test.testMeta)},`;
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
getTestKey(node) {
|
|
46
|
-
// .slice(1) -> b/c we remove top describe title (it's same for all tests)
|
|
47
|
-
return node.titlePath.slice(1).join(TEST_KEY_SEPARATOR);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
exports.TestMetaBuilder = TestMetaBuilder;
|
|
51
|
-
function getTestMeta(testMetaMap, testInfo) {
|
|
52
|
-
// .slice(2) -> b/c we remove filename and top describe title
|
|
53
|
-
const key = testInfo.titlePath.slice(2).join(TEST_KEY_SEPARATOR);
|
|
54
|
-
const testMeta = testMetaMap[key];
|
|
55
|
-
if (!testMeta) {
|
|
56
|
-
// throw new Error(`Can't find testMeta for key "${key}"`);
|
|
57
|
-
return {};
|
|
58
|
-
}
|
|
59
|
-
return testMeta;
|
|
60
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.TestNode = void 0;
|
|
7
|
-
var _utils = require("../utils");
|
|
8
|
-
var _specialTags = require("./specialTags");
|
|
9
|
-
/**
|
|
10
|
-
* Universal TestNode class representing test or suite in a test file.
|
|
11
|
-
* Holds parent-child links.
|
|
12
|
-
* Allows to inherit tags and titles path.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
class TestNode {
|
|
16
|
-
title;
|
|
17
|
-
titlePath;
|
|
18
|
-
ownTags;
|
|
19
|
-
tags;
|
|
20
|
-
specialTags;
|
|
21
|
-
constructor(gherkinNode, parent) {
|
|
22
|
-
this.title = gherkinNode.name;
|
|
23
|
-
this.titlePath = ((parent === null || parent === void 0 ? void 0 : parent.titlePath) || []).concat([this.title]);
|
|
24
|
-
this.ownTags = (0, _utils.removeDuplicates)(getTagNames(gherkinNode.tags));
|
|
25
|
-
this.tags = (0, _utils.removeDuplicates)(((parent === null || parent === void 0 ? void 0 : parent.tags) || []).concat(this.ownTags));
|
|
26
|
-
this.specialTags = new _specialTags.SpecialTags(this.ownTags, this.tags);
|
|
27
|
-
}
|
|
28
|
-
isSkipped() {
|
|
29
|
-
return this.specialTags.skip || this.specialTags.fixme;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
exports.TestNode = TestNode;
|
|
33
|
-
function getTagNames(tags) {
|
|
34
|
-
return tags.map(tag => tag.name);
|
|
35
|
-
}
|
|
@@ -1,133 +0,0 @@
|
|
|
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("../steps/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
|
-
}
|