@zohodesk/testinglibrary 0.1.8-exp-bdd-v2 → 0.1.8-exp-bdd-v3

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.
Files changed (56) hide show
  1. package/build/bdd-poc/test/stepGenerate/stepFileGenerate.js +1 -1
  2. package/build/core/playwright/index.js +6 -18
  3. package/build/core/playwright/setup/config-utils.js +14 -13
  4. package/build/core/playwright/test-runner.js +30 -26
  5. package/build/decorators.d.ts +1 -1
  6. package/build/decorators.js +2 -16
  7. package/package.json +1 -1
  8. package/build/bdd-framework/cli/commands/env.js +0 -43
  9. package/build/bdd-framework/cli/commands/export.js +0 -48
  10. package/build/bdd-framework/cli/commands/test.js +0 -61
  11. package/build/bdd-framework/cli/index.js +0 -11
  12. package/build/bdd-framework/cli/options.js +0 -20
  13. package/build/bdd-framework/cli/worker.js +0 -13
  14. package/build/bdd-framework/config/dir.js +0 -27
  15. package/build/bdd-framework/config/env.js +0 -49
  16. package/build/bdd-framework/config/index.js +0 -91
  17. package/build/bdd-framework/cucumber/buildStepDefinition.js +0 -43
  18. package/build/bdd-framework/cucumber/gherkin.d.js +0 -5
  19. package/build/bdd-framework/cucumber/gherkin.d.ts +0 -45
  20. package/build/bdd-framework/cucumber/loadConfig.js +0 -17
  21. package/build/bdd-framework/cucumber/loadFeatures.js +0 -39
  22. package/build/bdd-framework/cucumber/loadSnippetBuilder.js +0 -20
  23. package/build/bdd-framework/cucumber/loadSources.js +0 -57
  24. package/build/bdd-framework/cucumber/loadSteps.js +0 -35
  25. package/build/bdd-framework/decorators.js +0 -22
  26. package/build/bdd-framework/gen/formatter.js +0 -88
  27. package/build/bdd-framework/gen/i18n.js +0 -35
  28. package/build/bdd-framework/gen/index.js +0 -163
  29. package/build/bdd-framework/gen/poms.js +0 -46
  30. package/build/bdd-framework/gen/testFile.js +0 -356
  31. package/build/bdd-framework/gen/testNode.js +0 -48
  32. package/build/bdd-framework/gen/testPoms.js +0 -123
  33. package/build/bdd-framework/index.js +0 -45
  34. package/build/bdd-framework/playwright/fixtureParameterNames.js +0 -77
  35. package/build/bdd-framework/playwright/getLocationInFile.js +0 -46
  36. package/build/bdd-framework/playwright/loadConfig.js +0 -42
  37. package/build/bdd-framework/playwright/testTypeImpl.js +0 -57
  38. package/build/bdd-framework/playwright/transform.js +0 -80
  39. package/build/bdd-framework/playwright/types.js +0 -5
  40. package/build/bdd-framework/playwright/utils.js +0 -37
  41. package/build/bdd-framework/run/bddFixtures.js +0 -108
  42. package/build/bdd-framework/run/bddWorld.js +0 -88
  43. package/build/bdd-framework/snippets/index.js +0 -135
  44. package/build/bdd-framework/snippets/snippetSyntax.js +0 -41
  45. package/build/bdd-framework/snippets/snippetSyntaxDecorators.js +0 -26
  46. package/build/bdd-framework/snippets/snippetSyntaxTs.js +0 -18
  47. package/build/bdd-framework/stepDefinitions/createBdd.js +0 -49
  48. package/build/bdd-framework/stepDefinitions/createDecorators.js +0 -109
  49. package/build/bdd-framework/stepDefinitions/decorators/poms.js +0 -64
  50. package/build/bdd-framework/stepDefinitions/decorators/steps.js +0 -94
  51. package/build/bdd-framework/stepDefinitions/defineStep.js +0 -61
  52. package/build/bdd-framework/stepDefinitions/stepConfig.js +0 -24
  53. package/build/bdd-framework/utils/exit.js +0 -54
  54. package/build/bdd-framework/utils/index.js +0 -44
  55. package/build/bdd-framework/utils/jsStringWrap.js +0 -44
  56. package/build/bdd-framework/utils/logger.js +0 -29
