@zohodesk/testinglibrary 0.1.8-stb-bdd-v26 → 0.1.9-exp-actors

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