@dev-blinq/cucumber-js 1.0.36 → 1.0.37-stage

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 (251) hide show
  1. package/bin/cucumber-js +0 -0
  2. package/bin/cucumber.js +0 -0
  3. package/bin/download-install.js +51 -10
  4. package/lib/api/console_logger.d.ts +12 -12
  5. package/lib/api/console_logger.js +23 -23
  6. package/lib/api/convert_configuration.d.ts +4 -4
  7. package/lib/api/convert_configuration.js +65 -65
  8. package/lib/api/environment.d.ts +2 -2
  9. package/lib/api/environment.js +13 -13
  10. package/lib/api/formatters.d.ts +20 -20
  11. package/lib/api/formatters.js +60 -60
  12. package/lib/api/gherkin.d.ts +21 -21
  13. package/lib/api/gherkin.js +145 -99
  14. package/lib/api/gherkin.js.map +1 -1
  15. package/lib/api/index.d.ts +12 -12
  16. package/lib/api/index.js +27 -27
  17. package/lib/api/load_configuration.d.ts +9 -9
  18. package/lib/api/load_configuration.js +40 -40
  19. package/lib/api/load_sources.d.ts +9 -9
  20. package/lib/api/load_sources.js +52 -52
  21. package/lib/api/load_support.d.ts +10 -10
  22. package/lib/api/load_support.js +29 -29
  23. package/lib/api/paths.d.ts +8 -8
  24. package/lib/api/paths.js +101 -101
  25. package/lib/api/plugins.d.ts +4 -4
  26. package/lib/api/plugins.js +18 -18
  27. package/lib/api/run_cucumber.d.ts +11 -11
  28. package/lib/api/run_cucumber.js +114 -114
  29. package/lib/api/runtime.d.ts +21 -21
  30. package/lib/api/runtime.js +35 -35
  31. package/lib/api/support.d.ts +9 -9
  32. package/lib/api/support.js +25 -25
  33. package/lib/api/test_helpers.d.ts +3 -3
  34. package/lib/api/test_helpers.js +30 -30
  35. package/lib/api/types.d.ts +177 -177
  36. package/lib/api/types.js +2 -2
  37. package/lib/cli/helpers.d.ts +39 -39
  38. package/lib/cli/helpers.js +223 -223
  39. package/lib/cli/i18n.d.ts +2 -2
  40. package/lib/cli/i18n.js +69 -69
  41. package/lib/cli/index.d.ts +21 -21
  42. package/lib/cli/index.js +63 -63
  43. package/lib/cli/install_validator.d.ts +1 -1
  44. package/lib/cli/install_validator.js +13 -13
  45. package/lib/cli/run.d.ts +1 -1
  46. package/lib/cli/run.js +43 -43
  47. package/lib/cli/validate_node_engine_version.d.ts +10 -10
  48. package/lib/cli/validate_node_engine_version.js +23 -23
  49. package/lib/configuration/argv_parser.d.ts +20 -20
  50. package/lib/configuration/argv_parser.js +102 -102
  51. package/lib/configuration/axios_client.d.ts +1 -0
  52. package/lib/configuration/axios_client.js +40 -0
  53. package/lib/configuration/axios_client.js.map +1 -0
  54. package/lib/configuration/check_schema.d.ts +2 -2
  55. package/lib/configuration/check_schema.js +59 -59
  56. package/lib/configuration/default_configuration.d.ts +2 -2
  57. package/lib/configuration/default_configuration.js +28 -28
  58. package/lib/configuration/from_file.d.ts +3 -3
  59. package/lib/configuration/from_file.js +84 -84
  60. package/lib/configuration/helpers.d.ts +1 -1
  61. package/lib/configuration/helpers.js +10 -10
  62. package/lib/configuration/index.d.ts +7 -7
  63. package/lib/configuration/index.js +28 -28
  64. package/lib/configuration/locate_file.d.ts +1 -1
  65. package/lib/configuration/locate_file.js +20 -20
  66. package/lib/configuration/merge_configurations.d.ts +2 -2
  67. package/lib/configuration/merge_configurations.js +47 -47
  68. package/lib/configuration/option_splitter.d.ts +3 -3
  69. package/lib/configuration/option_splitter.js +22 -22
  70. package/lib/configuration/types.d.ts +30 -30
  71. package/lib/configuration/types.js +2 -2
  72. package/lib/configuration/validate_configuration.d.ts +3 -3
  73. package/lib/configuration/validate_configuration.js +12 -12
  74. package/lib/filter_stack_trace.d.ts +3 -3
  75. package/lib/filter_stack_trace.js +37 -37
  76. package/lib/formatter/api.d.ts +2 -0
  77. package/lib/formatter/api.js +53 -0
  78. package/lib/formatter/api.js.map +1 -0
  79. package/lib/formatter/builder.d.ts +37 -37
  80. package/lib/formatter/builder.js +100 -100
  81. package/lib/formatter/bvt_analysis_formatter.d.ts +19 -18
  82. package/lib/formatter/bvt_analysis_formatter.js +243 -192
  83. package/lib/formatter/bvt_analysis_formatter.js.map +1 -1
  84. package/lib/formatter/feature_data_format.d.ts +23 -14
  85. package/lib/formatter/feature_data_format.js +178 -80
  86. package/lib/formatter/feature_data_format.js.map +1 -1
  87. package/lib/formatter/fixtures/typescript.d.ts +2 -2
  88. package/lib/formatter/fixtures/typescript.js +5 -5
  89. package/lib/formatter/get_color_fns.d.ts +15 -15
  90. package/lib/formatter/get_color_fns.js +55 -55
  91. package/lib/formatter/helpers/duration_helpers.d.ts +2 -2
  92. package/lib/formatter/helpers/duration_helpers.js +8 -8
  93. package/lib/formatter/helpers/event_data_collector.d.ts +30 -30
  94. package/lib/formatter/helpers/event_data_collector.js +125 -125
  95. package/lib/formatter/helpers/formatters.d.ts +6 -6
  96. package/lib/formatter/helpers/formatters.js +44 -44
  97. package/lib/formatter/helpers/gherkin_document_parser.d.ts +5 -5
  98. package/lib/formatter/helpers/gherkin_document_parser.js +65 -65
  99. package/lib/formatter/helpers/index.d.ts +10 -10
  100. package/lib/formatter/helpers/index.js +51 -51
  101. package/lib/formatter/helpers/issue_helpers.d.ts +19 -19
  102. package/lib/formatter/helpers/issue_helpers.js +58 -58
  103. package/lib/formatter/helpers/keyword_type.d.ts +11 -11
  104. package/lib/formatter/helpers/keyword_type.js +31 -31
  105. package/lib/formatter/helpers/location_helpers.d.ts +2 -2
  106. package/lib/formatter/helpers/location_helpers.js +16 -16
  107. package/lib/formatter/helpers/pickle_parser.d.ts +17 -17
  108. package/lib/formatter/helpers/pickle_parser.js +27 -27
  109. package/lib/formatter/helpers/report_generator.d.ts +135 -103
  110. package/lib/formatter/helpers/report_generator.js +433 -247
  111. package/lib/formatter/helpers/report_generator.js.map +1 -1
  112. package/lib/formatter/helpers/step_argument_formatter.d.ts +2 -2
  113. package/lib/formatter/helpers/step_argument_formatter.js +47 -47
  114. package/lib/formatter/helpers/summary_helpers.d.ts +9 -9
  115. package/lib/formatter/helpers/summary_helpers.js +95 -95
  116. package/lib/formatter/helpers/test_case_attempt_formatter.d.ts +12 -12
  117. package/lib/formatter/helpers/test_case_attempt_formatter.js +113 -113
  118. package/lib/formatter/helpers/test_case_attempt_parser.d.ts +32 -32
  119. package/lib/formatter/helpers/test_case_attempt_parser.js +134 -134
  120. package/lib/formatter/helpers/upload_serivce.d.ts +14 -9
  121. package/lib/formatter/helpers/upload_serivce.js +171 -46
  122. package/lib/formatter/helpers/upload_serivce.js.map +1 -1
  123. package/lib/formatter/helpers/uploader.d.ts +11 -11
  124. package/lib/formatter/helpers/uploader.js +130 -56
  125. package/lib/formatter/helpers/uploader.js.map +1 -1
  126. package/lib/formatter/helpers/usage_helpers/index.d.ts +23 -23
  127. package/lib/formatter/helpers/usage_helpers/index.js +110 -110
  128. package/lib/formatter/html_formatter.d.ts +7 -7
  129. package/lib/formatter/html_formatter.js +29 -29
  130. package/lib/formatter/index.d.ts +53 -53
  131. package/lib/formatter/index.js +20 -20
  132. package/lib/formatter/json_formatter.d.ts +78 -78
  133. package/lib/formatter/json_formatter.js +229 -229
  134. package/lib/formatter/junit_formatter.d.ts +17 -17
  135. package/lib/formatter/junit_formatter.js +180 -180
  136. package/lib/formatter/message_formatter.d.ts +5 -5
  137. package/lib/formatter/message_formatter.js +14 -14
  138. package/lib/formatter/progress_bar_formatter.d.ts +18 -18
  139. package/lib/formatter/progress_bar_formatter.js +98 -98
  140. package/lib/formatter/progress_formatter.d.ts +9 -9
  141. package/lib/formatter/progress_formatter.js +58 -58
  142. package/lib/formatter/rerun_formatter.d.ts +13 -13
  143. package/lib/formatter/rerun_formatter.js +79 -79
  144. package/lib/formatter/snippets_formatter.d.ts +6 -6
  145. package/lib/formatter/snippets_formatter.js +60 -60
  146. package/lib/formatter/step_definition_snippet_builder/index.d.ts +20 -20
  147. package/lib/formatter/step_definition_snippet_builder/index.js +45 -45
  148. package/lib/formatter/step_definition_snippet_builder/javascript_snippet_syntax.d.ts +7 -7
  149. package/lib/formatter/step_definition_snippet_builder/javascript_snippet_syntax.js +45 -45
  150. package/lib/formatter/step_definition_snippet_builder/snippet_syntax.d.ts +16 -16
  151. package/lib/formatter/step_definition_snippet_builder/snippet_syntax.js +10 -10
  152. package/lib/formatter/summary_formatter.d.ts +14 -14
  153. package/lib/formatter/summary_formatter.js +67 -67
  154. package/lib/formatter/usage_formatter.d.ts +6 -6
  155. package/lib/formatter/usage_formatter.js +97 -97
  156. package/lib/formatter/usage_json_formatter.d.ts +7 -7
  157. package/lib/formatter/usage_json_formatter.js +33 -33
  158. package/lib/index.d.ts +58 -58
  159. package/lib/index.js +108 -108
  160. package/lib/logger.d.ts +5 -5
  161. package/lib/logger.js +2 -2
  162. package/lib/models/data_table.d.ts +10 -10
  163. package/lib/models/data_table.js +45 -45
  164. package/lib/models/definition.d.ts +55 -55
  165. package/lib/models/definition.js +21 -21
  166. package/lib/models/gherkin_step_keyword.d.ts +1 -1
  167. package/lib/models/gherkin_step_keyword.js +2 -2
  168. package/lib/models/pickle_order.d.ts +1 -1
  169. package/lib/models/pickle_order.js +2 -2
  170. package/lib/models/step_definition.d.ts +11 -11
  171. package/lib/models/step_definition.js +36 -36
  172. package/lib/models/test_case_hook_definition.d.ts +10 -10
  173. package/lib/models/test_case_hook_definition.js +26 -26
  174. package/lib/models/test_run_hook_definition.d.ts +3 -3
  175. package/lib/models/test_run_hook_definition.js +9 -9
  176. package/lib/models/test_step_hook_definition.d.ts +9 -9
  177. package/lib/models/test_step_hook_definition.js +25 -25
  178. package/lib/pickle_filter.d.ts +42 -42
  179. package/lib/pickle_filter.js +98 -98
  180. package/lib/plugin/index.d.ts +2 -2
  181. package/lib/plugin/index.js +18 -18
  182. package/lib/plugin/plugin_manager.d.ts +13 -13
  183. package/lib/plugin/plugin_manager.js +35 -35
  184. package/lib/plugin/types.d.ts +14 -14
  185. package/lib/plugin/types.js +2 -2
  186. package/lib/publish/http_stream.d.ts +30 -30
  187. package/lib/publish/http_stream.js +111 -111
  188. package/lib/publish/index.d.ts +2 -2
  189. package/lib/publish/index.js +4 -4
  190. package/lib/publish/publish_plugin.d.ts +2 -2
  191. package/lib/publish/publish_plugin.js +47 -47
  192. package/lib/runtime/assemble_test_cases.d.ts +13 -13
  193. package/lib/runtime/assemble_test_cases.js +87 -87
  194. package/lib/runtime/attachment_manager/index.d.ts +33 -33
  195. package/lib/runtime/attachment_manager/index.js +118 -118
  196. package/lib/runtime/format_error.d.ts +2 -2
  197. package/lib/runtime/format_error.js +35 -35
  198. package/lib/runtime/helpers.d.ts +6 -6
  199. package/lib/runtime/helpers.js +100 -100
  200. package/lib/runtime/index.d.ts +40 -40
  201. package/lib/runtime/index.js +75 -75
  202. package/lib/runtime/parallel/command_types.d.ts +32 -32
  203. package/lib/runtime/parallel/command_types.js +2 -2
  204. package/lib/runtime/parallel/coordinator.d.ts +72 -72
  205. package/lib/runtime/parallel/coordinator.js +221 -221
  206. package/lib/runtime/parallel/run_worker.d.ts +1 -1
  207. package/lib/runtime/parallel/run_worker.js +28 -28
  208. package/lib/runtime/parallel/worker.d.ts +26 -26
  209. package/lib/runtime/parallel/worker.js +86 -86
  210. package/lib/runtime/run_test_run_hooks.d.ts +3 -3
  211. package/lib/runtime/run_test_run_hooks.js +27 -27
  212. package/lib/runtime/step_runner.d.ts +16 -16
  213. package/lib/runtime/step_runner.js +87 -87
  214. package/lib/runtime/stopwatch.d.ts +12 -12
  215. package/lib/runtime/stopwatch.js +33 -33
  216. package/lib/runtime/test_case_runner.d.ts +54 -54
  217. package/lib/runtime/test_case_runner.js +267 -267
  218. package/lib/step_arguments.d.ts +6 -6
  219. package/lib/step_arguments.js +18 -18
  220. package/lib/support_code_library_builder/build_parameter_type.d.ts +3 -3
  221. package/lib/support_code_library_builder/build_parameter_type.js +12 -12
  222. package/lib/support_code_library_builder/get_definition_line_and_uri.d.ts +3 -3
  223. package/lib/support_code_library_builder/get_definition_line_and_uri.js +28 -28
  224. package/lib/support_code_library_builder/index.d.ts +74 -74
  225. package/lib/support_code_library_builder/index.js +296 -296
  226. package/lib/support_code_library_builder/parallel_can_assign_helpers.d.ts +2 -2
  227. package/lib/support_code_library_builder/parallel_can_assign_helpers.js +15 -15
  228. package/lib/support_code_library_builder/sourced_parameter_type_registry.d.ts +7 -7
  229. package/lib/support_code_library_builder/sourced_parameter_type_registry.js +18 -18
  230. package/lib/support_code_library_builder/types.d.ts +88 -88
  231. package/lib/support_code_library_builder/types.js +2 -2
  232. package/lib/support_code_library_builder/validate_arguments.d.ts +12 -12
  233. package/lib/support_code_library_builder/validate_arguments.js +72 -72
  234. package/lib/support_code_library_builder/world.d.ts +18 -18
  235. package/lib/support_code_library_builder/world.js +10 -10
  236. package/lib/time.d.ts +18 -18
  237. package/lib/time.js +60 -60
  238. package/lib/try_require.d.ts +7 -7
  239. package/lib/try_require.js +22 -22
  240. package/lib/types/index.d.ts +4 -4
  241. package/lib/types/index.js +2 -2
  242. package/lib/uncaught_exception_manager.d.ts +7 -7
  243. package/lib/uncaught_exception_manager.js +11 -11
  244. package/lib/user_code_runner.d.ts +14 -14
  245. package/lib/user_code_runner.js +81 -81
  246. package/lib/value_checker.d.ts +3 -3
  247. package/lib/value_checker.js +18 -18
  248. package/lib/version.d.ts +1 -1
  249. package/lib/version.js +5 -5
  250. package/lib/version.js.map +1 -1
  251. package/package.json +4 -1
