@zohodesk/testinglibrary 0.0.5 → 0.0.6

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 (111) hide show
  1. package/.babelrc +19 -0
  2. package/.eslintrc.js +27 -0
  3. package/.prettierrc +6 -0
  4. package/{changelog.md → Changelog.md} +38 -25
  5. package/README.md +17 -17
  6. package/bin/cli.js +2 -2
  7. package/bin/postinstall.js +1 -16
  8. package/build/bdd-framework/cli/commands/env.js +43 -0
  9. package/build/bdd-framework/cli/commands/export.js +48 -0
  10. package/build/bdd-framework/cli/commands/test.js +59 -0
  11. package/build/bdd-framework/cli/index.js +11 -0
  12. package/build/bdd-framework/cli/options.js +20 -0
  13. package/build/bdd-framework/cli/worker.js +13 -0
  14. package/build/bdd-framework/config/dir.js +27 -0
  15. package/build/bdd-framework/config/env.js +49 -0
  16. package/build/bdd-framework/config/index.js +91 -0
  17. package/build/bdd-framework/cucumber/buildStepDefinition.js +43 -0
  18. package/build/bdd-framework/cucumber/gherkin.d.js +5 -0
  19. package/build/bdd-framework/cucumber/gherkin.d.ts +45 -0
  20. package/build/bdd-framework/cucumber/loadConfig.js +17 -0
  21. package/build/bdd-framework/cucumber/loadFeatures.js +39 -0
  22. package/build/bdd-framework/cucumber/loadSnippetBuilder.js +20 -0
  23. package/build/bdd-framework/cucumber/loadSources.js +57 -0
  24. package/build/bdd-framework/cucumber/loadSteps.js +35 -0
  25. package/build/bdd-framework/decorators.js +22 -0
  26. package/build/bdd-framework/gen/formatter.js +88 -0
  27. package/build/bdd-framework/gen/i18n.js +35 -0
  28. package/build/bdd-framework/gen/index.js +160 -0
  29. package/build/bdd-framework/gen/poms.js +46 -0
  30. package/build/bdd-framework/gen/testFile.js +356 -0
  31. package/build/bdd-framework/gen/testNode.js +48 -0
  32. package/build/bdd-framework/gen/testPoms.js +123 -0
  33. package/build/bdd-framework/index.js +45 -0
  34. package/build/bdd-framework/playwright/fixtureParameterNames.js +77 -0
  35. package/build/bdd-framework/playwright/getLocationInFile.js +46 -0
  36. package/build/bdd-framework/playwright/loadConfig.js +42 -0
  37. package/build/bdd-framework/playwright/testTypeImpl.js +41 -0
  38. package/build/bdd-framework/playwright/transform.js +80 -0
  39. package/build/bdd-framework/playwright/types.js +5 -0
  40. package/build/bdd-framework/playwright/utils.js +34 -0
  41. package/build/bdd-framework/run/bddFixtures.js +108 -0
  42. package/build/bdd-framework/run/bddWorld.js +87 -0
  43. package/build/bdd-framework/snippets/index.js +131 -0
  44. package/build/bdd-framework/snippets/snippetSyntax.js +41 -0
  45. package/build/bdd-framework/snippets/snippetSyntaxDecorators.js +26 -0
  46. package/build/bdd-framework/snippets/snippetSyntaxTs.js +18 -0
  47. package/build/bdd-framework/stepDefinitions/createBdd.js +49 -0
  48. package/build/bdd-framework/stepDefinitions/createDecorators.js +109 -0
  49. package/build/bdd-framework/stepDefinitions/decorators/poms.js +50 -0
  50. package/build/bdd-framework/stepDefinitions/decorators/steps.js +94 -0
  51. package/build/bdd-framework/stepDefinitions/defineStep.js +61 -0
  52. package/build/bdd-framework/stepDefinitions/stepConfig.js +24 -0
  53. package/build/bdd-framework/utils/index.js +50 -0
  54. package/build/bdd-framework/utils/jsStringWrap.js +44 -0
  55. package/build/bdd-framework/utils/logger.js +29 -0
  56. package/build/core/jest/preprocessor/jsPreprocessor.js +13 -0
  57. package/{src → build}/core/jest/runner/jest-runner.js +46 -44
  58. package/build/core/jest/setup/index.js +9 -0
  59. package/build/core/playwright/codegen.js +55 -0
  60. package/build/core/playwright/custom-commands.js +8 -0
  61. package/build/core/playwright/env-initializer.js +21 -0
  62. package/{src → build}/core/playwright/index.js +112 -82
  63. package/build/core/playwright/readConfigFile.js +69 -0
  64. package/build/core/playwright/report-generator.js +41 -0
  65. package/build/core/playwright/setup/config-creator.js +117 -0
  66. package/build/core/playwright/test-runner.js +132 -0
  67. package/build/decorators.d.ts +1 -0
  68. package/build/decorators.js +16 -0
  69. package/build/index.d.ts +5 -0
  70. package/build/index.js +59 -0
  71. package/build/lib/cli.js +54 -0
  72. package/build/lib/post-install.js +17 -0
  73. package/build/lint/index.js +4 -0
  74. package/build/parser/parser.js +206 -0
  75. package/build/parser/sample.feature +34 -0
  76. package/build/parser/sample.spec.js +37 -0
  77. package/build/parser/verifier.js +130 -0
  78. package/build/setup-folder-structure/samples/auth-setup-sample.js +72 -0
  79. package/build/setup-folder-structure/samples/authUsers-sample.json +9 -0
  80. package/build/setup-folder-structure/samples/env-config-sample.json +21 -0
  81. package/build/setup-folder-structure/samples/git-ignore.sample.js +33 -0
  82. package/build/setup-folder-structure/samples/uat-config-sample.js +35 -0
  83. package/build/setup-folder-structure/setupProject.js +100 -0
  84. package/{src → build}/utils/cliArgsToObject.js +65 -63
  85. package/build/utils/fileUtils.js +53 -0
  86. package/build/utils/getFilePath.js +11 -0
  87. package/build/utils/logger.js +58 -0
  88. package/build/utils/rootPath.js +46 -0
  89. package/build/utils/stepDefinitionsFormatter.js +12 -0
  90. package/jest.config.js +63 -63
  91. package/npm-shrinkwrap.json +8790 -5772
  92. package/package.json +51 -30
  93. package/playwright.config.js +112 -112
  94. package/src/core/jest/preprocessor/jsPreprocessor.js +0 -9
  95. package/src/core/jest/setup/index.js +0 -165
  96. package/src/core/playwright/codegen.js +0 -60
  97. package/src/core/playwright/custom-commands.js +0 -3
  98. package/src/core/playwright/env-initializer.js +0 -24
  99. package/src/core/playwright/readConfigFile.js +0 -63
  100. package/src/core/playwright/report-generator.js +0 -45
  101. package/src/core/playwright/setup/config-creator.js +0 -77
  102. package/src/core/playwright/test-runner.js +0 -67
  103. package/src/index.js +0 -9
  104. package/src/lib/cli.js +0 -42
  105. package/src/setup-folder-structure/env-config-sample.json +0 -17
  106. package/src/setup-folder-structure/setupProject.js +0 -99
  107. package/src/setup-folder-structure/uat-config-sample.js +0 -22
  108. package/src/setup-folder-structure/user-example.json +0 -3
  109. package/src/utils/getFilePath.js +0 -9
  110. package/src/utils/logger.js +0 -28
  111. package/src/utils/rootPath.js +0 -51