@@ -1,356 +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 _createBdd = require("../stepDefinitions/createBdd");
14
- var _index = require("@cucumber/cucumber/lib/formatter/helpers/index");
15
- var _utils = require("../utils");
16
- var _testPoms = require("./testPoms");
17
- var _testNode = require("./testNode");
18
- var _stepConfig = require("../stepDefinitions/stepConfig");
19
- var _exit = require("../utils/exit");
20
- /**
21
- * Generate test code.
22
- */
23
-
24
- class TestFile {
25
- options;
26
- lines = [];
27
- i18nKeywordsMap;
28
- formatter;
29
- testNodes = [];
30
- hasCustomTest = false;
31
- undefinedSteps = [];
32
- constructor(options) {
33
- this.options = options;
34
- this.formatter = new _formatter.Formatter(options.config);
35
- }
36
- get sourceFile() {
37
- const {
38
- uri
39
- } = this.options.doc;
40
- if (!uri) throw new Error(`Document without uri`);
41
- return uri;
42
- }
43
- get content() {
44
- return this.lines.join('\n');
45
- }
46
- get language() {
47
- var _this$options$doc$fea;
48
- return ((_this$options$doc$fea = this.options.doc.feature) === null || _this$options$doc$fea === void 0 ? void 0 : _this$options$doc$fea.language) || 'en';
49
- }
50
- get config() {
51
- return this.options.config;
52
- }
53
- get outputPath() {
54
- return this.options.outputPath;
55
- }
56
- build() {
57
- this.loadI18nKeywords();
58
- this.lines = [...this.getFileHeader(), ...this.getRootSuite(), ...this.getFileFixtures()];
59
- return this;
60
- }
61
- save() {
62
- const dir = _path.default.dirname(this.outputPath);
63
- if (!_fs.default.existsSync(dir)) _fs.default.mkdirSync(dir, {
64
- recursive: true
65
- });
66
- _fs.default.writeFileSync(this.outputPath, this.content);
67
- }
68
- getFileHeader() {
69
- const importTestFrom = this.getRelativeImportTestFrom();
70
- return this.formatter.fileHeader(this.sourceFile, importTestFrom);
71
- }
72
- loadI18nKeywords() {
73
- if (this.language !== 'en') {
74
- this.i18nKeywordsMap = (0, _i18n.getKeywordsMap)(this.language);
75
- }
76
- }
77
- getRelativeImportTestFrom() {
78
- const {
79
- importTestFrom
80
- } = this.config;
81
- if (!importTestFrom) return;
82
- const {
83
- file,
84
- varName
85
- } = importTestFrom;
86
- const dir = _path.default.dirname(this.outputPath);
87
- return {
88
- file: _path.default.relative(dir, file),
89
- varName
90
- };
91
- }
92
- getFileFixtures() {
93
- return this.formatter.useFixtures([...this.formatter.testFixture(), ...this.formatter.tagsFixture(this.testNodes)]);
94
- }
95
- getRootSuite() {
96
- const {
97
- feature
98
- } = this.options.doc;
99
- if (!feature) throw new Error(`Document without feature.`);
100
- return this.getSuite(feature);
101
- }
102
- /**
103
- * Generate test.describe suite for root Feature or Rule
104
- */
105
- getSuite(feature, parent) {
106
- const node = new _testNode.TestNode(feature, parent);
107
- const lines = [];
108
- // const { backgrounds, rules, scenarios } =
109
- // bgFixtures, bgTags - used as fixture hints for decorator steps
110
- feature.children.forEach(child => lines.push(...this.getSuiteChild(child, node)));
111
- return this.formatter.suite(node, lines);
112
- }
113
- getSuiteChild(child, parent) {
114
- if ('rule' in child && child.rule) return this.getSuite(child.rule, parent);
115
- if (child.background) return this.getBeforeEach(child.background, parent);
116
- if (child.scenario) return this.getScenarioLines(child.scenario, parent);
117
- throw new Error(`Empty child: ${JSON.stringify(child)}`);
118
- }
119
- getScenarioLines(scenario, parent) {
120
- return this.isOutline(scenario) ? this.getOutlineSuite(scenario, parent) : this.getTest(scenario, parent);
121
- }
122
- /**
123
- * Generate test.beforeEach for Background
124
- */
125
- getBeforeEach(bg, parent) {
126
- const node = new _testNode.TestNode({
127
- name: 'background',
128
- tags: []
129
- }, parent);
130
- const {
131
- fixtures,
132
- lines
133
- } = this.getSteps(bg, node.tags);
134
- return this.formatter.beforeEach(fixtures, lines);
135
- }
136
- /**
137
- * Generate test.describe suite for Scenario Outline
138
- */
139
- getOutlineSuite(scenario, parent) {
140
- const node = new _testNode.TestNode(scenario, parent);
141
- const lines = [];
142
- let exampleIndex = 0;
143
- scenario.examples.forEach(examples => {
144
- const titleFormat = this.getExamplesTitleFormat(examples);
145
- examples.tableBody.forEach(exampleRow => {
146
- const testTitle = this.getOutlineTestTitle(titleFormat, examples, exampleRow, ++exampleIndex);
147
- const testLines = this.getOutlineTest(scenario, examples, exampleRow, testTitle, node);
148
- lines.push(...testLines);
149
- });
150
- });
151
- return this.formatter.suite(node, lines);
152
- }
153
- /**
154
- * Generate test from Examples row of Scenario Outline
155
- */
156
- // eslint-disable-next-line max-params
157
- getOutlineTest(scenario, examples, exampleRow, title, parent) {
158
- const node = new _testNode.TestNode({
159
- name: title,
160
- tags: examples.tags
161
- }, parent);
162
- if (this.skipByTagsExpression(node)) return [];
163
- this.testNodes.push(node);
164
- const {
165
- fixtures,
166
- lines
167
- } = this.getSteps(scenario, node.tags, exampleRow.id);
168
- return this.formatter.test(node, fixtures, lines);
169
- }
170
- /**
171
- * Generate test from Scenario
172
- */
173
- getTest(scenario, parent) {
174
- const node = new _testNode.TestNode(scenario, parent);
175
- if (this.skipByTagsExpression(node)) return [];
176
- this.testNodes.push(node);
177
- const {
178
- fixtures,
179
- lines
180
- } = this.getSteps(scenario, node.tags);
181
- return this.formatter.test(node, fixtures, lines);
182
- }
183
- /**
184
- * Generate test steps
185
- */
186
- getSteps(scenario, tags, outlineExampleRowId) {
187
- const testFixtureNames = new Set();
188
- const testPoms = new _testPoms.TestPoms(scenario.name || 'Background');
189
- const decoratorSteps = [];
190
- let previousKeywordType = undefined;
191
- const lines = scenario.steps.map((step, index) => {
192
- const {
193
- keyword,
194
- keywordType,
195
- fixtureNames: stepFixtureNames,
196
- line,
197
- pickleStep,
198
- stepConfig
199
- } = this.getStep(step, previousKeywordType, outlineExampleRowId);
200
- previousKeywordType = keywordType;
201
- testFixtureNames.add(keyword);
202
- stepFixtureNames.forEach(fixtureName => testFixtureNames.add(fixtureName));
203
- if ((0, _stepConfig.isDecorator)(stepConfig)) {
204
- testPoms.addByStep(stepConfig.pomNode);
205
- decoratorSteps.push({
206
- index,
207
- keyword,
208
- pickleStep,
209
- pomNode: stepConfig.pomNode
210
- });
211
- }
212
- return line;
213
- });
214
- // decorator steps handled in second pass to guess fixtures
215
- if (decoratorSteps.length) {
216
- testFixtureNames.forEach(fixtureName => testPoms.addByFixtureName(fixtureName));
217
- tags === null || tags === void 0 || tags.forEach(tag => testPoms.addByTag(tag));
218
- testPoms.resolveFixtures();
219
- decoratorSteps.forEach(step => {
220
- const {
221
- line,
222
- fixtureName
223
- } = this.getDecoratorStep(step, testPoms);
224
- lines[step.index] = line;
225
- testFixtureNames.add(fixtureName);
226
- });
227
- }
228
- return {
229
- fixtures: testFixtureNames,
230
- lines
231
- };
232
- }
233
- /**
234
- * Generate step for Given, When, Then
235
- */
236
- // eslint-disable-next-line max-statements, complexity
237
- getStep(step, previousKeywordType, outlineExampleRowId) {
238
- const pickleStep = this.getPickleStep(step, outlineExampleRowId);
239
- const stepDefinition = (0, _loadSteps.findStepDefinition)(this.options.supportCodeLibrary, pickleStep.text, this.sourceFile);
240
- const keywordType = (0, _index.getStepKeywordType)({
241
- keyword: step.keyword,
242
- language: this.language,
243
- previousKeywordType
244
- });
245
- let keyword = this.getStepKeyword(step);
246
- if (!stepDefinition) {
247
- this.undefinedSteps.push({
248
- keywordType,
249
- step,
250
- pickleStep
251
- });
252
- return this.getMissingStep(keyword, keywordType, pickleStep);
253
- }
254
- // for cucumber-style stepConfig is undefined
255
- const stepConfig = (0, _stepConfig.getStepConfig)(stepDefinition);
256
- if (stepConfig !== null && stepConfig !== void 0 && stepConfig.hasCustomTest) this.hasCustomTest = true;
257
- // for cucumber-style transform Given/When/Then -> Given_/When_/Then_
258
- // to use own bddWorld (containing PW built-in fixtures)
259
- if (!(0, _stepConfig.isPlaywrightStyle)(stepConfig)) keyword = `${keyword}_`;
260
- // for decorator steps fixtureNames are defined later in second pass
261
- const fixtureNames = (0, _stepConfig.isDecorator)(stepConfig) ? [] : (0, _createBdd.extractFixtureNames)(stepConfig === null || stepConfig === void 0 ? void 0 : stepConfig.fn);
262
- const line = (0, _stepConfig.isDecorator)(stepConfig) ? '' : this.formatter.step(keyword, pickleStep.text, pickleStep.argument, fixtureNames);
263
- return {
264
- keyword,
265
- keywordType,
266
- fixtureNames,
267
- line,
268
- pickleStep,
269
- stepConfig
270
- };
271
- }
272
- getMissingStep(keyword, keywordType, pickleStep) {
273
- return {
274
- keyword,
275
- keywordType,
276
- fixtureNames: [],
277
- line: this.formatter.missingStep(keyword, pickleStep.text),
278
- pickleStep,
279
- stepConfig: undefined
280
- };
281
- }
282
- getPickleStep(step, outlineExampleRowId) {
283
- for (const pickle of this.options.pickles) {
284
- const pickleStep = pickle.steps.find(({
285
- astNodeIds
286
- }) => {
287
- const hasStepId = astNodeIds.includes(step.id);
288
- const hasRowId = !outlineExampleRowId || astNodeIds.includes(outlineExampleRowId);
289
- return hasStepId && hasRowId;
290
- });
291
- if (pickleStep) return pickleStep;
292
- }
293
- throw new Error(`Pickle step not found for step: ${step.text}`);
294
- }
295
- getStepKeyword(step) {
296
- const origKeyword = step.keyword.trim();
297
- const enKeyword = origKeyword === '*' ? 'And' : this.getEnglishKeyword(origKeyword);
298
- if (!enKeyword) throw new Error(`Keyword not found: ${origKeyword}`);
299
- return enKeyword;
300
- }
301
- getDecoratorStep(step, testPoms) {
302
- const {
303
- keyword,
304
- pickleStep,
305
- pomNode
306
- } = step;
307
- const resolvedFixtures = testPoms.getResolvedFixtures(pomNode);
308
- if (resolvedFixtures.length !== 1) {
309
- const suggestedTags = resolvedFixtures.filter(f => !f.byTag).map(f => (0, _testPoms.buildFixtureTag)(f.name)).join(', ');
310
- const suggestedTagsStr = suggestedTags.length ? ` or set one of the following tags: ${suggestedTags}` : '.';
311
- (0, _exit.exit)(`Can't guess fixture for decorator step "${pickleStep.text}" in file: ${this.sourceFile}.`, `Please refactor your Page Object classes${suggestedTagsStr}`);
312
- }
313
- const fixtureName = resolvedFixtures[0].name;
314
- return {
315
- fixtureName,
316
- line: this.formatter.step(keyword, pickleStep.text, pickleStep.argument, [fixtureName])
317
- };
318
- }
319
- getOutlineTestTitle(titleFormat, examples, exampleRow, exampleIndex) {
320
- const params = {
321
- _index_: exampleIndex
322
- };
323
- exampleRow.cells.forEach((cell, index) => {
324
- var _examples$tableHeader;
325
- 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;
326
- if (colName) params[colName] = cell.value;
327
- });
328
- return (0, _utils.template)(titleFormat, params);
329
- }
330
- getExamplesTitleFormat(examples) {
331
- var _comment$text;
332
- const {
333
- line
334
- } = examples.location;
335
- const titleFormatCommentLine = line - 1;
336
- const comment = this.options.doc.comments.find(c => {
337
- return c.location.line === titleFormatCommentLine;
338
- });
339
- const commentText = comment === null || comment === void 0 || (_comment$text = comment.text) === null || _comment$text === void 0 ? void 0 : _comment$text.trim();
340
- const prefix = '# title-format:';
341
- return commentText !== null && commentText !== void 0 && commentText.startsWith(prefix) ? commentText.replace(prefix, '').trim() : this.config.examplesTitleFormat;
342
- }
343
- skipByTagsExpression(node) {
344
- var _this$options$tagsExp;
345
- // see: https://github.com/cucumber/tag-expressions/tree/main/javascript
346
- return ((_this$options$tagsExp = this.options.tagsExpression) === null || _this$options$tagsExp === void 0 ? void 0 : _this$options$tagsExp.evaluate(node.tags)) === false;
347
- }
348
- isOutline(scenario) {
349
- const keyword = this.getEnglishKeyword(scenario.keyword);
350
- return keyword === 'ScenarioOutline' || keyword === 'Scenario Outline' || keyword === 'Scenario Template';
351
- }
352
- getEnglishKeyword(keyword) {
353
- return this.i18nKeywordsMap ? this.i18nKeywordsMap.get(keyword) : keyword;
354
- }
355
- }
356
- exports.TestFile = TestFile;
@@ -1,48 +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
- /**
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
- initOwnTags(gherkinNode) {
27
- const tagNames = (0, _utils.removeDuplicates)(getTagNames(gherkinNode.tags));
28
- tagNames.forEach(tag => {
29
- if (isSpecialTag(tag)) {
30
- this.setFlag(tag);
31
- } else {
32
- this.ownTags.push(tag);
33
- }
34
- });
35
- }
36
- setFlag(tag) {
37
- if (tag === '@only') this.flags.only = true;
38
- if (tag === '@skip') this.flags.skip = true;
39
- if (tag === '@fixme') this.flags.fixme = true;
40
- }
41
- }
42
- exports.TestNode = TestNode;
43
- function getTagNames(tags) {
44
- return tags.map(tag => tag.name);
45
- }
46
- function isSpecialTag(tag) {
47
- return SPECIAL_TAGS.includes(tag);
48
- }
@@ -1,123 +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 _poms = require("../stepDefinitions/decorators/poms");
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, _poms.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, _poms.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) return usedPom.fixtures;
77
- // Recursively resolve children fixtures, used in test.
78
- let childFixtures = [...pomNode.children].map(child => this.getResolvedFixtures(child)).flat();
79
- if (!usedPom) return childFixtures;
80
- if (childFixtures.length) {
81
- this.verifyChildFixtures(pomNode, usedPom, childFixtures);
82
- usedPom.fixtures = childFixtures;
83
- } else {
84
- usedPom.fixtures = [{
85
- name: pomNode.fixtureName,
86
- byTag: usedPom.byTag
87
- }];
88
- }
89
- return usedPom.fixtures;
90
- }
91
- addUsedPom(pomNode, {
92
- byTag
93
- }) {
94
- if (!pomNode) return;
95
- const usedPom = this.usedPoms.get(pomNode);
96
- if (usedPom) {
97
- if (byTag && !usedPom.byTag) usedPom.byTag = true;
98
- } else {
99
- this.usedPoms.set(pomNode, {
100
- byTag
101
- });
102
- }
103
- }
104
- /**
105
- * For scenarios with @fixture:xxx tags verify that there are no steps from fixtures,
106
- * deeper than xxx.
107
- * @fixture:xxx tag provides maximum fixture that can be used in the scenario.
108
- */
109
- verifyChildFixtures(pomNode, usedPom, childFixtures) {
110
- if (!usedPom.byTag) return;
111
- const childFixturesBySteps = childFixtures.filter(f => !f.byTag);
112
- if (childFixturesBySteps.length) {
113
- (0, _exit.exit)(`Scenario "${this.title}" contains ${childFixturesBySteps.length} step(s)`, `not compatible with required fixture "${pomNode.fixtureName}"`);
114
- }
115
- }
116
- }
117
- exports.TestPoms = TestPoms;
118
- function extractFixtureName(tag) {
119
- return tag.startsWith(FIXTURE_TAG_PREFIX) ? tag.replace(FIXTURE_TAG_PREFIX, '') : '';
120
- }
121
- function buildFixtureTag(fixtureName) {
122
- return `${FIXTURE_TAG_PREFIX}${fixtureName}`;
123
- }
@@ -1,45 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "BDDInputConfig", {
7
- enumerable: true,
8
- get: function () {
9
- return _config.BDDInputConfig;
10
- }
11
- });
12
- Object.defineProperty(exports, "BddWorld", {
13
- enumerable: true,
14
- get: function () {
15
- return _bddWorld.BddWorld;
16
- }
17
- });
18
- Object.defineProperty(exports, "BddWorldOptions", {
19
- enumerable: true,
20
- get: function () {
21
- return _bddWorld.BddWorldOptions;
22
- }
23
- });
24
- Object.defineProperty(exports, "createBdd", {
25
- enumerable: true,
26
- get: function () {
27
- return _createBdd.createBdd;
28
- }
29
- });
30
- Object.defineProperty(exports, "defineBddConfig", {
31
- enumerable: true,
32
- get: function () {
33
- return _config.defineBddConfig;
34
- }
35
- });
36
- Object.defineProperty(exports, "test", {
37
- enumerable: true,
38
- get: function () {
39
- return _bddFixtures.test;
40
- }
41
- });
42
- var _config = require("./config");
43
- var _createBdd = require("./stepDefinitions/createBdd");
44
- var _bddFixtures = require("./run/bddFixtures");
45
- var _bddWorld = require("./run/bddWorld");
@@ -1,77 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.fixtureParameterNames = fixtureParameterNames;
7
- /**
8
- * Extracted from playwright.
9
- * https://github.com/microsoft/playwright/blob/main/packages/playwright-test/src/common/fixtures.ts#L226
10
- */
11
- /* eslint-disable max-statements, complexity, max-len, max-depth */
12
- const signatureSymbol = Symbol('signature');
13
- function fixtureParameterNames(fn) {
14
- if (typeof fn !== 'function') return [];
15
- if (!fn[signatureSymbol]) fn[signatureSymbol] = innerFixtureParameterNames(fn);
16
- return fn[signatureSymbol];
17
- }
18
- function innerFixtureParameterNames(fn) {
19
- const text = filterOutComments(fn.toString());
20
- const match = text.match(/(?:async)?(?:\s+function)?[^(]*\(([^)]*)/);
21
- if (!match) return [];
22
- const trimmedParams = match[1].trim();
23
- if (!trimmedParams) return [];
24
- const [firstParam] = splitByComma(trimmedParams);
25
- if (firstParam[0] !== '{' || firstParam[firstParam.length - 1] !== '}') {
26
- throw new Error('First argument must use the object destructuring pattern: ' + firstParam + ' ' + fn.toString());
27
- }
28
- const props = splitByComma(firstParam.substring(1, firstParam.length - 1)).map(prop => {
29
- const colon = prop.indexOf(':');
30
- return colon === -1 ? prop.trim() : prop.substring(0, colon).trim();
31
- });
32
- const restProperty = props.find(prop => prop.startsWith('...'));
33
- if (restProperty) {
34
- throw new Error(`Rest property "${restProperty}" is not supported. List all used fixtures explicitly, separated by comma. ${fn.toString()}`);
35
- }
36
- return props;
37
- }
38
- function filterOutComments(s) {
39
- const result = [];
40
- let commentState = 'none';
41
- for (let i = 0; i < s.length; ++i) {
42
- if (commentState === 'singleline') {
43
- if (s[i] === '\n') commentState = 'none';
44
- } else if (commentState === 'multiline') {
45
- if (s[i - 1] === '*' && s[i] === '/') commentState = 'none';
46
- } else if (commentState === 'none') {
47
- if (s[i] === '/' && s[i + 1] === '/') {
48
- commentState = 'singleline';
49
- } else if (s[i] === '/' && s[i + 1] === '*') {
50
- commentState = 'multiline';
51
- i += 2;
52
- } else {
53
- result.push(s[i]);
54
- }
55
- }
56
- }
57
- return result.join('');
58
- }
59
- function splitByComma(s) {
60
- const result = [];
61
- const stack = [];
62
- let start = 0;
63
- for (let i = 0; i < s.length; i++) {
64
- if (s[i] === '{' || s[i] === '[') {
65
- stack.push(s[i] === '{' ? '}' : ']');
66
- } else if (s[i] === stack[stack.length - 1]) {
67
- stack.pop();
68
- } else if (!stack.length && s[i] === ',') {
69
- const token = s.substring(start, i).trim();
70
- if (token) result.push(token);
71
- start = i + 1;
72
- }
73
- }
74
- const lastToken = s.substring(start).trim();
75
- if (lastToken) result.push(lastToken);
76
- return result;
77
- }
@@ -1,46 +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.getLocationInFile = getLocationInFile;
8
- var _url = _interopRequireDefault(require("url"));
9
- var _utils = require("./utils");
10
- /**
11
- * Inspects stacktrace and finds call location in provided file.
12
- * This function is based on Playwright's getLocationByStacktrace().
13
- * See: https://github.com/microsoft/playwright/blob/main/packages/playwright-test/src/common/transform.ts#L229
14
- */
15
- function getLocationInFile(filePath) {
16
- const {
17
- sourceMapSupport
18
- } = (0, _utils.requirePlaywrightModule)('lib/utilsBundle.js');
19
- const oldPrepareStackTrace = Error.prepareStackTrace;
20
- Error.prepareStackTrace = (error, stackFrames) => {
21
- const frameInFile = stackFrames.find(frame => frame.getFileName() === filePath);
22
- if (!frameInFile) return {
23
- file: '',
24
- line: 0,
25
- column: 0
26
- };
27
- const frame = sourceMapSupport.wrapCallSite(frameInFile);
28
- const fileName = frame.getFileName();
29
- // Node error stacks for modules use file:// urls instead of paths.
30
- const file = fileName && fileName.startsWith('file://') ? _url.default.fileURLToPath(fileName) : fileName;
31
- return {
32
- file,
33
- line: frame.getLineNumber(),
34
- column: frame.getColumnNumber()
35
- };
36
- };
37
- // commented stackTraceLImit modification, todo: check if it has perf impact
38
- // const oldStackTraceLimit = Error.stackTraceLimit;
39
- // Error.stackTraceLimit = level + 1;
40
- const obj = {};
41
- Error.captureStackTrace(obj);
42
- const location = obj.stack;
43
- // Error.stackTraceLimit = oldStackTraceLimit;
44
- Error.prepareStackTrace = oldPrepareStackTrace;
45
- return location;
46
- }