@@ -1,248 +1,434 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class ReportGenerator {
4
- constructor() {
5
- this.report = {
6
- result: {
7
- status: 'UNKNOWN',
8
- },
9
- testCases: [],
10
- };
11
- this.gherkinDocumentMap = new Map();
12
- this.pickleMap = new Map();
13
- this.testCaseMap = new Map();
14
- this.testStepMap = new Map();
15
- this.stepProgressMap = new Map();
16
- this.testProgressMap = new Map();
17
- this.reportFolder = null;
18
- }
19
- handleMessage(envelope) {
20
- const type = Object.keys(envelope)[0];
21
- switch (type) {
22
- // case "meta": { break}
23
- // case "source": { break}
24
- case 'parseError': {
25
- const parseError = envelope[type];
26
- this.handleParseError(parseError);
27
- break;
28
- }
29
- case 'gherkinDocument': {
30
- const doc = envelope[type];
31
- this.onGherkinDocument(doc);
32
- break;
33
- }
34
- case 'pickle': {
35
- const pickle = envelope[type];
36
- this.onPickle(pickle);
37
- break;
38
- }
39
- // case "stepDefinition": { break}
40
- // case "hook": { break} // Before Hook
41
- case 'testRunStarted': {
42
- const testRunStarted = envelope[type];
43
- this.onTestRunStarted(testRunStarted);
44
- break;
45
- }
46
- case 'testCase': {
47
- const testCase = envelope[type];
48
- this.onTestCase(testCase);
49
- break;
50
- }
51
- case 'testCaseStarted': {
52
- const testCaseStarted = envelope[type];
53
- this.onTestCaseStarted(testCaseStarted);
54
- break;
55
- }
56
- case 'testStepStarted': {
57
- const testStepStarted = envelope[type];
58
- this.onTestStepStarted(testStepStarted);
59
- break;
60
- }
61
- case 'attachment': {
62
- const attachment = envelope[type];
63
- this.onAttachment(attachment);
64
- break;
65
- }
66
- case 'testStepFinished': {
67
- const testStepFinished = envelope[type];
68
- this.onTestStepFinished(testStepFinished);
69
- break;
70
- }
71
- case 'testCaseFinished': {
72
- const testCaseFinished = envelope[type];
73
- this.onTestCaseFinished(testCaseFinished);
74
- break;
75
- }
76
- // case "hook": { break} // After Hook
77
- case 'testRunFinished': {
78
- const testRunFinished = envelope[type];
79
- this.onTestRunFinished(testRunFinished);
80
- break;
81
- }
82
- // case "parameterType" : { break}
83
- // case "undefinedParameterType": { break}
84
- }
85
- }
86
- getReport() {
87
- return this.report;
88
- }
89
- handleParseError(parseError) {
90
- const { message, source } = parseError;
91
- const timestamp = new Date().getTime();
92
- this.report.result = {
93
- status: 'FAILED',
94
- startTime: timestamp,
95
- endTime: timestamp,
96
- message: message,
97
- };
98
- }
99
- onGherkinDocument(doc) {
100
- this.gherkinDocumentMap.set(doc.uri, doc);
101
- }
102
- onPickle(pickle) {
103
- this.pickleMap.set(pickle.id, pickle);
104
- }
105
- getTimeStamp(timestamp) {
106
- return timestamp.seconds * 1000 + timestamp.nanos / 1000000;
107
- }
108
- onTestRunStarted(testRunStarted) {
109
- this.report.result = {
110
- status: 'STARTED',
111
- startTime: this.getTimeStamp(testRunStarted.timestamp),
112
- };
113
- }
114
- onTestCase(testCase) {
115
- this.testCaseMap.set(testCase.id, testCase);
116
- testCase.testSteps.forEach((testStep) => {
117
- this.testStepMap.set(testStep.id, testStep);
118
- });
119
- }
120
- onTestCaseStarted(testCaseStarted) {
121
- const { testCaseId, id, timestamp } = testCaseStarted;
122
- const testCase = this.testCaseMap.get(testCaseId);
123
- if (testCase === undefined)
124
- throw new Error(`testCase with id ${testCaseId} not found`);
125
- const pickle = this.pickleMap.get(testCase.pickleId);
126
- if (pickle === undefined)
127
- throw new Error(`pickle with id ${testCase.pickleId} not found`);
128
- const doc = this.gherkinDocumentMap.get(pickle.uri);
129
- if (doc === undefined)
130
- throw new Error(`gherkinDocument with uri ${pickle.uri} not found`);
131
- const featureName = doc.feature.name;
132
- const scenarioName = pickle.name;
133
- const steps = pickle.steps.map((step) => {
134
- this.stepProgressMap.set(step.id, {
135
- type: step.type,
136
- text: step.text,
137
- commands: [],
138
- result: {
139
- status: 'UNKNOWN',
140
- },
141
- });
142
- return this.stepProgressMap.get(step.id);
143
- });
144
- this.testProgressMap.set(id, {
145
- id,
146
- uri: pickle.uri,
147
- featureName,
148
- scenarioName,
149
- // TODO: compute parameters
150
- parameters: {},
151
- steps,
152
- result: {
153
- status: 'STARTED',
154
- startTime: this.getTimeStamp(timestamp),
155
- },
156
- });
157
- this.report.testCases.push(this.testProgressMap.get(id));
158
- }
159
- onTestStepStarted(testStepStarted) {
160
- const { testStepId, timestamp, testCaseStartedId } = testStepStarted;
161
- const testStep = this.testStepMap.get(testStepId);
162
- if (testStep === undefined)
163
- throw new Error(`testStep with id ${testStepId} not found`);
164
- if (testStep.pickleStepId === undefined)
165
- return;
166
- const stepProgess = this.stepProgressMap.get(testStep.pickleStepId);
167
- stepProgess.result = {
168
- status: 'STARTED',
169
- startTime: this.getTimeStamp(timestamp),
170
- };
171
- }
172
- onAttachment(attachment) {
173
- const { testCaseStartedId, testStepId, body, mediaType, contentEncoding, fileName, source, url, } = attachment;
174
- if (mediaType === 'text/plain') {
175
- this.reportFolder = body.replaceAll('\\', '/');
176
- }
177
- const testStep = this.testStepMap.get(testStepId);
178
- if (testStep.pickleStepId === undefined)
179
- return;
180
- const stepProgess = this.stepProgressMap.get(testStep.pickleStepId);
181
- if (mediaType === 'application/json') {
182
- const command = JSON.parse(body);
183
- stepProgess.commands.push(command);
184
- }
185
- }
186
- onTestStepFinished(testStepFinished) {
187
- const { testStepId, testCaseStartedId, testStepResult, timestamp } = testStepFinished;
188
- const testStep = this.testStepMap.get(testStepId);
189
- if (testStep.pickleStepId === undefined)
190
- return;
191
- const stepProgess = this.stepProgressMap.get(testStep.pickleStepId);
192
- const prevStepResult = stepProgess.result;
193
- stepProgess.result = {
194
- status: testStepResult.status,
195
- startTime: prevStepResult.startTime,
196
- endTime: this.getTimeStamp(timestamp),
197
- message: testStepResult.message,
198
- // exception: testStepResult.exception,
199
- };
200
- }
201
- getTestCaseResult(steps) {
202
- for (const step of steps) {
203
- switch (step.result.status) {
204
- case 'FAILED':
205
- return {
206
- status: step.result.status,
207
- message: step.result.message,
208
- // exception: step.result.exception,
209
- };
210
- case 'AMBIGUOUS':
211
- case 'UNDEFINED':
212
- case 'PENDING':
213
- return {
214
- status: 'FAILED',
215
- message: `step "${step.text}" is ${step.result.status}`,
216
- };
217
- }
218
- }
219
- return {
220
- status: 'PASSED',
221
- };
222
- }
223
- onTestCaseFinished(testCaseFinished) {
224
- const { testCaseStartedId, timestamp } = testCaseFinished;
225
- const testProgress = this.testProgressMap.get(testCaseStartedId);
226
- const prevResult = testProgress.result;
227
- const steps = Object.values(testProgress.steps);
228
- const result = this.getTestCaseResult(steps);
229
- testProgress.result = {
230
- ...result,
231
- startTime: prevResult.startTime,
232
- endTime: this.getTimeStamp(timestamp),
233
- };
234
- }
235
- onTestRunFinished(testRunFinished) {
236
- const { timestamp, success, exception, message } = testRunFinished;
237
- const prevResult = this.report.result;
238
- this.report.result = {
239
- status: success ? 'PASSED' : 'FAILED',
240
- startTime: prevResult.startTime,
241
- endTime: this.getTimeStamp(timestamp),
242
- message,
243
- // exception,
244
- };
245
- }
246
- }
247
- exports.default = ReportGenerator;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ var _a, _b;
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const upload_serivce_1 = require("./upload_serivce");
10
+ const URL = process.env.NODE_ENV_BLINQ === 'dev'
11
+ ? 'https://dev.api.blinq.io/api/runs'
12
+ : process.env.NODE_ENV_BLINQ === 'local'
13
+ ? 'http://localhost:5001/api/runs'
14
+ : process.env.NODE_ENV_BLINQ === 'stage'
15
+ ? 'https://stage.api.blinq.io/api/runs'
16
+ : 'https://api.blinq.io/api/runs';
17
+ const REPORT_SERVICE_URL = (_a = process.env.REPORT_SERVICE_URL) !== null && _a !== void 0 ? _a : URL;
18
+ const BATCH_SIZE = 10;
19
+ const MAX_RETRIES = 3;
20
+ const REPORT_SERVICE_TOKEN = (_b = process.env.TOKEN) !== null && _b !== void 0 ? _b : process.env.REPORT_SERVICE_TOKEN;
21
+ class ReportGenerator {
22
+ constructor() {
23
+ this.report = {
24
+ result: {
25
+ status: 'UNKNOWN',
26
+ },
27
+ testCases: [],
28
+ env: {
29
+ name: '',
30
+ baseUrl: '',
31
+ },
32
+ };
33
+ this.gherkinDocumentMap = new Map();
34
+ this.stepMap = new Map();
35
+ this.pickleMap = new Map();
36
+ this.testCaseMap = new Map();
37
+ this.testStepMap = new Map();
38
+ this.stepReportMap = new Map();
39
+ this.testCaseReportMap = new Map();
40
+ this.scenarioIterationCountMap = new Map();
41
+ this.logs = [];
42
+ this.networkLog = [];
43
+ this.runName = '';
44
+ this.reportFolder = null;
45
+ this.uploadService = new upload_serivce_1.RunUploadService(REPORT_SERVICE_URL, REPORT_SERVICE_TOKEN);
46
+ }
47
+ async handleMessage(envelope) {
48
+ if (envelope.meta && envelope.meta.runName) {
49
+ this.runName = envelope.meta.runName;
50
+ }
51
+ const type = Object.keys(envelope)[0];
52
+ switch (type) {
53
+ // case "meta": { break}
54
+ // case "source": { break}
55
+ case 'parseError': {
56
+ const parseError = envelope[type];
57
+ this.handleParseError(parseError);
58
+ break;
59
+ }
60
+ case 'gherkinDocument': {
61
+ const doc = envelope[type];
62
+ this.onGherkinDocument(doc);
63
+ break;
64
+ }
65
+ case 'pickle': {
66
+ const pickle = envelope[type];
67
+ this.onPickle(pickle);
68
+ break;
69
+ }
70
+ // case "stepDefinition": { break}
71
+ // case "hook": { break} // Before Hook
72
+ case 'testRunStarted': {
73
+ const testRunStarted = envelope[type];
74
+ this.onTestRunStarted(testRunStarted);
75
+ break;
76
+ }
77
+ case 'testCase': {
78
+ const testCase = envelope[type];
79
+ this.onTestCase(testCase);
80
+ break;
81
+ }
82
+ case 'testCaseStarted': {
83
+ const testCaseStarted = envelope[type];
84
+ this.onTestCaseStarted(testCaseStarted);
85
+ break;
86
+ }
87
+ case 'testStepStarted': {
88
+ const testStepStarted = envelope[type];
89
+ this.onTestStepStarted(testStepStarted);
90
+ break;
91
+ }
92
+ case 'attachment': {
93
+ const attachment = envelope[type];
94
+ this.onAttachment(attachment);
95
+ break;
96
+ }
97
+ case 'testStepFinished': {
98
+ const testStepFinished = envelope[type];
99
+ this.onTestStepFinished(testStepFinished);
100
+ break;
101
+ }
102
+ case 'testCaseFinished': {
103
+ const testCaseFinished = envelope[type];
104
+ await this.onTestCaseFinished(testCaseFinished);
105
+ break;
106
+ }
107
+ // case "hook": { break} // After Hook
108
+ case 'testRunFinished': {
109
+ const testRunFinished = envelope[type];
110
+ this.onTestRunFinished(testRunFinished);
111
+ break;
112
+ }
113
+ // case "parameterType" : { break}
114
+ // case "undefinedParameterType": { break}
115
+ }
116
+ }
117
+ getReport() {
118
+ return this.report;
119
+ }
120
+ handleParseError(parseError) {
121
+ const { message } = parseError;
122
+ const timestamp = new Date().getTime();
123
+ this.report.result = {
124
+ status: 'FAILED',
125
+ startTime: timestamp,
126
+ endTime: timestamp,
127
+ message: message,
128
+ };
129
+ }
130
+ onGherkinDocument(doc) {
131
+ this.gherkinDocumentMap.set(doc.uri, doc);
132
+ doc.feature.children.forEach((child) => {
133
+ if (child.scenario) {
134
+ child.scenario.steps.forEach((step) => {
135
+ this.stepMap.set(step.id, step);
136
+ });
137
+ }
138
+ else if (child.background) {
139
+ child.background.steps.forEach((step) => {
140
+ this.stepMap.set(step.id, step);
141
+ });
142
+ }
143
+ else if (child.rule) {
144
+ child.rule.children.forEach((child) => {
145
+ if (child.scenario) {
146
+ child.scenario.steps.forEach((step) => {
147
+ this.stepMap.set(step.id, step);
148
+ });
149
+ }
150
+ else if (child.background) {
151
+ child.background.steps.forEach((step) => {
152
+ this.stepMap.set(step.id, step);
153
+ });
154
+ }
155
+ });
156
+ }
157
+ });
158
+ }
159
+ onPickle(pickle) {
160
+ this.pickleMap.set(pickle.id, pickle);
161
+ }
162
+ getTimeStamp(timestamp) {
163
+ return timestamp.seconds * 1000 + timestamp.nanos / 1000000;
164
+ }
165
+ onTestRunStarted(testRunStarted) {
166
+ this.report.result = {
167
+ status: 'STARTED',
168
+ startTime: this.getTimeStamp(testRunStarted.timestamp),
169
+ };
170
+ }
171
+ onTestCase(testCase) {
172
+ this.testCaseMap.set(testCase.id, testCase);
173
+ testCase.testSteps.forEach((testStep) => {
174
+ this.testStepMap.set(testStep.id, testStep);
175
+ });
176
+ }
177
+ _findScenario(doc, scenarioId) {
178
+ for (const child of doc.feature.children) {
179
+ if (child.scenario && child.scenario.id === scenarioId) {
180
+ return child.scenario;
181
+ }
182
+ if (child.rule) {
183
+ for (const scenario of child.rule.children) {
184
+ if (scenario.scenario && scenario.scenario.id === scenarioId) {
185
+ return scenario.scenario;
186
+ }
187
+ }
188
+ }
189
+ }
190
+ throw new Error(`scenario "${scenarioId}" not found`);
191
+ }
192
+ _getParameters(scenario, exampleId) {
193
+ const parameters = {};
194
+ if (scenario.examples.length === 0)
195
+ return parameters;
196
+ for (const examples of scenario.examples) {
197
+ for (const tableRow of examples.tableBody) {
198
+ if (tableRow.id === exampleId) {
199
+ for (let i = 0; i < examples.tableHeader.cells.length; i++) {
200
+ parameters[examples.tableHeader.cells[i].value] =
201
+ tableRow.cells[i].value;
202
+ }
203
+ }
204
+ }
205
+ }
206
+ return parameters;
207
+ }
208
+ onTestCaseStarted(testCaseStarted) {
209
+ const { testCaseId, id, timestamp } = testCaseStarted;
210
+ const testCase = this.testCaseMap.get(testCaseId);
211
+ if (testCase === undefined)
212
+ throw new Error(`testCase with id ${testCaseId} not found`);
213
+ const pickle = this.pickleMap.get(testCase.pickleId);
214
+ if (pickle === undefined)
215
+ throw new Error(`pickle with id ${testCase.pickleId} not found`);
216
+ const doc = this.gherkinDocumentMap.get(pickle.uri);
217
+ if (doc === undefined)
218
+ throw new Error(`gherkinDocument with uri ${pickle.uri} not found`);
219
+ const featureName = doc.feature.name;
220
+ const scenarioId = pickle.astNodeIds[0];
221
+ const scenario = this._findScenario(doc, scenarioId);
222
+ const scenarioName = scenario.name;
223
+ if (!this.scenarioIterationCountMap.has(scenarioId)) {
224
+ this.scenarioIterationCountMap.set(scenarioId, 1);
225
+ }
226
+ const parameters = this._getParameters(scenario, pickle.astNodeIds[1]);
227
+ console.log(`Running scenario ${scenarioName} iteration ${this.scenarioIterationCountMap.get(scenarioId)} with parameters:\n${JSON.stringify(parameters, null, 4)}\n
228
+ `);
229
+ this.scenarioIterationCountMap.set(scenarioId, this.scenarioIterationCountMap.get(scenarioId) + 1);
230
+ const steps = pickle.steps.map((pickleStep) => {
231
+ const stepId = pickleStep.astNodeIds[0];
232
+ const step = this.stepMap.get(stepId);
233
+ this.stepReportMap.set(pickleStep.id, {
234
+ type: step.keywordType,
235
+ keyword: step.keyword,
236
+ text: step.text,
237
+ commands: [],
238
+ result: {
239
+ status: 'UNKNOWN',
240
+ },
241
+ });
242
+ return this.stepReportMap.get(pickleStep.id);
243
+ });
244
+ this.testCaseReportMap.set(id, {
245
+ id,
246
+ uri: pickle.uri,
247
+ featureName,
248
+ scenarioName,
249
+ parameters,
250
+ steps,
251
+ result: {
252
+ status: 'STARTED',
253
+ startTime: this.getTimeStamp(timestamp),
254
+ },
255
+ webLog: [],
256
+ networkLog: [],
257
+ });
258
+ this.report.testCases.push(this.testCaseReportMap.get(id));
259
+ }
260
+ onTestStepStarted(testStepStarted) {
261
+ const { testStepId, timestamp } = testStepStarted;
262
+ const testStep = this.testStepMap.get(testStepId);
263
+ if (testStep === undefined)
264
+ throw new Error(`testStep with id ${testStepId} not found`);
265
+ if (testStep.pickleStepId === undefined)
266
+ return;
267
+ const stepProgess = this.stepReportMap.get(testStep.pickleStepId);
268
+ stepProgess.result = {
269
+ status: 'STARTED',
270
+ startTime: this.getTimeStamp(timestamp),
271
+ };
272
+ }
273
+ onAttachment(attachment) {
274
+ const { testStepId, body, mediaType } = attachment;
275
+ if (mediaType === 'text/plain') {
276
+ this.reportFolder = body.replaceAll('\\', '/');
277
+ return;
278
+ }
279
+ if (mediaType === 'application/json+env') {
280
+ const data = JSON.parse(body);
281
+ this.report.env = data;
282
+ }
283
+ if (mediaType === 'application/json+log') {
284
+ const log = JSON.parse(body);
285
+ if (this.logs.length < 1000)
286
+ this.logs.push(log);
287
+ }
288
+ if (mediaType === 'application/json+network') {
289
+ const networkLog = JSON.parse(body);
290
+ if (this.networkLog.length < 1000)
291
+ this.networkLog.push(networkLog);
292
+ }
293
+ const testStep = this.testStepMap.get(testStepId);
294
+ if (testStep.pickleStepId === undefined)
295
+ return;
296
+ const stepProgess = this.stepReportMap.get(testStep.pickleStepId);
297
+ if (mediaType === 'application/json') {
298
+ const command = JSON.parse(body);
299
+ stepProgess.commands.push(command);
300
+ }
301
+ }
302
+ onTestStepFinished(testStepFinished) {
303
+ const { testStepId, testStepResult, timestamp } = testStepFinished;
304
+ const testStep = this.testStepMap.get(testStepId);
305
+ if (testStep.pickleStepId === undefined) {
306
+ if (testStepResult.status === 'FAILED') {
307
+ console.error(`Before/After hook failed with message: ${testStepResult.message}`);
308
+ }
309
+ return;
310
+ }
311
+ const stepProgess = this.stepReportMap.get(testStep.pickleStepId);
312
+ const prevStepResult = stepProgess.result;
313
+ let data = {};
314
+ const reportFolder = this.reportFolder;
315
+ if (reportFolder === null) {
316
+ throw new Error('"reportFolder" is "null". Failed to run BVT hooks. Please retry after running "Generate All" or "Record Scenario" ');
317
+ }
318
+ try {
319
+ if (fs_1.default.existsSync(path_1.default.join(reportFolder, 'data.json'))) {
320
+ data = JSON.parse(fs_1.default.readFileSync(path_1.default.join(reportFolder, 'data.json'), 'utf8'));
321
+ }
322
+ }
323
+ catch (error) {
324
+ console.log('Error reading data.json');
325
+ }
326
+ stepProgess.result = {
327
+ status: testStepResult.status,
328
+ startTime: prevStepResult.startTime,
329
+ endTime: this.getTimeStamp(timestamp),
330
+ message: testStepResult.message,
331
+ // exception: testStepResult.exception,
332
+ };
333
+ if (Object.keys(data).length > 0) {
334
+ stepProgess.data = data;
335
+ }
336
+ }
337
+ getLogFileContent() {
338
+ let projectPath = process.cwd();
339
+ if (process.env.PROJECT_PATH) {
340
+ projectPath = process.env.PROJECT_PATH;
341
+ }
342
+ const logFolder = path_1.default.join(projectPath, 'logs', 'web');
343
+ if (!fs_1.default.existsSync(logFolder)) {
344
+ return [];
345
+ }
346
+ let nextId = 1;
347
+ while (fs_1.default.existsSync(path_1.default.join(logFolder, `${nextId}.json`))) {
348
+ nextId++;
349
+ }
350
+ if (nextId === 1) {
351
+ return [];
352
+ }
353
+ try {
354
+ const logFileContent = fs_1.default.readFileSync(path_1.default.join(logFolder, `${nextId - 1}.json`), 'utf8');
355
+ return JSON.parse(logFileContent);
356
+ }
357
+ catch (error) {
358
+ return [];
359
+ }
360
+ }
361
+ getTestCaseResult(steps) {
362
+ for (const step of steps) {
363
+ switch (step.result.status) {
364
+ case 'FAILED':
365
+ return {
366
+ status: step.result.status,
367
+ message: step.result.message,
368
+ // exception: step.result.exception,
369
+ };
370
+ case 'AMBIGUOUS':
371
+ case 'UNDEFINED':
372
+ case 'PENDING':
373
+ return {
374
+ status: 'FAILED',
375
+ message: `step "${step.text}" is ${step.result.status}`,
376
+ };
377
+ }
378
+ }
379
+ return {
380
+ status: 'PASSED',
381
+ };
382
+ }
383
+ async onTestCaseFinished(testCaseFinished) {
384
+ const { testCaseStartedId, timestamp } = testCaseFinished;
385
+ const testProgress = this.testCaseReportMap.get(testCaseStartedId);
386
+ const prevResult = testProgress.result;
387
+ const steps = Object.values(testProgress.steps);
388
+ const result = this.getTestCaseResult(steps);
389
+ testProgress.result = {
390
+ ...result,
391
+ startTime: prevResult.startTime,
392
+ endTime: this.getTimeStamp(timestamp),
393
+ };
394
+ testProgress.webLog = this.logs;
395
+ testProgress.networkLog = this.networkLog;
396
+ this.networkLog = [];
397
+ this.logs = [];
398
+ await this.uploadTestCase(testProgress);
399
+ }
400
+ async uploadTestCase(testCase) {
401
+ let runId = '';
402
+ let projectId = '';
403
+ try {
404
+ if (process.env.RUN_ID && process.env.PROJECT_ID) {
405
+ runId = process.env.RUN_ID;
406
+ projectId = process.env.PROJECT_ID;
407
+ }
408
+ else {
409
+ const runDoc = await this.uploadService.createRunDocument(this.runName);
410
+ runId = runDoc._id;
411
+ projectId = runDoc.project_id;
412
+ process.env.RUN_ID = runId;
413
+ process.env.PROJECT_ID = projectId;
414
+ }
415
+ await this.uploadService.uploadTestCase(testCase, runId, projectId, this.reportFolder);
416
+ }
417
+ catch (e) {
418
+ console.error('Error uploading test case:', e);
419
+ }
420
+ }
421
+ onTestRunFinished(testRunFinished) {
422
+ const { timestamp, success, message } = testRunFinished;
423
+ const prevResult = this.report.result;
424
+ this.report.result = {
425
+ status: success ? 'PASSED' : 'FAILED',
426
+ startTime: prevResult.startTime,
427
+ endTime: this.getTimeStamp(timestamp),
428
+ message,
429
+ // exception,
430
+ };
431
+ }
432
+ }
433
+ exports.default = ReportGenerator;
248
434
  //# sourceMappingURL=report_generator.js.map