@zohodesk/testinglibrary 0.0.4 → 0.0.5-exp.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.
Files changed (88) hide show
  1. package/.babelrc +6 -0
  2. package/bin/cli.js +1 -1
  3. package/bin/postinstall.js +1 -16
  4. package/build/bdd-framework/cli/commands/env.js +44 -0
  5. package/build/bdd-framework/cli/commands/export.js +95 -0
  6. package/build/bdd-framework/cli/commands/test.js +98 -0
  7. package/build/bdd-framework/cli/index.js +11 -0
  8. package/build/bdd-framework/cli/options.js +21 -0
  9. package/build/bdd-framework/cli/worker.js +27 -0
  10. package/build/bdd-framework/config/dir.js +27 -0
  11. package/build/bdd-framework/config/env.js +49 -0
  12. package/build/bdd-framework/config/index.js +91 -0
  13. package/build/bdd-framework/cucumber/buildStepDefinition.js +44 -0
  14. package/build/bdd-framework/cucumber/gherkin.d.ts +45 -0
  15. package/build/bdd-framework/cucumber/loadConfig.js +32 -0
  16. package/build/bdd-framework/cucumber/loadFeatures.js +55 -0
  17. package/build/bdd-framework/cucumber/loadSnippetBuilder.js +33 -0
  18. package/build/bdd-framework/cucumber/loadSources.js +89 -0
  19. package/build/bdd-framework/cucumber/loadSteps.js +66 -0
  20. package/build/bdd-framework/decorators.js +21 -0
  21. package/build/bdd-framework/gen/formatter.js +124 -0
  22. package/build/bdd-framework/gen/i18n.js +46 -0
  23. package/build/bdd-framework/gen/index.js +322 -0
  24. package/build/bdd-framework/gen/poms.js +68 -0
  25. package/build/bdd-framework/gen/testFile.js +422 -0
  26. package/build/bdd-framework/gen/testNode.js +64 -0
  27. package/build/bdd-framework/index.js +33 -0
  28. package/build/bdd-framework/playwright/fixtureParameterNames.js +109 -0
  29. package/build/bdd-framework/playwright/getLocationInFile.js +51 -0
  30. package/build/bdd-framework/playwright/loadConfig.js +56 -0
  31. package/build/bdd-framework/playwright/testTypeImpl.js +48 -0
  32. package/build/bdd-framework/playwright/transform.js +86 -0
  33. package/build/bdd-framework/playwright/utils.js +25 -0
  34. package/build/bdd-framework/run/bddFixtures.js +166 -0
  35. package/build/bdd-framework/run/bddWorld.js +166 -0
  36. package/build/bdd-framework/snippets/index.js +184 -0
  37. package/build/bdd-framework/snippets/snippetSyntax.js +61 -0
  38. package/build/bdd-framework/snippets/snippetSyntaxDecorators.js +42 -0
  39. package/build/bdd-framework/snippets/snippetSyntaxTs.js +37 -0
  40. package/build/bdd-framework/stepDefinitions/createBdd.js +54 -0
  41. package/build/bdd-framework/stepDefinitions/createDecorators.js +123 -0
  42. package/build/bdd-framework/stepDefinitions/defineStep.js +64 -0
  43. package/build/bdd-framework/utils/index.js +59 -0
  44. package/build/bdd-framework/utils/jsStringWrap.js +45 -0
  45. package/build/bdd-framework/utils/logger.js +23 -0
  46. package/build/core/jest/preprocessor/jsPreprocessor.js +13 -0
  47. package/{src → build}/core/jest/runner/jest-runner.js +18 -17
  48. package/build/core/jest/setup/index.js +9 -0
  49. package/build/core/playwright/codegen.js +56 -0
  50. package/build/core/playwright/custom-commands.js +8 -0
  51. package/build/core/playwright/env-initializer.js +22 -0
  52. package/build/core/playwright/index.js +117 -0
  53. package/build/core/playwright/readConfigFile.js +61 -0
  54. package/build/core/playwright/report-generator.js +43 -0
  55. package/build/core/playwright/setup/config-creator.js +107 -0
  56. package/build/core/playwright/test-runner.js +102 -0
  57. package/build/index.js +37 -0
  58. package/build/lib/cli.js +47 -0
  59. package/build/lib/post-install.js +17 -0
  60. package/build/lint/index.js +6 -0
  61. package/build/setup-folder-structure/env-config-sample.json +17 -0
  62. package/build/setup-folder-structure/setupProject.js +102 -0
  63. package/build/setup-folder-structure/uat-config-sample.js +27 -0
  64. package/build/setup-folder-structure/user-example.json +3 -0
  65. package/build/utils/cliArgsToObject.js +64 -0
  66. package/build/utils/getFilePath.js +11 -0
  67. package/build/utils/logger.js +66 -0
  68. package/build/utils/rootPath.js +46 -0
  69. package/changelog.md +14 -0
  70. package/npm-shrinkwrap.json +2097 -147
  71. package/package.json +18 -4
  72. package/playwright.config.js +1 -1
  73. package/src/core/jest/preprocessor/jsPreprocessor.js +0 -9
  74. package/src/core/jest/setup/index.js +0 -165
  75. package/src/core/playwright/codegen.js +0 -60
  76. package/src/core/playwright/custom-commands.js +0 -3
  77. package/src/core/playwright/env-initializer.js +0 -24
  78. package/src/core/playwright/index.js +0 -82
  79. package/src/core/playwright/readConfigFile.js +0 -30
  80. package/src/core/playwright/report-generator.js +0 -43
  81. package/src/core/playwright/setup/config-creator.js +0 -77
  82. package/src/core/playwright/test-runner.js +0 -64
  83. package/src/index.js +0 -9
  84. package/src/lib/cli.js +0 -35
  85. package/src/utils/cliArgsToObject.js +0 -35
  86. package/src/utils/getFilePath.js +0 -9
  87. package/src/utils/logger.js +0 -28
  88. package/src/utils/rootPath.js +0 -51
