@dev-blinq/cucumber-js 1.0.11 → 1.0.12-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 (257) hide show
  1. package/bin/cucumber-js +0 -0
  2. package/bin/cucumber.js +0 -0
  3. package/bin/download-install.js +126 -0
  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 -64
  8. package/lib/api/convert_configuration.js.map +1 -1
  9. package/lib/api/environment.d.ts +2 -2
  10. package/lib/api/environment.js +13 -13
  11. package/lib/api/formatters.d.ts +20 -20
  12. package/lib/api/formatters.js +60 -60
  13. package/lib/api/gherkin.d.ts +21 -21
  14. package/lib/api/gherkin.js +140 -99
  15. package/lib/api/gherkin.js.map +1 -1
  16. package/lib/api/index.d.ts +12 -12
  17. package/lib/api/index.js +27 -27
  18. package/lib/api/load_configuration.d.ts +9 -9
  19. package/lib/api/load_configuration.js +40 -40
  20. package/lib/api/load_sources.d.ts +9 -9
  21. package/lib/api/load_sources.js +52 -52
  22. package/lib/api/load_support.d.ts +10 -10
  23. package/lib/api/load_support.js +29 -29
  24. package/lib/api/paths.d.ts +8 -8
  25. package/lib/api/paths.js +101 -101
  26. package/lib/api/plugins.d.ts +4 -4
  27. package/lib/api/plugins.js +18 -18
  28. package/lib/api/run_cucumber.d.ts +11 -11
  29. package/lib/api/run_cucumber.js +114 -114
  30. package/lib/api/run_cucumber.js.map +1 -1
  31. package/lib/api/runtime.d.ts +21 -21
  32. package/lib/api/runtime.js +35 -35
  33. package/lib/api/support.d.ts +9 -9
  34. package/lib/api/support.js +25 -25
  35. package/lib/api/test_helpers.d.ts +3 -3
  36. package/lib/api/test_helpers.js +30 -30
  37. package/lib/api/types.d.ts +177 -175
  38. package/lib/api/types.js +2 -2
  39. package/lib/api/types.js.map +1 -1
  40. package/lib/cli/helpers.d.ts +39 -37
  41. package/lib/cli/helpers.js +223 -202
  42. package/lib/cli/helpers.js.map +1 -1
  43. package/lib/cli/i18n.d.ts +2 -2
  44. package/lib/cli/i18n.js +69 -69
  45. package/lib/cli/index.d.ts +21 -21
  46. package/lib/cli/index.js +63 -58
  47. package/lib/cli/index.js.map +1 -1
  48. package/lib/cli/install_validator.d.ts +1 -1
  49. package/lib/cli/install_validator.js +13 -13
  50. package/lib/cli/run.d.ts +1 -1
  51. package/lib/cli/run.js +43 -43
  52. package/lib/cli/validate_node_engine_version.d.ts +10 -10
  53. package/lib/cli/validate_node_engine_version.js +23 -23
  54. package/lib/configuration/argv_parser.d.ts +20 -20
  55. package/lib/configuration/argv_parser.js +102 -100
  56. package/lib/configuration/argv_parser.js.map +1 -1
  57. package/lib/configuration/check_schema.d.ts +2 -2
  58. package/lib/configuration/check_schema.js +59 -59
  59. package/lib/configuration/default_configuration.d.ts +2 -2
  60. package/lib/configuration/default_configuration.js +28 -26
  61. package/lib/configuration/default_configuration.js.map +1 -1
  62. package/lib/configuration/from_file.d.ts +3 -3
  63. package/lib/configuration/from_file.js +84 -84
  64. package/lib/configuration/helpers.d.ts +1 -1
  65. package/lib/configuration/helpers.js +10 -10
  66. package/lib/configuration/index.d.ts +7 -7
  67. package/lib/configuration/index.js +28 -28
  68. package/lib/configuration/locate_file.d.ts +1 -1
  69. package/lib/configuration/locate_file.js +20 -20
  70. package/lib/configuration/merge_configurations.d.ts +2 -2
  71. package/lib/configuration/merge_configurations.js +47 -47
  72. package/lib/configuration/option_splitter.d.ts +3 -3
  73. package/lib/configuration/option_splitter.js +22 -22
  74. package/lib/configuration/types.d.ts +30 -28
  75. package/lib/configuration/types.js +2 -2
  76. package/lib/configuration/types.js.map +1 -1
  77. package/lib/configuration/validate_configuration.d.ts +3 -3
  78. package/lib/configuration/validate_configuration.js +12 -12
  79. package/lib/filter_stack_trace.d.ts +3 -3
  80. package/lib/filter_stack_trace.js +37 -37
  81. package/lib/formatter/builder.d.ts +37 -37
  82. package/lib/formatter/builder.js +100 -100
  83. package/lib/formatter/bvt_analysis_formatter.d.ts +18 -0
  84. package/lib/formatter/bvt_analysis_formatter.js +193 -0
  85. package/lib/formatter/bvt_analysis_formatter.js.map +1 -0
  86. package/lib/formatter/feature_data_format.d.ts +23 -14
  87. package/lib/formatter/feature_data_format.js +136 -80
  88. package/lib/formatter/feature_data_format.js.map +1 -1
  89. package/lib/formatter/fixtures/typescript.d.ts +2 -2
  90. package/lib/formatter/fixtures/typescript.js +5 -5
  91. package/lib/formatter/get_color_fns.d.ts +15 -15
  92. package/lib/formatter/get_color_fns.js +55 -55
  93. package/lib/formatter/helpers/duration_helpers.d.ts +2 -2
  94. package/lib/formatter/helpers/duration_helpers.js +8 -8
  95. package/lib/formatter/helpers/event_data_collector.d.ts +30 -30
  96. package/lib/formatter/helpers/event_data_collector.js +125 -125
  97. package/lib/formatter/helpers/formatters.d.ts +6 -6
  98. package/lib/formatter/helpers/formatters.js +44 -44
  99. package/lib/formatter/helpers/formatters.js.map +1 -1
  100. package/lib/formatter/helpers/gherkin_document_parser.d.ts +5 -5
  101. package/lib/formatter/helpers/gherkin_document_parser.js +65 -65
  102. package/lib/formatter/helpers/index.d.ts +10 -10
  103. package/lib/formatter/helpers/index.js +51 -51
  104. package/lib/formatter/helpers/issue_helpers.d.ts +19 -19
  105. package/lib/formatter/helpers/issue_helpers.js +58 -58
  106. package/lib/formatter/helpers/keyword_type.d.ts +11 -11
  107. package/lib/formatter/helpers/keyword_type.js +31 -31
  108. package/lib/formatter/helpers/location_helpers.d.ts +2 -2
  109. package/lib/formatter/helpers/location_helpers.js +16 -16
  110. package/lib/formatter/helpers/pickle_parser.d.ts +17 -17
  111. package/lib/formatter/helpers/pickle_parser.js +27 -27
  112. package/lib/formatter/helpers/report_generator.d.ts +110 -91
  113. package/lib/formatter/helpers/report_generator.js +348 -247
  114. package/lib/formatter/helpers/report_generator.js.map +1 -1
  115. package/lib/formatter/helpers/step_argument_formatter.d.ts +2 -2
  116. package/lib/formatter/helpers/step_argument_formatter.js +47 -47
  117. package/lib/formatter/helpers/summary_helpers.d.ts +9 -9
  118. package/lib/formatter/helpers/summary_helpers.js +95 -95
  119. package/lib/formatter/helpers/test_case_attempt_formatter.d.ts +12 -12
  120. package/lib/formatter/helpers/test_case_attempt_formatter.js +113 -113
  121. package/lib/formatter/helpers/test_case_attempt_parser.d.ts +32 -32
  122. package/lib/formatter/helpers/test_case_attempt_parser.js +134 -134
  123. package/lib/formatter/helpers/upload_serivce.d.ts +13 -9
  124. package/lib/formatter/helpers/upload_serivce.js +103 -46
  125. package/lib/formatter/helpers/upload_serivce.js.map +1 -1
  126. package/lib/formatter/helpers/uploader.d.ts +11 -0
  127. package/lib/formatter/helpers/uploader.js +78 -0
  128. package/lib/formatter/helpers/uploader.js.map +1 -0
  129. package/lib/formatter/helpers/usage_helpers/index.d.ts +23 -23
  130. package/lib/formatter/helpers/usage_helpers/index.js +110 -110
  131. package/lib/formatter/html_formatter.d.ts +7 -7
  132. package/lib/formatter/html_formatter.js +29 -29
  133. package/lib/formatter/index.d.ts +53 -53
  134. package/lib/formatter/index.js +20 -20
  135. package/lib/formatter/json_formatter.d.ts +78 -78
  136. package/lib/formatter/json_formatter.js +229 -229
  137. package/lib/formatter/junit_formatter.d.ts +17 -17
  138. package/lib/formatter/junit_formatter.js +180 -180
  139. package/lib/formatter/message_formatter.d.ts +5 -5
  140. package/lib/formatter/message_formatter.js +14 -14
  141. package/lib/formatter/progress_bar_formatter.d.ts +18 -18
  142. package/lib/formatter/progress_bar_formatter.js +98 -98
  143. package/lib/formatter/progress_formatter.d.ts +9 -9
  144. package/lib/formatter/progress_formatter.js +58 -58
  145. package/lib/formatter/rerun_formatter.d.ts +13 -13
  146. package/lib/formatter/rerun_formatter.js +79 -79
  147. package/lib/formatter/snippets_formatter.d.ts +6 -6
  148. package/lib/formatter/snippets_formatter.js +60 -60
  149. package/lib/formatter/step_definition_snippet_builder/index.d.ts +20 -20
  150. package/lib/formatter/step_definition_snippet_builder/index.js +45 -45
  151. package/lib/formatter/step_definition_snippet_builder/javascript_snippet_syntax.d.ts +7 -7
  152. package/lib/formatter/step_definition_snippet_builder/javascript_snippet_syntax.js +45 -45
  153. package/lib/formatter/step_definition_snippet_builder/snippet_syntax.d.ts +16 -16
  154. package/lib/formatter/step_definition_snippet_builder/snippet_syntax.js +10 -10
  155. package/lib/formatter/summary_formatter.d.ts +14 -14
  156. package/lib/formatter/summary_formatter.js +67 -67
  157. package/lib/formatter/usage_formatter.d.ts +6 -6
  158. package/lib/formatter/usage_formatter.js +97 -97
  159. package/lib/formatter/usage_json_formatter.d.ts +7 -7
  160. package/lib/formatter/usage_json_formatter.js +33 -33
  161. package/lib/index.d.ts +58 -58
  162. package/lib/index.js +108 -108
  163. package/lib/logger.d.ts +5 -5
  164. package/lib/logger.js +2 -2
  165. package/lib/models/data_table.d.ts +10 -10
  166. package/lib/models/data_table.js +45 -45
  167. package/lib/models/definition.d.ts +55 -55
  168. package/lib/models/definition.js +21 -21
  169. package/lib/models/gherkin_step_keyword.d.ts +1 -1
  170. package/lib/models/gherkin_step_keyword.js +2 -2
  171. package/lib/models/pickle_order.d.ts +1 -1
  172. package/lib/models/pickle_order.js +2 -2
  173. package/lib/models/step_definition.d.ts +11 -11
  174. package/lib/models/step_definition.js +36 -36
  175. package/lib/models/test_case_hook_definition.d.ts +10 -10
  176. package/lib/models/test_case_hook_definition.js +26 -26
  177. package/lib/models/test_run_hook_definition.d.ts +3 -3
  178. package/lib/models/test_run_hook_definition.js +9 -9
  179. package/lib/models/test_step_hook_definition.d.ts +9 -9
  180. package/lib/models/test_step_hook_definition.js +25 -25
  181. package/lib/pickle_filter.d.ts +42 -42
  182. package/lib/pickle_filter.js +98 -98
  183. package/lib/plugin/index.d.ts +2 -2
  184. package/lib/plugin/index.js +18 -18
  185. package/lib/plugin/plugin_manager.d.ts +13 -13
  186. package/lib/plugin/plugin_manager.js +35 -35
  187. package/lib/plugin/types.d.ts +14 -14
  188. package/lib/plugin/types.js +2 -2
  189. package/lib/publish/http_stream.d.ts +30 -30
  190. package/lib/publish/http_stream.js +111 -111
  191. package/lib/publish/index.d.ts +2 -2
  192. package/lib/publish/index.js +4 -4
  193. package/lib/publish/publish_plugin.d.ts +2 -2
  194. package/lib/publish/publish_plugin.js +47 -47
  195. package/lib/runtime/assemble_test_cases.d.ts +13 -13
  196. package/lib/runtime/assemble_test_cases.js +87 -87
  197. package/lib/runtime/attachment_manager/index.d.ts +33 -33
  198. package/lib/runtime/attachment_manager/index.js +118 -118
  199. package/lib/runtime/format_error.d.ts +2 -2
  200. package/lib/runtime/format_error.js +35 -35
  201. package/lib/runtime/helpers.d.ts +6 -6
  202. package/lib/runtime/helpers.js +100 -100
  203. package/lib/runtime/index.d.ts +40 -40
  204. package/lib/runtime/index.js +75 -75
  205. package/lib/runtime/parallel/command_types.d.ts +32 -32
  206. package/lib/runtime/parallel/command_types.js +2 -2
  207. package/lib/runtime/parallel/coordinator.d.ts +72 -72
  208. package/lib/runtime/parallel/coordinator.js +221 -221
  209. package/lib/runtime/parallel/run_worker.d.ts +1 -1
  210. package/lib/runtime/parallel/run_worker.js +28 -28
  211. package/lib/runtime/parallel/worker.d.ts +26 -26
  212. package/lib/runtime/parallel/worker.js +86 -86
  213. package/lib/runtime/run_test_run_hooks.d.ts +3 -3
  214. package/lib/runtime/run_test_run_hooks.js +27 -27
  215. package/lib/runtime/step_runner.d.ts +16 -16
  216. package/lib/runtime/step_runner.js +87 -87
  217. package/lib/runtime/stopwatch.d.ts +12 -12
  218. package/lib/runtime/stopwatch.js +33 -33
  219. package/lib/runtime/test_case_runner.d.ts +54 -54
  220. package/lib/runtime/test_case_runner.js +267 -267
  221. package/lib/step_arguments.d.ts +6 -6
  222. package/lib/step_arguments.js +18 -18
  223. package/lib/support_code_library_builder/build_parameter_type.d.ts +3 -3
  224. package/lib/support_code_library_builder/build_parameter_type.js +12 -12
  225. package/lib/support_code_library_builder/get_definition_line_and_uri.d.ts +3 -3
  226. package/lib/support_code_library_builder/get_definition_line_and_uri.js +28 -28
  227. package/lib/support_code_library_builder/index.d.ts +74 -74
  228. package/lib/support_code_library_builder/index.js +296 -296
  229. package/lib/support_code_library_builder/parallel_can_assign_helpers.d.ts +2 -2
  230. package/lib/support_code_library_builder/parallel_can_assign_helpers.js +15 -15
  231. package/lib/support_code_library_builder/sourced_parameter_type_registry.d.ts +7 -7
  232. package/lib/support_code_library_builder/sourced_parameter_type_registry.js +18 -18
  233. package/lib/support_code_library_builder/types.d.ts +88 -88
  234. package/lib/support_code_library_builder/types.js +2 -2
  235. package/lib/support_code_library_builder/validate_arguments.d.ts +12 -12
  236. package/lib/support_code_library_builder/validate_arguments.js +72 -72
  237. package/lib/support_code_library_builder/world.d.ts +18 -18
  238. package/lib/support_code_library_builder/world.js +10 -10
  239. package/lib/time.d.ts +18 -18
  240. package/lib/time.js +60 -60
  241. package/lib/try_require.d.ts +7 -7
  242. package/lib/try_require.js +22 -22
  243. package/lib/types/index.d.ts +4 -4
  244. package/lib/types/index.js +2 -2
  245. package/lib/uncaught_exception_manager.d.ts +7 -7
  246. package/lib/uncaught_exception_manager.js +11 -11
  247. package/lib/user_code_runner.d.ts +14 -14
  248. package/lib/user_code_runner.js +81 -81
  249. package/lib/value_checker.d.ts +3 -3
  250. package/lib/value_checker.js +18 -18
  251. package/lib/version.d.ts +1 -1
  252. package/lib/version.js +5 -5
  253. package/lib/version.js.map +1 -1
  254. package/package.json +4 -2
  255. package/lib/formatter/bvt_formatter.d.ts +0 -9
  256. package/lib/formatter/bvt_formatter.js +0 -63
  257. package/lib/formatter/bvt_formatter.js.map +0 -1