@@ -0,0 +1,356 @@
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
+ /**
20
+ * Generate test code.
21
+ */
22
+
23
+ class TestFile {
24
+ options;
25
+ lines = [];
26
+ i18nKeywordsMap;
27
+ formatter;
28
+ testNodes = [];
29
+ hasCustomTest = false;
30
+ undefinedSteps = [];
31
+ constructor(options) {
32
+ this.options = options;
33
+ this.formatter = new _formatter.Formatter(options.config);
34
+ }
35
+ get sourceFile() {
36
+ const {
37
+ uri
38
+ } = this.options.doc;
39
+ if (!uri) throw new Error(`Document without uri`);
40
+ return uri;
41
+ }
42
+ get content() {
43
+ return this.lines.join('\n');
44
+ }
45
+ get language() {
46
+ var _this$options$doc$fea;
47
+ return ((_this$options$doc$fea = this.options.doc.feature) === null || _this$options$doc$fea === void 0 ? void 0 : _this$options$doc$fea.language) || 'en';
48
+ }
49
+ get config() {
50
+ return this.options.config;
51
+ }
52
+ get outputPath() {
53
+ return this.options.outputPath;
54
+ }
55
+ build() {
56
+ this.loadI18nKeywords();
57
+ this.lines = [...this.getFileHeader(), ...this.getRootSuite(), ...this.getFileFixtures()];
58
+ return this;
59
+ }
60
+ save() {
61
+ const dir = _path.default.dirname(this.outputPath);
62
+ if (!_fs.default.existsSync(dir)) _fs.default.mkdirSync(dir, {
63
+ recursive: true
64
+ });
65
+ _fs.default.writeFileSync(this.outputPath, this.content);
66
+ }
67
+ getFileHeader() {
68
+ const importTestFrom = this.getRelativeImportTestFrom();
69
+ return this.formatter.fileHeader(this.sourceFile, importTestFrom);
70
+ }
71
+ loadI18nKeywords() {
72
+ if (this.language !== 'en') {
73
+ this.i18nKeywordsMap = (0, _i18n.getKeywordsMap)(this.language);
74
+ }
75
+ }
76
+ getRelativeImportTestFrom() {
77
+ const {
78
+ importTestFrom
79
+ } = this.config;
80
+ if (!importTestFrom) return;
81
+ const {
82
+ file,
83
+ varName
84
+ } = importTestFrom;
85
+ const dir = _path.default.dirname(this.outputPath);
86
+ return {
87
+ file: _path.default.relative(dir, file),
88
+ varName
89
+ };
90
+ }
91
+ getFileFixtures() {
92
+ return this.formatter.useFixtures([...this.formatter.testFixture(), ...this.formatter.tagsFixture(this.testNodes)]);
93
+ }
94
+ getRootSuite() {
95
+ const {
96
+ feature
97
+ } = this.options.doc;
98
+ if (!feature) throw new Error(`Document without feature.`);
99
+ return this.getSuite(feature);
100
+ }
101
+ /**
102
+ * Generate test.describe suite for root Feature or Rule
103
+ */
104
+ getSuite(feature, parent) {
105
+ const node = new _testNode.TestNode(feature, parent);
106
+ const lines = [];
107
+ // const { backgrounds, rules, scenarios } =
108
+ // bgFixtures, bgTags - used as fixture hints for decorator steps
109
+ feature.children.forEach(child => lines.push(...this.getSuiteChild(child, node)));
110
+ return this.formatter.suite(node, lines);
111
+ }
112
+ getSuiteChild(child, parent) {
113
+ if ('rule' in child && child.rule) return this.getSuite(child.rule, parent);
114
+ if (child.background) return this.getBeforeEach(child.background, parent);
115
+ if (child.scenario) return this.getScenarioLines(child.scenario, parent);
116
+ throw new Error(`Empty child: ${JSON.stringify(child)}`);
117
+ }
118
+ getScenarioLines(scenario, parent) {
119
+ return isOutline(scenario) ? this.getOutlineSuite(scenario, parent) : this.getTest(scenario, parent);
120
+ }
121
+ /**
122
+ * Generate test.beforeEach for Background
123
+ */
124
+ getBeforeEach(bg, parent) {
125
+ const node = new _testNode.TestNode({
126
+ name: 'background',
127
+ tags: []
128
+ }, parent);
129
+ const {
130
+ fixtures,
131
+ lines
132
+ } = this.getSteps(bg, node.tags);
133
+ return this.formatter.beforeEach(fixtures, lines);
134
+ }
135
+ /**
136
+ * Generate test.describe suite for Scenario Outline
137
+ */
138
+ getOutlineSuite(scenario, parent) {
139
+ const node = new _testNode.TestNode(scenario, parent);
140
+ const lines = [];
141
+ let exampleIndex = 0;
142
+ scenario.examples.forEach(examples => {
143
+ const titleFormat = this.getExamplesTitleFormat(examples);
144
+ examples.tableBody.forEach(exampleRow => {
145
+ const testTitle = this.getOutlineTestTitle(titleFormat, examples, exampleRow, ++exampleIndex);
146
+ const testLines = this.getOutlineTest(scenario, examples, exampleRow, testTitle, node);
147
+ lines.push(...testLines);
148
+ });
149
+ });
150
+ return this.formatter.suite(node, lines);
151
+ }
152
+ /**
153
+ * Generate test from Examples row of Scenario Outline
154
+ */
155
+ // eslint-disable-next-line max-params
156
+ getOutlineTest(scenario, examples, exampleRow, title, parent) {
157
+ const node = new _testNode.TestNode({
158
+ name: title,
159
+ tags: examples.tags
160
+ }, parent);
161
+ if (this.skipByTagsExpression(node)) return [];
162
+ this.testNodes.push(node);
163
+ const {
164
+ fixtures,
165
+ lines
166
+ } = this.getSteps(scenario, node.tags, exampleRow.id);
167
+ return this.formatter.test(node, fixtures, lines);
168
+ }
169
+ /**
170
+ * Generate test from Scenario
171
+ */
172
+ getTest(scenario, parent) {
173
+ const node = new _testNode.TestNode(scenario, parent);
174
+ if (this.skipByTagsExpression(node)) return [];
175
+ this.testNodes.push(node);
176
+ const {
177
+ fixtures,
178
+ lines
179
+ } = this.getSteps(scenario, node.tags);
180
+ return this.formatter.test(node, fixtures, lines);
181
+ }
182
+ /**
183
+ * Generate test steps
184
+ */
185
+ getSteps(scenario, tags, outlineExampleRowId) {
186
+ const testFixtureNames = new Set();
187
+ const testPoms = new _testPoms.TestPoms(scenario.name || 'Background');
188
+ const decoratorSteps = [];
189
+ let previousKeywordType = undefined;
190
+ const lines = scenario.steps.map((step, index) => {
191
+ const {
192
+ keyword,
193
+ keywordType,
194
+ fixtureNames: stepFixtureNames,
195
+ line,
196
+ pickleStep,
197
+ stepConfig
198
+ } = this.getStep(step, previousKeywordType, outlineExampleRowId);
199
+ previousKeywordType = keywordType;
200
+ testFixtureNames.add(keyword);
201
+ stepFixtureNames.forEach(fixtureName => testFixtureNames.add(fixtureName));
202
+ if ((0, _stepConfig.isDecorator)(stepConfig)) {
203
+ testPoms.addByStep(stepConfig.pomNode);
204
+ decoratorSteps.push({
205
+ index,
206
+ keyword,
207
+ pickleStep,
208
+ pomNode: stepConfig.pomNode
209
+ });
210
+ }
211
+ return line;
212
+ });
213
+ // decorator steps handled in second pass to guess fixtures
214
+ if (decoratorSteps.length) {
215
+ testFixtureNames.forEach(fixtureName => testPoms.addByFixtureName(fixtureName));
216
+ tags === null || tags === void 0 || tags.forEach(tag => testPoms.addByTag(tag));
217
+ testPoms.resolveFixtures();
218
+ decoratorSteps.forEach(step => {
219
+ const {
220
+ line,
221
+ fixtureName
222
+ } = this.getDecoratorStep(step, testPoms);
223
+ lines[step.index] = line;
224
+ testFixtureNames.add(fixtureName);
225
+ });
226
+ }
227
+ return {
228
+ fixtures: testFixtureNames,
229
+ lines
230
+ };
231
+ }
232
+ /**
233
+ * Generate step for Given, When, Then
234
+ */
235
+ // eslint-disable-next-line max-statements, complexity
236
+ getStep(step, previousKeywordType, outlineExampleRowId) {
237
+ const pickleStep = this.getPickleStep(step, outlineExampleRowId);
238
+ const stepDefinition = (0, _loadSteps.findStepDefinition)(this.options.supportCodeLibrary, pickleStep.text, this.sourceFile);
239
+ const keywordType = (0, _index.getStepKeywordType)({
240
+ keyword: step.keyword,
241
+ language: this.language,
242
+ previousKeywordType
243
+ });
244
+ let keyword = this.getStepKeyword(step);
245
+ if (!stepDefinition) {
246
+ this.undefinedSteps.push({
247
+ keywordType,
248
+ step,
249
+ pickleStep
250
+ });
251
+ return this.getMissingStep(keyword, keywordType, pickleStep);
252
+ }
253
+ // for cucumber-style stepConfig is undefined
254
+ const stepConfig = (0, _stepConfig.getStepConfig)(stepDefinition);
255
+ if (stepConfig !== null && stepConfig !== void 0 && stepConfig.hasCustomTest) this.hasCustomTest = true;
256
+ // for cucumber-style transform Given/When/Then -> Given_/When_/Then_
257
+ // to use own bddWorld (containing PW built-in fixtures)
258
+ if (!(0, _stepConfig.isPlaywrightStyle)(stepConfig)) keyword = `${keyword}_`;
259
+ // for decorator steps fixtureNames are defined later in second pass
260
+ const fixtureNames = (0, _stepConfig.isDecorator)(stepConfig) ? [] : (0, _createBdd.extractFixtureNames)(stepConfig === null || stepConfig === void 0 ? void 0 : stepConfig.fn);
261
+ const line = (0, _stepConfig.isDecorator)(stepConfig) ? '' : this.formatter.step(keyword, pickleStep.text, pickleStep.argument, fixtureNames);
262
+ return {
263
+ keyword,
264
+ keywordType,
265
+ fixtureNames,
266
+ line,
267
+ pickleStep,
268
+ stepConfig
269
+ };
270
+ }
271
+ getMissingStep(keyword, keywordType, pickleStep) {
272
+ return {
273
+ keyword,
274
+ keywordType,
275
+ fixtureNames: [],
276
+ line: this.formatter.missingStep(keyword, pickleStep.text),
277
+ pickleStep,
278
+ stepConfig: undefined
279
+ };
280
+ }
281
+ getPickleStep(step, outlineExampleRowId) {
282
+ for (const pickle of this.options.pickles) {
283
+ const pickleStep = pickle.steps.find(({
284
+ astNodeIds
285
+ }) => {
286
+ const hasStepId = astNodeIds.includes(step.id);
287
+ const hasRowId = !outlineExampleRowId || astNodeIds.includes(outlineExampleRowId);
288
+ return hasStepId && hasRowId;
289
+ });
290
+ if (pickleStep) return pickleStep;
291
+ }
292
+ throw new Error(`Pickle step not found for step: ${step.text}`);
293
+ }
294
+ getStepKeyword(step) {
295
+ const origKeyword = step.keyword.trim();
296
+ let enKeyword;
297
+ if (origKeyword === '*') {
298
+ enKeyword = 'And';
299
+ } else {
300
+ enKeyword = this.i18nKeywordsMap ? this.i18nKeywordsMap.get(origKeyword) : origKeyword;
301
+ }
302
+ if (!enKeyword) throw new Error(`Keyword not found: ${origKeyword}`);
303
+ return enKeyword;
304
+ }
305
+ getDecoratorStep(step, testPoms) {
306
+ const {
307
+ keyword,
308
+ pickleStep,
309
+ pomNode
310
+ } = step;
311
+ const resolvedFixtures = testPoms.getResolvedFixtures(pomNode);
312
+ if (resolvedFixtures.length !== 1) {
313
+ const suggestedTags = resolvedFixtures.filter(f => !f.byTag).map(f => (0, _testPoms.buildFixtureTag)(f.name)).join(', ');
314
+ const suggestedTagsStr = suggestedTags.length ? ` or set one of the following tags: ${suggestedTags}` : '.';
315
+ (0, _utils.exitWithMessage)(`Can't guess fixture for decorator step "${pickleStep.text}" in file: ${this.sourceFile}.`, `Please refactor your Page Object classes${suggestedTagsStr}`);
316
+ }
317
+ const fixtureName = resolvedFixtures[0].name;
318
+ return {
319
+ fixtureName,
320
+ line: this.formatter.step(keyword, pickleStep.text, pickleStep.argument, [fixtureName])
321
+ };
322
+ }
323
+ getOutlineTestTitle(titleFormat, examples, exampleRow, exampleIndex) {
324
+ const params = {
325
+ _index_: exampleIndex
326
+ };
327
+ exampleRow.cells.forEach((cell, index) => {
328
+ var _examples$tableHeader;
329
+ 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;
330
+ if (colName) params[colName] = cell.value;
331
+ });
332
+ return (0, _utils.template)(titleFormat, params);
333
+ }
334
+ getExamplesTitleFormat(examples) {
335
+ var _comment$text;
336
+ const {
337
+ line
338
+ } = examples.location;
339
+ const titleFormatCommentLine = line - 1;
340
+ const comment = this.options.doc.comments.find(c => {
341
+ return c.location.line === titleFormatCommentLine;
342
+ });
343
+ const commentText = comment === null || comment === void 0 || (_comment$text = comment.text) === null || _comment$text === void 0 ? void 0 : _comment$text.trim();
344
+ const prefix = '# title-format:';
345
+ return commentText !== null && commentText !== void 0 && commentText.startsWith(prefix) ? commentText.replace(prefix, '').trim() : this.config.examplesTitleFormat;
346
+ }
347
+ skipByTagsExpression(node) {
348
+ var _this$options$tagsExp;
349
+ // see: https://github.com/cucumber/tag-expressions/tree/main/javascript
350
+ return ((_this$options$tagsExp = this.options.tagsExpression) === null || _this$options$tagsExp === void 0 ? void 0 : _this$options$tagsExp.evaluate(node.tags)) === false;
351
+ }
352
+ }
353
+ exports.TestFile = TestFile;
354
+ function isOutline(scenario) {
355
+ return scenario.keyword === 'Scenario Outline' || scenario.keyword === 'Scenario Template';
356
+ }
@@ -0,0 +1,48 @@
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
+ }
@@ -0,0 +1,123 @@
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 _utils = require("../utils");
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, _utils.exitWithMessage)(`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
+ }
@@ -0,0 +1,45 @@
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");
@@ -0,0 +1,77 @@
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
+ }
@@ -0,0 +1,46 @@
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
+ }