@@ -0,0 +1,422 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.TestFile = void 0;
8
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
10
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
11
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
12
+ var _fs = _interopRequireDefault(require("fs"));
13
+ var _path = _interopRequireDefault(require("path"));
14
+ var _formatter = require("./formatter");
15
+ var _i18n = require("./i18n");
16
+ var _loadSteps = require("../cucumber/loadSteps");
17
+ var _createBdd = require("../stepDefinitions/createBdd");
18
+ var _index = require("@cucumber/cucumber/lib/formatter/helpers/index");
19
+ var _utils = require("../utils");
20
+ var _defineStep = require("../stepDefinitions/defineStep");
21
+ var _poms = require("./poms");
22
+ var _testNode = require("./testNode");
23
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
24
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
25
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } /**
26
+ * Generate test code.
27
+ */ /* eslint-disable max-lines, max-params */
28
+ var TestFile = /*#__PURE__*/function () {
29
+ function TestFile(options) {
30
+ (0, _classCallCheck2["default"])(this, TestFile);
31
+ (0, _defineProperty2["default"])(this, "lines", []);
32
+ (0, _defineProperty2["default"])(this, "i18nKeywordsMap", void 0);
33
+ (0, _defineProperty2["default"])(this, "formatter", void 0);
34
+ (0, _defineProperty2["default"])(this, "testNodes", []);
35
+ (0, _defineProperty2["default"])(this, "hasCustomTest", false);
36
+ (0, _defineProperty2["default"])(this, "undefinedSteps", []);
37
+ this.options = options;
38
+ this.formatter = new _formatter.Formatter(options.config);
39
+ }
40
+ (0, _createClass2["default"])(TestFile, [{
41
+ key: "sourceFile",
42
+ get: function get() {
43
+ var uri = this.options.doc.uri;
44
+ if (!uri) throw new Error("Document without uri");
45
+ return uri;
46
+ }
47
+ }, {
48
+ key: "content",
49
+ get: function get() {
50
+ return this.lines.join('\n');
51
+ }
52
+ }, {
53
+ key: "language",
54
+ get: function get() {
55
+ var _this$options$doc$fea;
56
+ return ((_this$options$doc$fea = this.options.doc.feature) === null || _this$options$doc$fea === void 0 ? void 0 : _this$options$doc$fea.language) || 'en';
57
+ }
58
+ }, {
59
+ key: "config",
60
+ get: function get() {
61
+ return this.options.config;
62
+ }
63
+ }, {
64
+ key: "outputPath",
65
+ get: function get() {
66
+ return this.options.outputPath;
67
+ }
68
+ }, {
69
+ key: "build",
70
+ value: function build() {
71
+ this.loadI18nKeywords();
72
+ this.lines = [].concat((0, _toConsumableArray2["default"])(this.getFileHeader()), (0, _toConsumableArray2["default"])(this.getRootSuite()), (0, _toConsumableArray2["default"])(this.getFileFixtures()));
73
+ return this;
74
+ }
75
+ }, {
76
+ key: "save",
77
+ value: function save() {
78
+ var dir = _path["default"].dirname(this.outputPath);
79
+ if (!_fs["default"].existsSync(dir)) _fs["default"].mkdirSync(dir, {
80
+ recursive: true
81
+ });
82
+ _fs["default"].writeFileSync(this.outputPath, this.content);
83
+ }
84
+ }, {
85
+ key: "getFileHeader",
86
+ value: function getFileHeader() {
87
+ var importTestFrom = this.getRelativeImportTestFrom();
88
+ return this.formatter.fileHeader(this.sourceFile, importTestFrom);
89
+ }
90
+ }, {
91
+ key: "loadI18nKeywords",
92
+ value: function loadI18nKeywords() {
93
+ if (this.language !== 'en') {
94
+ this.i18nKeywordsMap = (0, _i18n.getKeywordsMap)(this.language);
95
+ }
96
+ }
97
+ }, {
98
+ key: "getRelativeImportTestFrom",
99
+ value: function getRelativeImportTestFrom() {
100
+ var importTestFrom = this.config.importTestFrom;
101
+ if (!importTestFrom) return;
102
+ var file = importTestFrom.file,
103
+ varName = importTestFrom.varName;
104
+ var dir = _path["default"].dirname(this.outputPath);
105
+ return {
106
+ file: _path["default"].relative(dir, file),
107
+ varName: varName
108
+ };
109
+ }
110
+ }, {
111
+ key: "getFileFixtures",
112
+ value: function getFileFixtures() {
113
+ return this.formatter.useFixtures([].concat((0, _toConsumableArray2["default"])(this.formatter.testFixture()), (0, _toConsumableArray2["default"])(this.formatter.tagsFixture(this.testNodes))));
114
+ }
115
+ }, {
116
+ key: "getRootSuite",
117
+ value: function getRootSuite() {
118
+ var feature = this.options.doc.feature;
119
+ if (!feature) throw new Error("Document without feature.");
120
+ return this.getSuite(feature);
121
+ }
122
+
123
+ /**
124
+ * Generate test.describe suite for root Feature or Rule
125
+ */
126
+ }, {
127
+ key: "getSuite",
128
+ value: function getSuite(feature, parent) {
129
+ var _this = this;
130
+ var node = new _testNode.TestNode(feature, parent);
131
+ var lines = [];
132
+ feature.children.forEach(function (child) {
133
+ return lines.push.apply(lines, (0, _toConsumableArray2["default"])(_this.getSuiteChild(child, node)));
134
+ });
135
+ return this.formatter.suite(node, lines);
136
+ }
137
+ }, {
138
+ key: "getSuiteChild",
139
+ value: function getSuiteChild(child, parent) {
140
+ if ('rule' in child && child.rule) return this.getSuite(child.rule, parent);
141
+ if (child.background) return this.getBeforeEach(child.background);
142
+ if (child.scenario) return this.getScenarioLines(child.scenario, parent);
143
+ throw new Error("Empty child: ".concat(JSON.stringify(child)));
144
+ }
145
+ }, {
146
+ key: "getScenarioLines",
147
+ value: function getScenarioLines(scenario, parent) {
148
+ return isOutline(scenario) ? this.getOutlineSuite(scenario, parent) : this.getTest(scenario, parent);
149
+ }
150
+
151
+ /**
152
+ * Generate test.beforeEach for Background
153
+ */
154
+ }, {
155
+ key: "getBeforeEach",
156
+ value: function getBeforeEach(bg) {
157
+ var _this$getSteps = this.getSteps(bg),
158
+ fixtures = _this$getSteps.fixtures,
159
+ lines = _this$getSteps.lines;
160
+ return this.formatter.beforeEach(fixtures, lines);
161
+ }
162
+
163
+ /**
164
+ * Generate test.describe suite for Scenario Outline
165
+ */
166
+ }, {
167
+ key: "getOutlineSuite",
168
+ value: function getOutlineSuite(scenario, parent) {
169
+ var _this2 = this;
170
+ var node = new _testNode.TestNode(scenario, parent);
171
+ var lines = [];
172
+ var exampleIndex = 0;
173
+ scenario.examples.forEach(function (examples) {
174
+ var titleFormat = _this2.getExamplesTitleFormat(examples);
175
+ examples.tableBody.forEach(function (exampleRow) {
176
+ var testTitle = _this2.getOutlineTestTitle(titleFormat, examples, exampleRow, ++exampleIndex);
177
+ var testLines = _this2.getOutlineTest(scenario, examples, exampleRow, testTitle, node);
178
+ lines.push.apply(lines, (0, _toConsumableArray2["default"])(testLines));
179
+ });
180
+ });
181
+ return this.formatter.suite(node, lines);
182
+ }
183
+
184
+ /**
185
+ * Generate test from Examples row of Scenario Outline
186
+ */
187
+ // eslint-disable-next-line max-params
188
+ }, {
189
+ key: "getOutlineTest",
190
+ value: function getOutlineTest(scenario, examples, exampleRow, title, parent) {
191
+ var node = new _testNode.TestNode({
192
+ name: title,
193
+ tags: examples.tags
194
+ }, parent);
195
+ if (this.skipByTagsExpression(node)) return [];
196
+ this.testNodes.push(node);
197
+ var _this$getSteps2 = this.getSteps(scenario, node.ownTags, exampleRow.id),
198
+ fixtures = _this$getSteps2.fixtures,
199
+ lines = _this$getSteps2.lines;
200
+ return this.formatter.test(node, fixtures, lines);
201
+ }
202
+
203
+ /**
204
+ * Generate test from Scenario
205
+ */
206
+ }, {
207
+ key: "getTest",
208
+ value: function getTest(scenario, parent) {
209
+ var node = new _testNode.TestNode(scenario, parent);
210
+ if (this.skipByTagsExpression(node)) return [];
211
+ this.testNodes.push(node);
212
+ var _this$getSteps3 = this.getSteps(scenario, node.ownTags),
213
+ fixtures = _this$getSteps3.fixtures,
214
+ lines = _this$getSteps3.lines;
215
+ return this.formatter.test(node, fixtures, lines);
216
+ }
217
+
218
+ /**
219
+ * Generate test steps
220
+ */
221
+ }, {
222
+ key: "getSteps",
223
+ value: function getSteps(scenario, ownTestTags, outlineExampleRowId) {
224
+ var _this3 = this;
225
+ var testFixtureNames = new Set();
226
+ var usedPoms = new _poms.POMS();
227
+ var decoratorSteps = [];
228
+ var previousKeywordType = undefined;
229
+ var lines = scenario.steps.map(function (step, index) {
230
+ var _this3$getStep = _this3.getStep(step, previousKeywordType, outlineExampleRowId),
231
+ keyword = _this3$getStep.keyword,
232
+ keywordType = _this3$getStep.keywordType,
233
+ stepFixtureNames = _this3$getStep.fixtureNames,
234
+ line = _this3$getStep.line,
235
+ pickleStep = _this3$getStep.pickleStep,
236
+ stepConfig = _this3$getStep.stepConfig;
237
+ previousKeywordType = keywordType;
238
+ testFixtureNames.add(keyword);
239
+ stepFixtureNames.forEach(function (fixtureName) {
240
+ return testFixtureNames.add(fixtureName);
241
+ });
242
+ if (!line && stepConfig !== null && stepConfig !== void 0 && stepConfig.pomNode) {
243
+ usedPoms.add(stepConfig.pomNode);
244
+ decoratorSteps.push({
245
+ index: index,
246
+ keyword: keyword,
247
+ pickleStep: pickleStep,
248
+ pomNode: stepConfig.pomNode
249
+ });
250
+ }
251
+ return line;
252
+ });
253
+ if (decoratorSteps.length) {
254
+ testFixtureNames.forEach(function (fixtureName) {
255
+ return usedPoms.addByFixtureName(fixtureName);
256
+ });
257
+ ownTestTags === null || ownTestTags === void 0 || ownTestTags.forEach(function (tag) {
258
+ return usedPoms.addByTag(tag);
259
+ });
260
+ decoratorSteps.forEach(function (step) {
261
+ var _this3$getDecoratorSt = _this3.getDecoratorStep(step, usedPoms),
262
+ line = _this3$getDecoratorSt.line,
263
+ fixtureNames = _this3$getDecoratorSt.fixtureNames;
264
+ lines[step.index] = line;
265
+ fixtureNames.forEach(function (fixtureName) {
266
+ return testFixtureNames.add(fixtureName);
267
+ });
268
+ });
269
+ }
270
+ return {
271
+ fixtures: testFixtureNames,
272
+ lines: lines
273
+ };
274
+ }
275
+
276
+ /**
277
+ * Generate step for Given, When, Then
278
+ */
279
+ // eslint-disable-next-line max-statements, complexity
280
+ }, {
281
+ key: "getStep",
282
+ value: function getStep(step, previousKeywordType, outlineExampleRowId) {
283
+ var pickleStep = this.getPickleStep(step, outlineExampleRowId);
284
+ var stepDefinition = (0, _loadSteps.findStepDefinition)(this.options.supportCodeLibrary, pickleStep.text, this.sourceFile);
285
+ var keywordType = (0, _index.getStepKeywordType)({
286
+ keyword: step.keyword,
287
+ language: this.language,
288
+ previousKeywordType: previousKeywordType
289
+ });
290
+ var keyword = this.getStepKeyword(step);
291
+ if (!stepDefinition) {
292
+ this.undefinedSteps.push({
293
+ keywordType: keywordType,
294
+ step: step,
295
+ pickleStep: pickleStep
296
+ });
297
+ return this.getMissingStep(keyword, keywordType, pickleStep);
298
+ }
299
+ // for cucumber-style stepConfig is undefined
300
+ var stepConfig = (0, _defineStep.getStepConfig)(stepDefinition);
301
+ if (stepConfig !== null && stepConfig !== void 0 && stepConfig.hasCustomTest) this.hasCustomTest = true;
302
+ // for cucumber-style transform Given/When/Then -> Given_/When_/Then_
303
+ // to use fixtures with own bddWorld (containing fixtures)
304
+ if (!(0, _defineStep.isPlaywrightStyle)(stepDefinition)) keyword = "".concat(keyword, "_");
305
+ // for decorator steps fixtures defined later in second pass
306
+ var fixtureNames = stepConfig !== null && stepConfig !== void 0 && stepConfig.isDecorator ? [] : (0, _createBdd.extractFixtureNames)(stepConfig === null || stepConfig === void 0 ? void 0 : stepConfig.fn);
307
+ var line = stepConfig !== null && stepConfig !== void 0 && stepConfig.isDecorator ? '' : this.formatter.step(keyword, pickleStep.text, pickleStep.argument, fixtureNames);
308
+ return {
309
+ keyword: keyword,
310
+ keywordType: keywordType,
311
+ fixtureNames: fixtureNames,
312
+ line: line,
313
+ pickleStep: pickleStep,
314
+ stepConfig: stepConfig
315
+ };
316
+ }
317
+ }, {
318
+ key: "getMissingStep",
319
+ value: function getMissingStep(keyword, keywordType, pickleStep) {
320
+ return {
321
+ keyword: keyword,
322
+ keywordType: keywordType,
323
+ fixtureNames: [],
324
+ line: this.formatter.missingStep(keyword, pickleStep.text),
325
+ pickleStep: pickleStep,
326
+ stepConfig: undefined
327
+ };
328
+ }
329
+ }, {
330
+ key: "getPickleStep",
331
+ value: function getPickleStep(step, outlineExampleRowId) {
332
+ var _iterator = _createForOfIteratorHelper(this.options.pickles),
333
+ _step;
334
+ try {
335
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
336
+ var pickle = _step.value;
337
+ var pickleStep = pickle.steps.find(function (_ref) {
338
+ var astNodeIds = _ref.astNodeIds;
339
+ var hasStepId = astNodeIds.includes(step.id);
340
+ var hasRowId = !outlineExampleRowId || astNodeIds.includes(outlineExampleRowId);
341
+ return hasStepId && hasRowId;
342
+ });
343
+ if (pickleStep) return pickleStep;
344
+ }
345
+ } catch (err) {
346
+ _iterator.e(err);
347
+ } finally {
348
+ _iterator.f();
349
+ }
350
+ throw new Error("Pickle step not found for step: ".concat(step.text));
351
+ }
352
+ }, {
353
+ key: "getStepKeyword",
354
+ value: function getStepKeyword(step) {
355
+ var origKeyword = step.keyword.trim();
356
+ var enKeyword;
357
+ if (origKeyword === '*') {
358
+ enKeyword = 'And';
359
+ } else {
360
+ enKeyword = this.i18nKeywordsMap ? this.i18nKeywordsMap.get(origKeyword) : origKeyword;
361
+ }
362
+ if (!enKeyword) throw new Error("Keyword not found: ".concat(origKeyword));
363
+ return enKeyword;
364
+ }
365
+ }, {
366
+ key: "getDecoratorStep",
367
+ value: function getDecoratorStep(step, usedPoms) {
368
+ var keyword = step.keyword,
369
+ pickleStep = step.pickleStep,
370
+ pomNode = step.pomNode;
371
+ var fixtureNames = usedPoms.resolveFixtureNames(pomNode);
372
+ if (fixtureNames.length !== 1) {
373
+ var suggestedTags = fixtureNames.map(function (name) {
374
+ return (0, _poms.buildFixtureTag)(name);
375
+ }).join(', ');
376
+ (0, _utils.exitWithMessage)("Can't guess fixture for decorator step \"".concat(pickleStep.text, "\" in file: ").concat(this.sourceFile, "."), "Please set one of the following tags (".concat(suggestedTags, ") or refactor your Page Object classes."));
377
+ }
378
+ return {
379
+ fixtureNames: fixtureNames,
380
+ line: this.formatter.step(keyword, pickleStep.text, pickleStep.argument, [fixtureNames[0]])
381
+ };
382
+ }
383
+ }, {
384
+ key: "getOutlineTestTitle",
385
+ value: function getOutlineTestTitle(titleFormat, examples, exampleRow, exampleIndex) {
386
+ var params = {
387
+ _index_: exampleIndex
388
+ };
389
+ exampleRow.cells.forEach(function (cell, index) {
390
+ var _examples$tableHeader;
391
+ var 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;
392
+ if (colName) params[colName] = cell.value;
393
+ });
394
+ return (0, _utils.template)(titleFormat, params);
395
+ }
396
+ }, {
397
+ key: "getExamplesTitleFormat",
398
+ value: function getExamplesTitleFormat(examples) {
399
+ var _comment$text;
400
+ var line = examples.location.line;
401
+ var titleFormatCommentLine = line - 1;
402
+ var comment = this.options.doc.comments.find(function (c) {
403
+ return c.location.line === titleFormatCommentLine;
404
+ });
405
+ var commentText = comment === null || comment === void 0 || (_comment$text = comment.text) === null || _comment$text === void 0 ? void 0 : _comment$text.trim();
406
+ var prefix = '# title-format:';
407
+ return commentText !== null && commentText !== void 0 && commentText.startsWith(prefix) ? commentText.replace(prefix, '').trim() : this.config.examplesTitleFormat;
408
+ }
409
+ }, {
410
+ key: "skipByTagsExpression",
411
+ value: function skipByTagsExpression(node) {
412
+ var _this$options$tagsExp;
413
+ // see: https://github.com/cucumber/tag-expressions/tree/main/javascript
414
+ return ((_this$options$tagsExp = this.options.tagsExpression) === null || _this$options$tagsExp === void 0 ? void 0 : _this$options$tagsExp.evaluate(node.tags)) === false;
415
+ }
416
+ }]);
417
+ return TestFile;
418
+ }();
419
+ exports.TestFile = TestFile;
420
+ function isOutline(scenario) {
421
+ return scenario.keyword === 'Scenario Outline' || scenario.keyword === 'Scenario Template';
422
+ }
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.TestNode = void 0;
8
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
9
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+ var _utils = require("../utils");
12
+ /**
13
+ * Universal TestNode class with accumulated data (tags, titiles)
14
+ * of parent-child relations in test file structure.
15
+ */
16
+
17
+ var SPECIAL_TAGS = ['@only', '@skip', '@fixme'];
18
+ var TestNode = /*#__PURE__*/function () {
19
+ function TestNode(origItem, parent) {
20
+ (0, _classCallCheck2["default"])(this, TestNode);
21
+ (0, _defineProperty2["default"])(this, "title", void 0);
22
+ (0, _defineProperty2["default"])(this, "titlePath", void 0);
23
+ (0, _defineProperty2["default"])(this, "ownTags", []);
24
+ (0, _defineProperty2["default"])(this, "tags", []);
25
+ (0, _defineProperty2["default"])(this, "flags", {});
26
+ this.origItem = origItem;
27
+ this.parent = parent;
28
+ this.initOwnTags(origItem);
29
+ this.tags = (0, _utils.removeDuplicates)(((parent === null || parent === void 0 ? void 0 : parent.tags) || []).concat(this.ownTags));
30
+ this.title = origItem.name;
31
+ this.titlePath = ((parent === null || parent === void 0 ? void 0 : parent.titlePath) || []).concat([this.title]);
32
+ }
33
+ (0, _createClass2["default"])(TestNode, [{
34
+ key: "initOwnTags",
35
+ value: function initOwnTags(origItem) {
36
+ var _this = this;
37
+ var tagNames = (0, _utils.removeDuplicates)(getTagNames(origItem.tags));
38
+ tagNames.forEach(function (tag) {
39
+ if (isSpecialTag(tag)) {
40
+ _this.setFlag(tag);
41
+ } else {
42
+ _this.ownTags.push(tag);
43
+ }
44
+ });
45
+ }
46
+ }, {
47
+ key: "setFlag",
48
+ value: function setFlag(tag) {
49
+ if (tag === '@only') this.flags.only = true;
50
+ if (tag === '@skip') this.flags.skip = true;
51
+ if (tag === '@fixme') this.flags.fixme = true;
52
+ }
53
+ }]);
54
+ return TestNode;
55
+ }();
56
+ exports.TestNode = TestNode;
57
+ function getTagNames(tags) {
58
+ return tags.map(function (tag) {
59
+ return tag.name;
60
+ });
61
+ }
62
+ function isSpecialTag(tag) {
63
+ return SPECIAL_TAGS.includes(tag);
64
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "BddWorld", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _bddWorld.BddWorld;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "createBdd", {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return _createBdd.createBdd;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "defineBddConfig", {
19
+ enumerable: true,
20
+ get: function get() {
21
+ return _config.defineBddConfig;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "test", {
25
+ enumerable: true,
26
+ get: function get() {
27
+ return _bddFixtures.test;
28
+ }
29
+ });
30
+ var _config = require("./config");
31
+ var _createBdd = require("./stepDefinitions/createBdd");
32
+ var _bddFixtures = require("./run/bddFixtures");
33
+ var _bddWorld = require("./run/bddWorld");
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.fixtureParameterNames = fixtureParameterNames;
8
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
+ /**
10
+ * Extracted from playwright.
11
+ * https://github.com/microsoft/playwright/blob/main/packages/playwright-test/src/common/fixtures.ts#L226
12
+ */
13
+
14
+ /* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types */
15
+ /* eslint-disable max-statements, complexity, max-len, max-depth */
16
+
17
+ var signatureSymbol = Symbol('signature');
18
+ function fixtureParameterNames(fn) {
19
+ if (typeof fn !== 'function') {
20
+ return [];
21
+ }
22
+ ;
23
+ if (!fn[signatureSymbol]) {
24
+ fn[signatureSymbol] = innerFixtureParameterNames(fn);
25
+ }
26
+ return fn[signatureSymbol];
27
+ }
28
+ function innerFixtureParameterNames(fn) {
29
+ var text = filterOutComments(fn.toString());
30
+ var match = text.match(/(?:async)?(?:\s+function)?[^(]*\(([^)]*)/);
31
+ if (!match) {
32
+ return [];
33
+ }
34
+ ;
35
+ var trimmedParams = match[1].trim();
36
+ if (!trimmedParams) {
37
+ return [];
38
+ }
39
+ ;
40
+ var _splitByComma = splitByComma(trimmedParams),
41
+ _splitByComma2 = (0, _slicedToArray2["default"])(_splitByComma, 1),
42
+ firstParam = _splitByComma2[0];
43
+ if (firstParam[0] !== '{' || firstParam[firstParam.length - 1] !== '}') {
44
+ throw new Error('First argument must use the object destructuring pattern: ' + firstParam + ' ' + fn.toString());
45
+ }
46
+ var props = splitByComma(firstParam.substring(1, firstParam.length - 1)).map(function (prop) {
47
+ var colon = prop.indexOf(':');
48
+ return colon === -1 ? prop.trim() : prop.substring(0, colon).trim();
49
+ });
50
+ var restProperty = props.find(function (prop) {
51
+ return prop.startsWith('...');
52
+ });
53
+ if (restProperty) {
54
+ throw new Error("Rest property \"".concat(restProperty, "\" is not supported. List all used fixtures explicitly, separated by comma. ").concat(fn.toString()));
55
+ }
56
+ return props;
57
+ }
58
+ function filterOutComments(s) {
59
+ var result = [];
60
+ var commentState = 'none';
61
+ for (var i = 0; i < s.length; ++i) {
62
+ if (commentState === 'singleline') {
63
+ if (s[i] === '\n') {
64
+ commentState = 'none';
65
+ }
66
+ ;
67
+ } else if (commentState === 'multiline') {
68
+ if (s[i - 1] === '*' && s[i] === '/') {
69
+ commentState = 'none';
70
+ }
71
+ ;
72
+ } else if (commentState === 'none') {
73
+ if (s[i] === '/' && s[i + 1] === '/') {
74
+ commentState = 'singleline';
75
+ } else if (s[i] === '/' && s[i + 1] === '*') {
76
+ commentState = 'multiline';
77
+ i += 2;
78
+ } else {
79
+ result.push(s[i]);
80
+ }
81
+ }
82
+ }
83
+ return result.join('');
84
+ }
85
+ function splitByComma(s) {
86
+ var result = [];
87
+ var stack = [];
88
+ var start = 0;
89
+ for (var i = 0; i < s.length; i++) {
90
+ if (s[i] === '{' || s[i] === '[') {
91
+ stack.push(s[i] === '{' ? '}' : ']');
92
+ } else if (s[i] === stack[stack.length - 1]) {
93
+ stack.pop();
94
+ } else if (!stack.length && s[i] === ',') {
95
+ var token = s.substring(start, i).trim();
96
+ if (token) {
97
+ result.push(token);
98
+ }
99
+ ;
100
+ start = i + 1;
101
+ }
102
+ }
103
+ var lastToken = s.substring(start).trim();
104
+ if (lastToken) {
105
+ result.push(lastToken);
106
+ }
107
+ ;
108
+ return result;
109
+ }
@@ -0,0 +1,51 @@
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
+ var _requirePlaywrightMod = (0, _utils.requirePlaywrightModule)('lib/utilsBundle.js'),
17
+ sourceMapSupport = _requirePlaywrightMod.sourceMapSupport;
18
+ var oldPrepareStackTrace = Error.prepareStackTrace;
19
+ Error.prepareStackTrace = function (error, stackFrames) {
20
+ var frameInFile = stackFrames.find(function (frame) {
21
+ return frame.getFileName() === filePath;
22
+ });
23
+ if (!frameInFile) {
24
+ return {
25
+ file: '',
26
+ line: 0,
27
+ column: 0
28
+ };
29
+ }
30
+ ;
31
+ var frame = sourceMapSupport.wrapCallSite(frameInFile);
32
+ var fileName = frame.getFileName();
33
+ // Node error stacks for modules use file:// urls instead of paths.
34
+ var file = fileName && fileName.startsWith('file://') ? _url["default"].fileURLToPath(fileName) : fileName;
35
+ return {
36
+ file: file,
37
+ line: frame.getLineNumber(),
38
+ column: frame.getColumnNumber()
39
+ };
40
+ };
41
+ // commented stackTraceLImit modification, todo: check if it has perf impact
42
+ // const oldStackTraceLimit = Error.stackTraceLimit;
43
+ // Error.stackTraceLimit = level + 1;
44
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
45
+ var obj = {};
46
+ Error.captureStackTrace(obj);
47
+ var location = obj.stack;
48
+ // Error.stackTraceLimit = oldStackTraceLimit;
49
+ Error.prepareStackTrace = oldPrepareStackTrace;
50
+ return location;
51
+ }