@@ -1,101 +1,101 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const get_color_fns_1 = __importDefault(require("./get_color_fns"));
7
- const javascript_snippet_syntax_1 = __importDefault(require("./step_definition_snippet_builder/javascript_snippet_syntax"));
8
- const path_1 = __importDefault(require("path"));
9
- const step_definition_snippet_builder_1 = __importDefault(require("./step_definition_snippet_builder"));
10
- const value_checker_1 = require("../value_checker");
11
- const snippet_syntax_1 = require("./step_definition_snippet_builder/snippet_syntax");
12
- const url_1 = require("url");
13
- const formatters_1 = __importDefault(require("./helpers/formatters"));
14
- // eslint-disable-next-line @typescript-eslint/no-var-requires
15
- const { importer } = require('../importer');
16
- const FormatterBuilder = {
17
- async build(type, options) {
18
- const FormatterConstructor = await FormatterBuilder.getConstructorByType(type, options.cwd);
19
- const colorFns = (0, get_color_fns_1.default)(options.stream, options.env, options.parsedArgvOptions.colorsEnabled);
20
- const snippetBuilder = await FormatterBuilder.getStepDefinitionSnippetBuilder({
21
- cwd: options.cwd,
22
- snippetInterface: options.parsedArgvOptions.snippetInterface,
23
- snippetSyntax: options.parsedArgvOptions.snippetSyntax,
24
- supportCodeLibrary: options.supportCodeLibrary,
25
- });
26
- return new FormatterConstructor({
27
- colorFns,
28
- snippetBuilder,
29
- ...options,
30
- });
31
- },
32
- async getConstructorByType(type, cwd) {
33
- const formatters = formatters_1.default.getFormatters();
34
- return formatters[type]
35
- ? formatters[type]
36
- : await FormatterBuilder.loadCustomClass('formatter', type, cwd);
37
- },
38
- async getStepDefinitionSnippetBuilder({ cwd, snippetInterface, snippetSyntax, supportCodeLibrary, }) {
39
- if ((0, value_checker_1.doesNotHaveValue)(snippetInterface)) {
40
- snippetInterface = snippet_syntax_1.SnippetInterface.Synchronous;
41
- }
42
- let Syntax = javascript_snippet_syntax_1.default;
43
- if ((0, value_checker_1.doesHaveValue)(snippetSyntax)) {
44
- Syntax = await FormatterBuilder.loadCustomClass('syntax', snippetSyntax, cwd);
45
- }
46
- return new step_definition_snippet_builder_1.default({
47
- snippetSyntax: new Syntax(snippetInterface),
48
- parameterTypeRegistry: supportCodeLibrary.parameterTypeRegistry,
49
- });
50
- },
51
- async loadCustomClass(type, descriptor, cwd) {
52
- let normalized = descriptor;
53
- if (descriptor.startsWith('.')) {
54
- normalized = (0, url_1.pathToFileURL)(path_1.default.resolve(cwd, descriptor));
55
- }
56
- else if (descriptor.startsWith('file://')) {
57
- normalized = new URL(descriptor);
58
- }
59
- let CustomClass = await FormatterBuilder.loadFile(normalized);
60
- CustomClass = FormatterBuilder.resolveConstructor(CustomClass);
61
- if ((0, value_checker_1.doesHaveValue)(CustomClass)) {
62
- return CustomClass;
63
- }
64
- else {
65
- throw new Error(`Custom ${type} (${descriptor}) does not export a function/class`);
66
- }
67
- },
68
- async loadFile(urlOrName) {
69
- let result;
70
- try {
71
- // eslint-disable-next-line @typescript-eslint/no-var-requires
72
- result = require(typeof urlOrName === 'string'
73
- ? urlOrName
74
- : (0, url_1.fileURLToPath)(urlOrName));
75
- }
76
- catch (error) {
77
- if (error.code === 'ERR_REQUIRE_ESM') {
78
- result = await importer(urlOrName);
79
- }
80
- else {
81
- throw error;
82
- }
83
- }
84
- return result;
85
- },
86
- resolveConstructor(ImportedCode) {
87
- if ((0, value_checker_1.doesNotHaveValue)(ImportedCode)) {
88
- return null;
89
- }
90
- if (typeof ImportedCode === 'function') {
91
- return ImportedCode;
92
- }
93
- else if (typeof ImportedCode === 'object' &&
94
- typeof ImportedCode.default === 'function') {
95
- return ImportedCode.default;
96
- }
97
- return null;
98
- },
99
- };
100
- exports.default = FormatterBuilder;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const get_color_fns_1 = __importDefault(require("./get_color_fns"));
7
+ const javascript_snippet_syntax_1 = __importDefault(require("./step_definition_snippet_builder/javascript_snippet_syntax"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const step_definition_snippet_builder_1 = __importDefault(require("./step_definition_snippet_builder"));
10
+ const value_checker_1 = require("../value_checker");
11
+ const snippet_syntax_1 = require("./step_definition_snippet_builder/snippet_syntax");
12
+ const url_1 = require("url");
13
+ const formatters_1 = __importDefault(require("./helpers/formatters"));
14
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
15
+ const { importer } = require('../importer');
16
+ const FormatterBuilder = {
17
+ async build(type, options) {
18
+ const FormatterConstructor = await FormatterBuilder.getConstructorByType(type, options.cwd);
19
+ const colorFns = (0, get_color_fns_1.default)(options.stream, options.env, options.parsedArgvOptions.colorsEnabled);
20
+ const snippetBuilder = await FormatterBuilder.getStepDefinitionSnippetBuilder({
21
+ cwd: options.cwd,
22
+ snippetInterface: options.parsedArgvOptions.snippetInterface,
23
+ snippetSyntax: options.parsedArgvOptions.snippetSyntax,
24
+ supportCodeLibrary: options.supportCodeLibrary,
25
+ });
26
+ return new FormatterConstructor({
27
+ colorFns,
28
+ snippetBuilder,
29
+ ...options,
30
+ });
31
+ },
32
+ async getConstructorByType(type, cwd) {
33
+ const formatters = formatters_1.default.getFormatters();
34
+ return formatters[type]
35
+ ? formatters[type]
36
+ : await FormatterBuilder.loadCustomClass('formatter', type, cwd);
37
+ },
38
+ async getStepDefinitionSnippetBuilder({ cwd, snippetInterface, snippetSyntax, supportCodeLibrary, }) {
39
+ if ((0, value_checker_1.doesNotHaveValue)(snippetInterface)) {
40
+ snippetInterface = snippet_syntax_1.SnippetInterface.Synchronous;
41
+ }
42
+ let Syntax = javascript_snippet_syntax_1.default;
43
+ if ((0, value_checker_1.doesHaveValue)(snippetSyntax)) {
44
+ Syntax = await FormatterBuilder.loadCustomClass('syntax', snippetSyntax, cwd);
45
+ }
46
+ return new step_definition_snippet_builder_1.default({
47
+ snippetSyntax: new Syntax(snippetInterface),
48
+ parameterTypeRegistry: supportCodeLibrary.parameterTypeRegistry,
49
+ });
50
+ },
51
+ async loadCustomClass(type, descriptor, cwd) {
52
+ let normalized = descriptor;
53
+ if (descriptor.startsWith('.')) {
54
+ normalized = (0, url_1.pathToFileURL)(path_1.default.resolve(cwd, descriptor));
55
+ }
56
+ else if (descriptor.startsWith('file://')) {
57
+ normalized = new URL(descriptor);
58
+ }
59
+ let CustomClass = await FormatterBuilder.loadFile(normalized);
60
+ CustomClass = FormatterBuilder.resolveConstructor(CustomClass);
61
+ if ((0, value_checker_1.doesHaveValue)(CustomClass)) {
62
+ return CustomClass;
63
+ }
64
+ else {
65
+ throw new Error(`Custom ${type} (${descriptor}) does not export a function/class`);
66
+ }
67
+ },
68
+ async loadFile(urlOrName) {
69
+ let result;
70
+ try {
71
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
72
+ result = require(typeof urlOrName === 'string'
73
+ ? urlOrName
74
+ : (0, url_1.fileURLToPath)(urlOrName));
75
+ }
76
+ catch (error) {
77
+ if (error.code === 'ERR_REQUIRE_ESM') {
78
+ result = await importer(urlOrName);
79
+ }
80
+ else {
81
+ throw error;
82
+ }
83
+ }
84
+ return result;
85
+ },
86
+ resolveConstructor(ImportedCode) {
87
+ if ((0, value_checker_1.doesNotHaveValue)(ImportedCode)) {
88
+ return null;
89
+ }
90
+ if (typeof ImportedCode === 'function') {
91
+ return ImportedCode;
92
+ }
93
+ else if (typeof ImportedCode === 'object' &&
94
+ typeof ImportedCode.default === 'function') {
95
+ return ImportedCode.default;
96
+ }
97
+ return null;
98
+ },
99
+ };
100
+ exports.default = FormatterBuilder;
101
101
  //# sourceMappingURL=builder.js.map
@@ -0,0 +1,18 @@
1
+ import Formatter, { IFormatterOptions } from '.';
2
+ export default class BVTAnalysisFormatter extends Formatter {
3
+ private reportGenerator;
4
+ private uploader;
5
+ private exit;
6
+ private START;
7
+ private runName;
8
+ constructor(options: IFormatterOptions);
9
+ private uploadReport;
10
+ finished(): Promise<any>;
11
+ private analyzeReport;
12
+ private processTestCases;
13
+ private processTestCase;
14
+ private uploadFinalReport;
15
+ private retrain;
16
+ private call_cucumber_client;
17
+ private logReportLink;
18
+ }
@@ -0,0 +1,193 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const child_process_1 = require("child_process");
7
+ const path_1 = __importDefault(require("path"));
8
+ const _1 = __importDefault(require("."));
9
+ const value_checker_1 = require("../value_checker");
10
+ const report_generator_1 = __importDefault(require("./helpers/report_generator"));
11
+ const uploader_1 = __importDefault(require("./helpers/uploader"));
12
+ const fs_1 = require("fs");
13
+ const tmp_promise_1 = require("tmp-promise");
14
+ //User token
15
+ const TOKEN = process.env.TOKEN;
16
+ class BVTAnalysisFormatter extends _1.default {
17
+ constructor(options) {
18
+ super(options);
19
+ this.reportGenerator = new report_generator_1.default();
20
+ this.uploader = new uploader_1.default(this.reportGenerator);
21
+ this.exit = false;
22
+ if (!TOKEN && process.env.BVT_FORMATTER === 'ANALYSIS') {
23
+ throw new Error('TOKEN must be set');
24
+ }
25
+ options.eventBroadcaster.on('envelope', async (envelope) => {
26
+ this.reportGenerator.handleMessage(envelope);
27
+ if ((0, value_checker_1.doesHaveValue)(envelope.meta) &&
28
+ (0, value_checker_1.doesHaveValue)(envelope.meta.runName)) {
29
+ this.runName = envelope.meta.runName;
30
+ }
31
+ if ((0, value_checker_1.doesHaveValue)(envelope.testRunFinished)) {
32
+ const report = this.reportGenerator.getReport();
33
+ this.START = Date.now();
34
+ if (process.env.BVT_FORMATTER === 'ANALYSIS') {
35
+ await this.analyzeReport(report);
36
+ }
37
+ else {
38
+ await this.uploadReport(report);
39
+ }
40
+ this.exit = true;
41
+ }
42
+ });
43
+ }
44
+ async uploadReport(report) {
45
+ const uploadSuccessful = await this.uploadFinalReport(report);
46
+ if (uploadSuccessful && report.result.status !== 'FAILED') {
47
+ process.exit(0);
48
+ }
49
+ process.exit(1);
50
+ }
51
+ async finished() {
52
+ await new Promise((resolve) => {
53
+ const checkInterval = setInterval(() => {
54
+ if (this.exit) {
55
+ clearInterval(checkInterval);
56
+ resolve(null);
57
+ }
58
+ }, 100); // check every 100ms
59
+ });
60
+ }
61
+ async analyzeReport(report) {
62
+ if (report.result.status === 'PASSED') {
63
+ this.log('All tests passed. No need to retrain\n');
64
+ const uploadSuccessful = await this.uploadFinalReport(report);
65
+ if (uploadSuccessful) {
66
+ process.exit(0);
67
+ }
68
+ process.exit(1);
69
+ }
70
+ //checking if the type of report.result is JsonResultFailed or not
71
+ this.log('Some tests failed, starting the retraining...\n');
72
+ if (!('startTime' in report.result) || !('endTime' in report.result)) {
73
+ this.log('Unknown error occured,not retraining\n');
74
+ await this.uploadFinalReport(report);
75
+ return;
76
+ }
77
+ const finalReport = await this.processTestCases(report);
78
+ const uploadSuccessful = await this.uploadFinalReport(finalReport);
79
+ if (finalReport.result.status !== 'FAILED' && uploadSuccessful) {
80
+ process.exit(0);
81
+ }
82
+ else {
83
+ process.exit(1);
84
+ }
85
+ }
86
+ async processTestCases(report) {
87
+ const finalTestCases = [];
88
+ for (const testCase of report.testCases) {
89
+ const modifiedTestCase = await this.processTestCase(testCase, report);
90
+ finalTestCases.push(modifiedTestCase);
91
+ }
92
+ const finalResult = finalTestCases.some((tc) => tc.result.status !== 'PASSED')
93
+ ? report.result
94
+ : {
95
+ ...report.result,
96
+ status: 'PASSED',
97
+ };
98
+ return {
99
+ result: finalResult,
100
+ testCases: finalTestCases,
101
+ };
102
+ }
103
+ async processTestCase(testCase, report) {
104
+ if (testCase.result.status === 'PASSED') {
105
+ return testCase;
106
+ }
107
+ const failedTestSteps = testCase.steps
108
+ .map((step, i) => (step.result.status !== 'PASSED' ? i : null))
109
+ .filter((i) => i !== null);
110
+ const retrainStats = await this.retrain(failedTestSteps, testCase);
111
+ if (!retrainStats) {
112
+ return testCase;
113
+ }
114
+ return {
115
+ ...testCase,
116
+ retrainStats,
117
+ };
118
+ }
119
+ async uploadFinalReport(finalReport) {
120
+ let success = true;
121
+ try {
122
+ const { projectId, runId } = await this.uploader.uploadRun(finalReport, this.runName);
123
+ this.logReportLink(runId, projectId);
124
+ }
125
+ catch (err) {
126
+ this.log('Error uploading report\n');
127
+ if ('stack' in err) {
128
+ this.log(err.stack);
129
+ }
130
+ success = false;
131
+ }
132
+ //this.log(JSON.stringify(finalReport, null, 2))
133
+ return success;
134
+ }
135
+ async retrain(failedTestCases, testCase) {
136
+ const stepsToRetrain = testCase.steps.map((_, i) => i);
137
+ return await this.call_cucumber_client(stepsToRetrain, testCase);
138
+ }
139
+ async call_cucumber_client(stepsToRetrain, testCase) {
140
+ return new Promise((resolve, reject) => {
141
+ const cucumber_client_path = path_1.default.resolve(process.cwd(), 'node_modules', '@dev-blinq', 'cucumber_client', 'bin', 'client', 'cucumber.js');
142
+ const args = [
143
+ process.cwd(),
144
+ path_1.default.join(process.cwd(), testCase.uri),
145
+ `${testCase.scenarioName}`,
146
+ `${stepsToRetrain.join(',')}`,
147
+ ];
148
+ if (process.env.BLINQ_ENV) {
149
+ args.push(`--env=${process.env.BLINQ_ENV}`);
150
+ }
151
+ // const temporaryFileTask = await import('tempy')
152
+ (0, tmp_promise_1.withFile)(async ({ path: tempFile, fd }) => {
153
+ // when this function returns or throws - release the file
154
+ args.push(`--temp-file=${tempFile}`);
155
+ const cucumberClient = (0, child_process_1.spawn)('node', [cucumber_client_path, ...args], {
156
+ env: {
157
+ ...process.env,
158
+ },
159
+ });
160
+ cucumberClient.stdout.on('data', (data) => {
161
+ console.log(data.toString());
162
+ });
163
+ cucumberClient.stderr.on('data', (data) => {
164
+ console.error(data.toString());
165
+ });
166
+ cucumberClient.on('close', (code) => {
167
+ if (code === 0) {
168
+ const reportData = (0, fs_1.readFileSync)(tempFile, 'utf-8');
169
+ const retrainStats = JSON.parse(reportData);
170
+ resolve(retrainStats);
171
+ }
172
+ else {
173
+ this.log('Error retraining\n');
174
+ resolve(null);
175
+ }
176
+ });
177
+ });
178
+ });
179
+ }
180
+ logReportLink(runId, projectId) {
181
+ let reportLinkBaseUrl = 'https://app.blinq.io';
182
+ if (process.env.NODE_ENV_BLINQ === 'local') {
183
+ reportLinkBaseUrl = 'http://localhost:3000';
184
+ }
185
+ else if (process.env.NODE_ENV_BLINQ === 'dev') {
186
+ reportLinkBaseUrl = 'https://dev.app.blinq.io';
187
+ }
188
+ const reportLink = `${reportLinkBaseUrl}/${projectId}/run-report/${runId}`;
189
+ this.log(`Report link: ${reportLink}\n`);
190
+ }
191
+ }
192
+ exports.default = BVTAnalysisFormatter;
193
+ //# sourceMappingURL=bvt_analysis_formatter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bvt_analysis_formatter.js","sourceRoot":"","sources":["../../src/formatter/bvt_analysis_formatter.ts"],"names":[],"mappings":";;;;;AACA,iDAAqC;AACrC,gDAAuB;AACvB,yCAAgD;AAChD,oDAAgD;AAChD,kFASmC;AACnC,kEAA+C;AAC/C,2BAAiC;AACjC,6CAAsC;AACtC,YAAY;AACZ,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAAA;AAQ/B,MAAqB,oBAAqB,SAAQ,UAAS;IAMzD,YAAY,OAA0B;QACpC,KAAK,CAAC,OAAO,CAAC,CAAA;QANR,oBAAe,GAAG,IAAI,0BAAe,EAAE,CAAA;QACvC,aAAQ,GAAG,IAAI,kBAAc,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA;QACnD,SAAI,GAAG,KAAK,CAAA;QAKlB,IAAI,CAAC,KAAK,IAAI,OAAO,CAAC,GAAG,CAAC,aAAa,KAAK,UAAU,EAAE;YACtD,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAA;SACrC;QACD,OAAO,CAAC,gBAAgB,CAAC,EAAE,CACzB,UAAU,EACV,KAAK,EAAE,QAAiC,EAAE,EAAE;YAC1C,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAA;YAC5C,IACE,IAAA,6BAAa,EAAC,QAAQ,CAAC,IAAI,CAAC;gBAC5B,IAAA,6BAAa,EAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,EACpC;gBACA,IAAI,CAAC,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAA;aACrC;YACD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AO,EAAE;YAC1C,iBAAiB,GAAG,uBAAuB,CAAA;SAC5C;aAAM,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,KAAK,KAAK,EAAE;YAC/C,iBAAiB,GAAG,0BAA0B,CAAA;SAC/C;QACD,MAAM,UAAU,GAAG,GAAG,iBAAiB,IAAI,SAAS,eAAe,KAAK,EAAE,CAAA;QAC1E,IAAI,CAAC,GAAG,CAAC,gBAAgB,UAAU,IAAI,CAAC,CAAA;IAC1C,CAAC;CACF;AArND,uCAqNC","sourcesContent":["import { Envelope, Meta } from '@cucumber/messages'\nimport { spawn } from 'child_process'\nimport path from 'path'\nimport Formatter, { IFormatterOptions } from '.'\nimport { doesHaveValue } from '../value_checker'\nimport ReportGenerator, {\n JsonFixedByAi,\n JsonReport,\n JsonResultFailed,\n JsonResultPassed,\n JsonStep,\n JsonTestProgress,\n JsonTestResult,\n RetrainStats,\n} from './helpers/report_generator'\nimport ReportUploader from './helpers/uploader'\nimport { readFileSync } from 'fs'\nimport { withFile } from 'tmp-promise'\n//User token\nconst TOKEN = process.env.TOKEN\ninterface MetaMessage extends Meta {\n runName: string\n}\n\ninterface EnvelopeWithMetaMessage extends Envelope {\n meta: MetaMessage\n}\nexport default class BVTAnalysisFormatter extends Formatter {\n private reportGenerator = new ReportGenerator()\n private uploader = new ReportUploader(this.reportGenerator)\n private exit = false\n private START: number\n private runName: string\n constructor(options: IFormatterOptions) {\n super(options)\n if (!TOKEN && process.env.BVT_FORMATTER === 'ANALYSIS') {\n throw new Error('TOKEN must be set')\n }\n options.eventBroadcaster.on(\n 'envelope',\n async (envelope: EnvelopeWithMetaMessage) => {\n this.reportGenerator.handleMessage(envelope)\n if (\n doesHaveValue(envelope.meta) &&\n doesHaveValue(envelope.meta.runName)\n ) {\n this.runName = envelope.meta.runName\n }\n if (doesHaveValue(envelope.testRunFinished)) {\n const report = this.reportGenerator.getReport()\n this.START = Date.now()\n if (process.env.BVT_FORMATTER === 'ANALYSIS') {\n await this.analyzeReport(report)\n } else {\n await this.uploadReport(report)\n }\n this.exit = true\n }\n }\n )\n }\n\n private async uploadReport(report: JsonReport) {\n const uploadSuccessful = await this.uploadFinalReport(report)\n if (uploadSuccessful && report.result.status !== 'FAILED') {\n process.exit(0)\n }\n process.exit(1)\n }\n\n async finished(): Promise<any> {\n await new Promise((resolve) => {\n const checkInterval = setInterval(() => {\n if (this.exit) {\n clearInterval(checkInterval)\n resolve(null)\n }\n }, 100) // check every 100ms\n })\n }\n private async analyzeReport(report: JsonReport) {\n if (report.result.status === 'PASSED') {\n this.log('All tests passed. No need to retrain\\n')\n const uploadSuccessful = await this.uploadFinalReport(report)\n if (uploadSuccessful) {\n process.exit(0)\n }\n\n process.exit(1)\n }\n //checking if the type of report.result is JsonResultFailed or not\n this.log('Some tests failed, starting the retraining...\\n')\n if (!('startTime' in report.result) || !('endTime' in report.result)) {\n this.log('Unknown error occured,not retraining\\n')\n await this.uploadFinalReport(report)\n return\n }\n const finalReport = await this.processTestCases(report)\n const uploadSuccessful = await this.uploadFinalReport(finalReport)\n if (finalReport.result.status !== 'FAILED' && uploadSuccessful) {\n process.exit(0)\n } else {\n process.exit(1)\n }\n }\n private async processTestCases(report: JsonReport): Promise<JsonReport> {\n const finalTestCases = []\n for (const testCase of report.testCases) {\n const modifiedTestCase = await this.processTestCase(testCase, report)\n\n finalTestCases.push(modifiedTestCase)\n }\n const finalResult = finalTestCases.some(\n (tc) => tc.result.status !== 'PASSED'\n )\n ? report.result\n : ({\n ...report.result,\n status: 'PASSED',\n } as JsonTestResult)\n return {\n result: finalResult,\n testCases: finalTestCases,\n }\n }\n private async processTestCase(\n testCase: JsonTestProgress,\n report: JsonReport\n ): Promise<JsonTestProgress> {\n if (testCase.result.status === 'PASSED') {\n return testCase\n }\n const failedTestSteps = testCase.steps\n .map((step, i) => (step.result.status !== 'PASSED' ? i : null))\n .filter((i) => i !== null)\n const retrainStats = await this.retrain(failedTestSteps, testCase)\n\n if (!retrainStats) {\n return testCase\n }\n\n return {\n ...testCase,\n retrainStats,\n }\n }\n\n private async uploadFinalReport(finalReport: JsonReport) {\n let success = true\n try {\n const { projectId, runId } = await this.uploader.uploadRun(\n finalReport,\n this.runName\n )\n this.logReportLink(runId, projectId)\n } catch (err) {\n this.log('Error uploading report\\n')\n if ('stack' in err) {\n this.log(err.stack)\n }\n success = false\n }\n\n //this.log(JSON.stringify(finalReport, null, 2))\n return success\n }\n private async retrain(\n failedTestCases: number[],\n testCase: JsonTestProgress\n ): Promise<RetrainStats | null> {\n const stepsToRetrain = testCase.steps.map((_, i) => i)\n return await this.call_cucumber_client(stepsToRetrain, testCase)\n }\n\n private async call_cucumber_client(\n stepsToRetrain: number[],\n testCase: JsonTestProgress\n ): Promise<RetrainStats | null> {\n return new Promise((resolve, reject) => {\n const cucumber_client_path = path.resolve(\n process.cwd(),\n 'node_modules',\n '@dev-blinq',\n 'cucumber_client',\n 'bin',\n 'client',\n 'cucumber.js'\n )\n\n const args: string[] = [\n process.cwd(),\n path.join(process.cwd(), testCase.uri),\n `${testCase.scenarioName}`,\n `${stepsToRetrain.join(',')}`,\n ]\n\n if (process.env.BLINQ_ENV) {\n args.push(`--env=${process.env.BLINQ_ENV}`)\n }\n // const temporaryFileTask = await import('tempy')\n withFile(async ({ path: tempFile, fd }) => {\n // when this function returns or throws - release the file\n args.push(`--temp-file=${tempFile}`)\n const cucumberClient = spawn('node', [cucumber_client_path, ...args], {\n env: {\n ...process.env,\n },\n })\n\n cucumberClient.stdout.on('data', (data) => {\n console.log(data.toString())\n })\n\n cucumberClient.stderr.on('data', (data) => {\n console.error(data.toString())\n })\n\n cucumberClient.on('close', (code) => {\n if (code === 0) {\n const reportData = readFileSync(tempFile, 'utf-8')\n const retrainStats = JSON.parse(reportData) as RetrainStats\n resolve(retrainStats)\n } else {\n this.log('Error retraining\\n')\n resolve(null)\n }\n })\n })\n })\n }\n private logReportLink(runId: string, projectId: string) {\n let reportLinkBaseUrl = 'https://app.blinq.io'\n if (process.env.NODE_ENV_BLINQ === 'local') {\n reportLinkBaseUrl = 'http://localhost:3000'\n } else if (process.env.NODE_ENV_BLINQ === 'dev') {\n reportLinkBaseUrl = 'https://dev.app.blinq.io'\n }\n const reportLink = `${reportLinkBaseUrl}/${projectId}/run-report/${runId}`\n this.log(`Report link: ${reportLink}\\n`)\n }\n}\n"]}
@@ -1,14 +1,23 @@
1
- declare const generateTestData: (featureFileContent: string, vars?: any, fakeData?: {
2
- var: string;
3
- fake: string;
4
- }[]) => {
5
- newContent: string;
6
- variables: any;
7
- otherFakeData: {
8
- var: string;
9
- fake: string;
10
- }[];
11
- changed: boolean;
12
- fakeIndex: number;
13
- };
14
- export { generateTestData };
1
+ import { TableCell } from '@cucumber/messages';
2
+ declare const generateTestData: (featureFileContent: string, vars?: any, fakeData?: {
3
+ var: string;
4
+ fake: string;
5
+ }[]) => {
6
+ newContent: string;
7
+ variables: any;
8
+ otherFakeData: {
9
+ var: string;
10
+ fake: string;
11
+ }[];
12
+ changed: boolean;
13
+ fakeIndex: number;
14
+ };
15
+ declare const generateExamplesFromFunction: (data: string, feature_path: string, functionName: string, functionFile: string) => {
16
+ newData: string;
17
+ mjsData: any;
18
+ };
19
+ declare const generateExamplesFromFunctionGherkin: (headers: readonly TableCell[], values: readonly TableCell[], mjsData: any) => {
20
+ header: string;
21
+ value: any;
22
+ }[];
23
+ export { generateTestData, generateExamplesFromFunction, generateExamplesFromFunctionGherkin, };