@dev-blinq/cucumber-js 1.0.0-amdocs
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.
- package/LICENSE +22 -0
- package/README.md +68 -0
- package/api/index.d.ts +6 -0
- package/bin/cucumber-js +3 -0
- package/bin/cucumber.js +3 -0
- package/bin/cucumber.ts +2 -0
- package/bin/download-install.js +167 -0
- package/lib/api/console_logger.d.ts +12 -0
- package/lib/api/console_logger.js +24 -0
- package/lib/api/console_logger.js.map +1 -0
- package/lib/api/convert_configuration.d.ts +4 -0
- package/lib/api/convert_configuration.js +66 -0
- package/lib/api/convert_configuration.js.map +1 -0
- package/lib/api/environment.d.ts +2 -0
- package/lib/api/environment.js +14 -0
- package/lib/api/environment.js.map +1 -0
- package/lib/api/formatters.d.ts +20 -0
- package/lib/api/formatters.js +61 -0
- package/lib/api/formatters.js.map +1 -0
- package/lib/api/gherkin.d.ts +21 -0
- package/lib/api/gherkin.js +146 -0
- package/lib/api/gherkin.js.map +1 -0
- package/lib/api/index.d.ts +12 -0
- package/lib/api/index.js +28 -0
- package/lib/api/index.js.map +1 -0
- package/lib/api/load_configuration.d.ts +9 -0
- package/lib/api/load_configuration.js +41 -0
- package/lib/api/load_configuration.js.map +1 -0
- package/lib/api/load_sources.d.ts +9 -0
- package/lib/api/load_sources.js +53 -0
- package/lib/api/load_sources.js.map +1 -0
- package/lib/api/load_support.d.ts +10 -0
- package/lib/api/load_support.js +30 -0
- package/lib/api/load_support.js.map +1 -0
- package/lib/api/paths.d.ts +8 -0
- package/lib/api/paths.js +102 -0
- package/lib/api/paths.js.map +1 -0
- package/lib/api/plugins.d.ts +4 -0
- package/lib/api/plugins.js +19 -0
- package/lib/api/plugins.js.map +1 -0
- package/lib/api/run_cucumber.d.ts +11 -0
- package/lib/api/run_cucumber.js +115 -0
- package/lib/api/run_cucumber.js.map +1 -0
- package/lib/api/runtime.d.ts +21 -0
- package/lib/api/runtime.js +36 -0
- package/lib/api/runtime.js.map +1 -0
- package/lib/api/support.d.ts +9 -0
- package/lib/api/support.js +26 -0
- package/lib/api/support.js.map +1 -0
- package/lib/api/test_helpers.d.ts +3 -0
- package/lib/api/test_helpers.js +36 -0
- package/lib/api/test_helpers.js.map +1 -0
- package/lib/api/types.d.ts +177 -0
- package/lib/api/types.js +3 -0
- package/lib/api/types.js.map +1 -0
- package/lib/api/wrapper.mjs +6 -0
- package/lib/cli/helpers.d.ts +39 -0
- package/lib/cli/helpers.js +224 -0
- package/lib/cli/helpers.js.map +1 -0
- package/lib/cli/i18n.d.ts +2 -0
- package/lib/cli/i18n.js +70 -0
- package/lib/cli/i18n.js.map +1 -0
- package/lib/cli/index.d.ts +21 -0
- package/lib/cli/index.js +64 -0
- package/lib/cli/index.js.map +1 -0
- package/lib/cli/install_validator.d.ts +1 -0
- package/lib/cli/install_validator.js +18 -0
- package/lib/cli/install_validator.js.map +1 -0
- package/lib/cli/run.d.ts +1 -0
- package/lib/cli/run.js +44 -0
- package/lib/cli/run.js.map +1 -0
- package/lib/cli/validate_node_engine_version.d.ts +10 -0
- package/lib/cli/validate_node_engine_version.js +24 -0
- package/lib/cli/validate_node_engine_version.js.map +1 -0
- package/lib/configuration/argv_parser.d.ts +20 -0
- package/lib/configuration/argv_parser.js +104 -0
- package/lib/configuration/argv_parser.js.map +1 -0
- package/lib/configuration/axios_client.d.ts +1 -0
- package/lib/configuration/axios_client.js +40 -0
- package/lib/configuration/axios_client.js.map +1 -0
- package/lib/configuration/check_schema.d.ts +2 -0
- package/lib/configuration/check_schema.js +60 -0
- package/lib/configuration/check_schema.js.map +1 -0
- package/lib/configuration/default_configuration.d.ts +2 -0
- package/lib/configuration/default_configuration.js +29 -0
- package/lib/configuration/default_configuration.js.map +1 -0
- package/lib/configuration/from_file.d.ts +3 -0
- package/lib/configuration/from_file.js +85 -0
- package/lib/configuration/from_file.js.map +1 -0
- package/lib/configuration/helpers.d.ts +1 -0
- package/lib/configuration/helpers.js +11 -0
- package/lib/configuration/helpers.js.map +1 -0
- package/lib/configuration/index.d.ts +7 -0
- package/lib/configuration/index.js +29 -0
- package/lib/configuration/index.js.map +1 -0
- package/lib/configuration/locate_file.d.ts +1 -0
- package/lib/configuration/locate_file.js +21 -0
- package/lib/configuration/locate_file.js.map +1 -0
- package/lib/configuration/merge_configurations.d.ts +2 -0
- package/lib/configuration/merge_configurations.js +48 -0
- package/lib/configuration/merge_configurations.js.map +1 -0
- package/lib/configuration/option_splitter.d.ts +3 -0
- package/lib/configuration/option_splitter.js +23 -0
- package/lib/configuration/option_splitter.js.map +1 -0
- package/lib/configuration/types.d.ts +30 -0
- package/lib/configuration/types.js +3 -0
- package/lib/configuration/types.js.map +1 -0
- package/lib/configuration/validate_configuration.d.ts +3 -0
- package/lib/configuration/validate_configuration.js +13 -0
- package/lib/configuration/validate_configuration.js.map +1 -0
- package/lib/filter_stack_trace.d.ts +3 -0
- package/lib/filter_stack_trace.js +38 -0
- package/lib/filter_stack_trace.js.map +1 -0
- package/lib/formatter/api.d.ts +2 -0
- package/lib/formatter/api.js +53 -0
- package/lib/formatter/api.js.map +1 -0
- package/lib/formatter/builder.d.ts +37 -0
- package/lib/formatter/builder.js +101 -0
- package/lib/formatter/builder.js.map +1 -0
- package/lib/formatter/bvt_analysis_formatter.d.ts +30 -0
- package/lib/formatter/bvt_analysis_formatter.js +334 -0
- package/lib/formatter/bvt_analysis_formatter.js.map +1 -0
- package/lib/formatter/feature_data_format.d.ts +23 -0
- package/lib/formatter/feature_data_format.js +182 -0
- package/lib/formatter/feature_data_format.js.map +1 -0
- package/lib/formatter/fixtures/typescript.d.ts +2 -0
- package/lib/formatter/fixtures/typescript.js +6 -0
- package/lib/formatter/fixtures/typescript.js.map +1 -0
- package/lib/formatter/get_color_fns.d.ts +15 -0
- package/lib/formatter/get_color_fns.js +56 -0
- package/lib/formatter/get_color_fns.js.map +1 -0
- package/lib/formatter/helpers/constants.d.ts +44 -0
- package/lib/formatter/helpers/constants.js +50 -0
- package/lib/formatter/helpers/constants.js.map +1 -0
- package/lib/formatter/helpers/duration_helpers.d.ts +2 -0
- package/lib/formatter/helpers/duration_helpers.js +9 -0
- package/lib/formatter/helpers/duration_helpers.js.map +1 -0
- package/lib/formatter/helpers/event_data_collector.d.ts +30 -0
- package/lib/formatter/helpers/event_data_collector.js +126 -0
- package/lib/formatter/helpers/event_data_collector.js.map +1 -0
- package/lib/formatter/helpers/formatters.d.ts +6 -0
- package/lib/formatter/helpers/formatters.js +45 -0
- package/lib/formatter/helpers/formatters.js.map +1 -0
- package/lib/formatter/helpers/gherkin_document_parser.d.ts +5 -0
- package/lib/formatter/helpers/gherkin_document_parser.js +66 -0
- package/lib/formatter/helpers/gherkin_document_parser.js.map +1 -0
- package/lib/formatter/helpers/index.d.ts +10 -0
- package/lib/formatter/helpers/index.js +52 -0
- package/lib/formatter/helpers/index.js.map +1 -0
- package/lib/formatter/helpers/issue_helpers.d.ts +19 -0
- package/lib/formatter/helpers/issue_helpers.js +59 -0
- package/lib/formatter/helpers/issue_helpers.js.map +1 -0
- package/lib/formatter/helpers/keyword_type.d.ts +11 -0
- package/lib/formatter/helpers/keyword_type.js +32 -0
- package/lib/formatter/helpers/keyword_type.js.map +1 -0
- package/lib/formatter/helpers/location_helpers.d.ts +2 -0
- package/lib/formatter/helpers/location_helpers.js +17 -0
- package/lib/formatter/helpers/location_helpers.js.map +1 -0
- package/lib/formatter/helpers/pickle_parser.d.ts +17 -0
- package/lib/formatter/helpers/pickle_parser.js +28 -0
- package/lib/formatter/helpers/pickle_parser.js.map +1 -0
- package/lib/formatter/helpers/report_generator.d.ts +148 -0
- package/lib/formatter/helpers/report_generator.js +573 -0
- package/lib/formatter/helpers/report_generator.js.map +1 -0
- package/lib/formatter/helpers/step_argument_formatter.d.ts +2 -0
- package/lib/formatter/helpers/step_argument_formatter.js +48 -0
- package/lib/formatter/helpers/step_argument_formatter.js.map +1 -0
- package/lib/formatter/helpers/summary_helpers.d.ts +9 -0
- package/lib/formatter/helpers/summary_helpers.js +96 -0
- package/lib/formatter/helpers/summary_helpers.js.map +1 -0
- package/lib/formatter/helpers/test_case_attempt_formatter.d.ts +12 -0
- package/lib/formatter/helpers/test_case_attempt_formatter.js +114 -0
- package/lib/formatter/helpers/test_case_attempt_formatter.js.map +1 -0
- package/lib/formatter/helpers/test_case_attempt_parser.d.ts +32 -0
- package/lib/formatter/helpers/test_case_attempt_parser.js +135 -0
- package/lib/formatter/helpers/test_case_attempt_parser.js.map +1 -0
- package/lib/formatter/helpers/upload_serivce.d.ts +26 -0
- package/lib/formatter/helpers/upload_serivce.js +237 -0
- package/lib/formatter/helpers/upload_serivce.js.map +1 -0
- package/lib/formatter/helpers/uploader.d.ts +12 -0
- package/lib/formatter/helpers/uploader.js +151 -0
- package/lib/formatter/helpers/uploader.js.map +1 -0
- package/lib/formatter/helpers/usage_helpers/index.d.ts +23 -0
- package/lib/formatter/helpers/usage_helpers/index.js +111 -0
- package/lib/formatter/helpers/usage_helpers/index.js.map +1 -0
- package/lib/formatter/html_formatter.d.ts +7 -0
- package/lib/formatter/html_formatter.js +30 -0
- package/lib/formatter/html_formatter.js.map +1 -0
- package/lib/formatter/index.d.ts +53 -0
- package/lib/formatter/index.js +21 -0
- package/lib/formatter/index.js.map +1 -0
- package/lib/formatter/json_formatter.d.ts +78 -0
- package/lib/formatter/json_formatter.js +230 -0
- package/lib/formatter/json_formatter.js.map +1 -0
- package/lib/formatter/junit_formatter.d.ts +17 -0
- package/lib/formatter/junit_formatter.js +181 -0
- package/lib/formatter/junit_formatter.js.map +1 -0
- package/lib/formatter/message_formatter.d.ts +5 -0
- package/lib/formatter/message_formatter.js +15 -0
- package/lib/formatter/message_formatter.js.map +1 -0
- package/lib/formatter/progress_bar_formatter.d.ts +18 -0
- package/lib/formatter/progress_bar_formatter.js +99 -0
- package/lib/formatter/progress_bar_formatter.js.map +1 -0
- package/lib/formatter/progress_formatter.d.ts +9 -0
- package/lib/formatter/progress_formatter.js +59 -0
- package/lib/formatter/progress_formatter.js.map +1 -0
- package/lib/formatter/rerun_formatter.d.ts +13 -0
- package/lib/formatter/rerun_formatter.js +80 -0
- package/lib/formatter/rerun_formatter.js.map +1 -0
- package/lib/formatter/snippets_formatter.d.ts +6 -0
- package/lib/formatter/snippets_formatter.js +61 -0
- package/lib/formatter/snippets_formatter.js.map +1 -0
- package/lib/formatter/step_definition_snippet_builder/index.d.ts +20 -0
- package/lib/formatter/step_definition_snippet_builder/index.js +46 -0
- package/lib/formatter/step_definition_snippet_builder/index.js.map +1 -0
- package/lib/formatter/step_definition_snippet_builder/javascript_snippet_syntax.d.ts +7 -0
- package/lib/formatter/step_definition_snippet_builder/javascript_snippet_syntax.js +46 -0
- package/lib/formatter/step_definition_snippet_builder/javascript_snippet_syntax.js.map +1 -0
- package/lib/formatter/step_definition_snippet_builder/snippet_syntax.d.ts +16 -0
- package/lib/formatter/step_definition_snippet_builder/snippet_syntax.js +11 -0
- package/lib/formatter/step_definition_snippet_builder/snippet_syntax.js.map +1 -0
- package/lib/formatter/summary_formatter.d.ts +14 -0
- package/lib/formatter/summary_formatter.js +68 -0
- package/lib/formatter/summary_formatter.js.map +1 -0
- package/lib/formatter/usage_formatter.d.ts +6 -0
- package/lib/formatter/usage_formatter.js +98 -0
- package/lib/formatter/usage_formatter.js.map +1 -0
- package/lib/formatter/usage_json_formatter.d.ts +7 -0
- package/lib/formatter/usage_json_formatter.js +34 -0
- package/lib/formatter/usage_json_formatter.js.map +1 -0
- package/lib/importer.js +13 -0
- package/lib/index.d.ts +58 -0
- package/lib/index.js +109 -0
- package/lib/index.js.map +1 -0
- package/lib/logger.d.ts +5 -0
- package/lib/logger.js +3 -0
- package/lib/logger.js.map +1 -0
- package/lib/models/data_table.d.ts +10 -0
- package/lib/models/data_table.js +46 -0
- package/lib/models/data_table.js.map +1 -0
- package/lib/models/definition.d.ts +55 -0
- package/lib/models/definition.js +22 -0
- package/lib/models/definition.js.map +1 -0
- package/lib/models/gherkin_step_keyword.d.ts +1 -0
- package/lib/models/gherkin_step_keyword.js +3 -0
- package/lib/models/gherkin_step_keyword.js.map +1 -0
- package/lib/models/pickle_order.d.ts +1 -0
- package/lib/models/pickle_order.js +3 -0
- package/lib/models/pickle_order.js.map +1 -0
- package/lib/models/step_definition.d.ts +11 -0
- package/lib/models/step_definition.js +37 -0
- package/lib/models/step_definition.js.map +1 -0
- package/lib/models/test_case_hook_definition.d.ts +10 -0
- package/lib/models/test_case_hook_definition.js +27 -0
- package/lib/models/test_case_hook_definition.js.map +1 -0
- package/lib/models/test_run_hook_definition.d.ts +3 -0
- package/lib/models/test_run_hook_definition.js +10 -0
- package/lib/models/test_run_hook_definition.js.map +1 -0
- package/lib/models/test_step_hook_definition.d.ts +9 -0
- package/lib/models/test_step_hook_definition.js +26 -0
- package/lib/models/test_step_hook_definition.js.map +1 -0
- package/lib/pickle_filter.d.ts +42 -0
- package/lib/pickle_filter.js +99 -0
- package/lib/pickle_filter.js.map +1 -0
- package/lib/plugin/index.d.ts +2 -0
- package/lib/plugin/index.js +19 -0
- package/lib/plugin/index.js.map +1 -0
- package/lib/plugin/plugin_manager.d.ts +13 -0
- package/lib/plugin/plugin_manager.js +36 -0
- package/lib/plugin/plugin_manager.js.map +1 -0
- package/lib/plugin/types.d.ts +14 -0
- package/lib/plugin/types.js +3 -0
- package/lib/plugin/types.js.map +1 -0
- package/lib/publish/http_stream.d.ts +30 -0
- package/lib/publish/http_stream.js +112 -0
- package/lib/publish/http_stream.js.map +1 -0
- package/lib/publish/index.d.ts +2 -0
- package/lib/publish/index.js +5 -0
- package/lib/publish/index.js.map +1 -0
- package/lib/publish/publish_plugin.d.ts +2 -0
- package/lib/publish/publish_plugin.js +48 -0
- package/lib/publish/publish_plugin.js.map +1 -0
- package/lib/runtime/assemble_test_cases.d.ts +13 -0
- package/lib/runtime/assemble_test_cases.js +88 -0
- package/lib/runtime/assemble_test_cases.js.map +1 -0
- package/lib/runtime/attachment_manager/index.d.ts +33 -0
- package/lib/runtime/attachment_manager/index.js +119 -0
- package/lib/runtime/attachment_manager/index.js.map +1 -0
- package/lib/runtime/format_error.d.ts +2 -0
- package/lib/runtime/format_error.js +36 -0
- package/lib/runtime/format_error.js.map +1 -0
- package/lib/runtime/helpers.d.ts +6 -0
- package/lib/runtime/helpers.js +101 -0
- package/lib/runtime/helpers.js.map +1 -0
- package/lib/runtime/index.d.ts +40 -0
- package/lib/runtime/index.js +76 -0
- package/lib/runtime/index.js.map +1 -0
- package/lib/runtime/parallel/command_types.d.ts +32 -0
- package/lib/runtime/parallel/command_types.js +3 -0
- package/lib/runtime/parallel/command_types.js.map +1 -0
- package/lib/runtime/parallel/coordinator.d.ts +72 -0
- package/lib/runtime/parallel/coordinator.js +222 -0
- package/lib/runtime/parallel/coordinator.js.map +1 -0
- package/lib/runtime/parallel/run_worker.d.ts +1 -0
- package/lib/runtime/parallel/run_worker.js +29 -0
- package/lib/runtime/parallel/run_worker.js.map +1 -0
- package/lib/runtime/parallel/worker.d.ts +26 -0
- package/lib/runtime/parallel/worker.js +87 -0
- package/lib/runtime/parallel/worker.js.map +1 -0
- package/lib/runtime/run_test_run_hooks.d.ts +3 -0
- package/lib/runtime/run_test_run_hooks.js +28 -0
- package/lib/runtime/run_test_run_hooks.js.map +1 -0
- package/lib/runtime/step_runner.d.ts +16 -0
- package/lib/runtime/step_runner.js +88 -0
- package/lib/runtime/step_runner.js.map +1 -0
- package/lib/runtime/stopwatch.d.ts +12 -0
- package/lib/runtime/stopwatch.js +34 -0
- package/lib/runtime/stopwatch.js.map +1 -0
- package/lib/runtime/test_case_runner.d.ts +55 -0
- package/lib/runtime/test_case_runner.js +277 -0
- package/lib/runtime/test_case_runner.js.map +1 -0
- package/lib/step_arguments.d.ts +6 -0
- package/lib/step_arguments.js +19 -0
- package/lib/step_arguments.js.map +1 -0
- package/lib/support_code_library_builder/build_parameter_type.d.ts +3 -0
- package/lib/support_code_library_builder/build_parameter_type.js +13 -0
- package/lib/support_code_library_builder/build_parameter_type.js.map +1 -0
- package/lib/support_code_library_builder/get_definition_line_and_uri.d.ts +3 -0
- package/lib/support_code_library_builder/get_definition_line_and_uri.js +29 -0
- package/lib/support_code_library_builder/get_definition_line_and_uri.js.map +1 -0
- package/lib/support_code_library_builder/index.d.ts +74 -0
- package/lib/support_code_library_builder/index.js +304 -0
- package/lib/support_code_library_builder/index.js.map +1 -0
- package/lib/support_code_library_builder/parallel_can_assign_helpers.d.ts +2 -0
- package/lib/support_code_library_builder/parallel_can_assign_helpers.js +16 -0
- package/lib/support_code_library_builder/parallel_can_assign_helpers.js.map +1 -0
- package/lib/support_code_library_builder/sourced_parameter_type_registry.d.ts +7 -0
- package/lib/support_code_library_builder/sourced_parameter_type_registry.js +19 -0
- package/lib/support_code_library_builder/sourced_parameter_type_registry.js.map +1 -0
- package/lib/support_code_library_builder/types.d.ts +88 -0
- package/lib/support_code_library_builder/types.js +3 -0
- package/lib/support_code_library_builder/types.js.map +1 -0
- package/lib/support_code_library_builder/validate_arguments.d.ts +12 -0
- package/lib/support_code_library_builder/validate_arguments.js +73 -0
- package/lib/support_code_library_builder/validate_arguments.js.map +1 -0
- package/lib/support_code_library_builder/world.d.ts +18 -0
- package/lib/support_code_library_builder/world.js +11 -0
- package/lib/support_code_library_builder/world.js.map +1 -0
- package/lib/time.d.ts +18 -0
- package/lib/time.js +61 -0
- package/lib/time.js.map +1 -0
- package/lib/try_require.d.ts +7 -0
- package/lib/try_require.js +26 -0
- package/lib/try_require.js.map +1 -0
- package/lib/types/index.d.ts +4 -0
- package/lib/types/index.js +3 -0
- package/lib/types/index.js.map +1 -0
- package/lib/uncaught_exception_manager.d.ts +7 -0
- package/lib/uncaught_exception_manager.js +12 -0
- package/lib/uncaught_exception_manager.js.map +1 -0
- package/lib/user_code_runner.d.ts +14 -0
- package/lib/user_code_runner.js +82 -0
- package/lib/user_code_runner.js.map +1 -0
- package/lib/value_checker.d.ts +3 -0
- package/lib/value_checker.js +19 -0
- package/lib/value_checker.js.map +1 -0
- package/lib/version.d.ts +1 -0
- package/lib/version.js +6 -0
- package/lib/version.js.map +1 -0
- package/lib/wrapper.mjs +44 -0
- package/package.json +197 -0
|
@@ -0,0 +1,237 @@
|
|
|
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
|
+
exports.RunUploadService = void 0;
|
|
8
|
+
const fs_1 = require("fs");
|
|
9
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
10
|
+
const axios_client_1 = require("../../configuration/axios_client");
|
|
11
|
+
const path_1 = __importDefault(require("path"));
|
|
12
|
+
const bvt_analysis_formatter_1 = require("../bvt_analysis_formatter");
|
|
13
|
+
const constants_1 = require("./constants");
|
|
14
|
+
const REPORT_SERVICE_URL = (_a = process.env.REPORT_SERVICE_URL) !== null && _a !== void 0 ? _a : URL;
|
|
15
|
+
const BATCH_SIZE = 10;
|
|
16
|
+
const MAX_RETRIES = 3;
|
|
17
|
+
const REPORT_SERVICE_TOKEN = (_b = process.env.TOKEN) !== null && _b !== void 0 ? _b : process.env.REPORT_SERVICE_TOKEN;
|
|
18
|
+
class RunUploadService {
|
|
19
|
+
constructor(runsApiBaseURL, accessToken) {
|
|
20
|
+
this.runsApiBaseURL = runsApiBaseURL;
|
|
21
|
+
this.accessToken = accessToken;
|
|
22
|
+
}
|
|
23
|
+
async createRunDocument(name) {
|
|
24
|
+
try {
|
|
25
|
+
const runDocResult = await axios_client_1.axiosClient.post(this.runsApiBaseURL + '/cucumber-runs/create', {
|
|
26
|
+
name: name ? name : 'TEST',
|
|
27
|
+
}, {
|
|
28
|
+
headers: {
|
|
29
|
+
Authorization: 'Bearer ' + this.accessToken,
|
|
30
|
+
'x-source': 'cucumber_js',
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
if (runDocResult.status !== 200) {
|
|
34
|
+
throw new Error('Failed to create run document in the server');
|
|
35
|
+
}
|
|
36
|
+
if (runDocResult.data.status !== true) {
|
|
37
|
+
throw new Error('Failed to create run document in the server');
|
|
38
|
+
}
|
|
39
|
+
return runDocResult.data.run;
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
if (error.response && error.response.status === 403) {
|
|
43
|
+
console.log('Warning: Your trial plan has ended. Cannot create or upload reports.');
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
throw new Error('Failed to create run document in the server: ' + error);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async upload(formData) {
|
|
50
|
+
const response = await axios_client_1.axiosClient.post(this.runsApiBaseURL + '/cucumber-runs/upload', formData, {
|
|
51
|
+
headers: {
|
|
52
|
+
...formData.getHeaders(),
|
|
53
|
+
Authorization: 'Bearer ' + this.accessToken,
|
|
54
|
+
'x-source': 'cucumber_js',
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
if (response.status === 401) {
|
|
58
|
+
console.log('Warning: Your trial plan has ended. Cannot upload reports and perform retraining');
|
|
59
|
+
throw new Error('Warning: Your trial plan has ended. Cannot upload reports and perform retraining');
|
|
60
|
+
}
|
|
61
|
+
if (response.status !== 200) {
|
|
62
|
+
throw new Error('Failed to upload run to the server');
|
|
63
|
+
}
|
|
64
|
+
if (response.data.status !== true) {
|
|
65
|
+
throw new Error('Failed to upload run to the server');
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async getPreSignedUrls(fileUris, runId) {
|
|
69
|
+
const response = await axios_client_1.axiosClient.post(this.runsApiBaseURL + '/cucumber-runs/generateuploadurls', {
|
|
70
|
+
fileUris,
|
|
71
|
+
runId,
|
|
72
|
+
}, {
|
|
73
|
+
headers: {
|
|
74
|
+
Authorization: 'Bearer ' + this.accessToken,
|
|
75
|
+
'x-source': 'cucumber_js',
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
if (response.status === 403) {
|
|
79
|
+
console.log('Warning: Your trial plan has ended. Cannot upload reports and perform retraining');
|
|
80
|
+
throw new Error('Warning: Your trial plan has ended. Cannot upload reports and perform retraining');
|
|
81
|
+
}
|
|
82
|
+
if (response.status !== 200) {
|
|
83
|
+
throw new Error('Failed to get pre-signed urls for the files');
|
|
84
|
+
}
|
|
85
|
+
if (response.data.status !== true) {
|
|
86
|
+
throw new Error('Failed to get pre-signed urls for the files');
|
|
87
|
+
}
|
|
88
|
+
return response.data.uploadUrls;
|
|
89
|
+
}
|
|
90
|
+
async uploadTestCase(testCaseReport, runId, projectId, reportFolder, rerunId) {
|
|
91
|
+
const fileUris = [];
|
|
92
|
+
//iterate over all the files in the JsonCommand.screenshotId and insert them into the fileUris array
|
|
93
|
+
for (const step of testCaseReport.steps) {
|
|
94
|
+
for (const command of step.commands) {
|
|
95
|
+
if (command.screenshotId) {
|
|
96
|
+
fileUris.push('screenshots' + '/' + String(command.screenshotId) + '.png');
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const preSignedUrls = await this.getPreSignedUrls(fileUris, runId);
|
|
101
|
+
//upload all the files in the fileUris array
|
|
102
|
+
try {
|
|
103
|
+
for (let i = 0; i < fileUris.length; i += BATCH_SIZE) {
|
|
104
|
+
const batch = fileUris.slice(i, Math.min(i + BATCH_SIZE, fileUris.length));
|
|
105
|
+
await Promise.all(batch
|
|
106
|
+
.filter((fileUri) => preSignedUrls[fileUri])
|
|
107
|
+
.map(async (fileUri) => {
|
|
108
|
+
for (let j = 0; j < MAX_RETRIES; j++) {
|
|
109
|
+
if ((0, fs_1.existsSync)(path_1.default.join(reportFolder, fileUri))) {
|
|
110
|
+
const success = await this.uploadFile(path_1.default.join(reportFolder, fileUri), preSignedUrls[fileUri]);
|
|
111
|
+
if (success) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
console.error('Failed to upload file:', fileUri);
|
|
117
|
+
}));
|
|
118
|
+
}
|
|
119
|
+
const { data } = await axios_client_1.axiosClient.post(this.runsApiBaseURL + '/cucumber-runs/createNewTestCase', {
|
|
120
|
+
runId,
|
|
121
|
+
projectId,
|
|
122
|
+
testProgressReport: testCaseReport,
|
|
123
|
+
mode: process.env.MODE === 'cloud' ? 'cloud' : 'local',
|
|
124
|
+
browser: process.env.BROWSER ? process.env.BROWSER : 'chromium',
|
|
125
|
+
rerunId,
|
|
126
|
+
}, {
|
|
127
|
+
headers: {
|
|
128
|
+
Authorization: 'Bearer ' + this.accessToken,
|
|
129
|
+
'x-source': 'cucumber_js',
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
try {
|
|
133
|
+
await axios_client_1.axiosClient.post(`${constants_1.SERVICES_URI.STORAGE}/event`, {
|
|
134
|
+
event: constants_1.ActionEvents.upload_report,
|
|
135
|
+
}, {
|
|
136
|
+
headers: {
|
|
137
|
+
Authorization: 'Bearer ' + this.accessToken,
|
|
138
|
+
'x-source': 'cucumber_js',
|
|
139
|
+
'x-bvt-project-id': projectId,
|
|
140
|
+
},
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
// no event tracking
|
|
145
|
+
}
|
|
146
|
+
(0, bvt_analysis_formatter_1.logReportLink)(runId, projectId);
|
|
147
|
+
return data;
|
|
148
|
+
}
|
|
149
|
+
catch (e) {
|
|
150
|
+
console.error(`failed to upload the test case: ${testCaseReport.id} ${e}`);
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
async uploadFile(filePath, preSignedUrl) {
|
|
155
|
+
const fileStream = (0, fs_1.createReadStream)(filePath);
|
|
156
|
+
let success = true;
|
|
157
|
+
try {
|
|
158
|
+
const fileStats = await promises_1.default.stat(filePath);
|
|
159
|
+
const fileSize = fileStats.size;
|
|
160
|
+
await axios_client_1.axiosClient.put(preSignedUrl, fileStream, {
|
|
161
|
+
headers: {
|
|
162
|
+
'Content-Type': 'application/octet-stream',
|
|
163
|
+
'Content-Length': fileSize,
|
|
164
|
+
},
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
if (process.env.NODE_ENV_BLINQ === 'dev') {
|
|
169
|
+
console.error('Error uploading file:', error);
|
|
170
|
+
}
|
|
171
|
+
success = false;
|
|
172
|
+
}
|
|
173
|
+
finally {
|
|
174
|
+
fileStream.close();
|
|
175
|
+
}
|
|
176
|
+
return success;
|
|
177
|
+
}
|
|
178
|
+
async uploadComplete(runId, projectId) {
|
|
179
|
+
const response = await axios_client_1.axiosClient.post(this.runsApiBaseURL + '/cucumber-runs/uploadCompletion', {
|
|
180
|
+
runId,
|
|
181
|
+
projectId,
|
|
182
|
+
mode: process.env.MODE === 'cloud' ? 'cloud' : 'local',
|
|
183
|
+
browser: process.env.BROWSER ? process.env.BROWSER : 'chromium',
|
|
184
|
+
}, {
|
|
185
|
+
headers: {
|
|
186
|
+
Authorization: 'Bearer ' + this.accessToken,
|
|
187
|
+
'x-source': 'cucumber_js',
|
|
188
|
+
},
|
|
189
|
+
});
|
|
190
|
+
if (response.status !== 200) {
|
|
191
|
+
throw new Error('Failed to mark run as complete');
|
|
192
|
+
}
|
|
193
|
+
if (response.data.status !== true) {
|
|
194
|
+
throw new Error('Failed to mark run as complete');
|
|
195
|
+
}
|
|
196
|
+
try {
|
|
197
|
+
await axios_client_1.axiosClient.post(`${constants_1.SERVICES_URI.STORAGE}/event`, {
|
|
198
|
+
event: constants_1.ActionEvents.upload_report,
|
|
199
|
+
}, {
|
|
200
|
+
headers: {
|
|
201
|
+
Authorization: 'Bearer ' + this.accessToken,
|
|
202
|
+
'x-source': 'cucumber_js',
|
|
203
|
+
'x-bvt-project-id': projectId,
|
|
204
|
+
},
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
catch (error) {
|
|
208
|
+
// no event tracking
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
async modifyTestCase(runId, projectId, testProgressReport) {
|
|
212
|
+
try {
|
|
213
|
+
const res = await axios_client_1.axiosClient.post(this.runsApiBaseURL + '/cucumber-runs/modifyTestCase', {
|
|
214
|
+
runId,
|
|
215
|
+
projectId,
|
|
216
|
+
testProgressReport,
|
|
217
|
+
}, {
|
|
218
|
+
headers: {
|
|
219
|
+
Authorization: 'Bearer ' + this.accessToken,
|
|
220
|
+
'x-source': 'cucumber_js',
|
|
221
|
+
},
|
|
222
|
+
});
|
|
223
|
+
if (res.status !== 200) {
|
|
224
|
+
throw new Error('');
|
|
225
|
+
}
|
|
226
|
+
if (res.data.status !== true) {
|
|
227
|
+
throw new Error('');
|
|
228
|
+
}
|
|
229
|
+
(0, bvt_analysis_formatter_1.logReportLink)(runId, projectId);
|
|
230
|
+
}
|
|
231
|
+
catch (e) {
|
|
232
|
+
console.error(`failed to modify the test case: ${testProgressReport.id} ${e}`);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
exports.RunUploadService = RunUploadService;
|
|
237
|
+
//# sourceMappingURL=upload_serivce.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upload_serivce.js","sourceRoot":"","sources":["../../../src/formatter/helpers/upload_serivce.ts"],"names":[],"mappings":";;;;;;;AAEA,2BAAiD;AACjD,2DAA4B;AAG5B,mEAA8D;AAC9D,gDAAuB;AACvB,sEAAyD;AACzD,2CAAwD;AAExD,MAAM,kBAAkB,GAAG,MAAA,OAAO,CAAC,GAAG,CAAC,kBAAkB,mCAAI,GAAG,CAAA;AAChE,MAAM,UAAU,GAAG,EAAE,CAAA;AACrB,MAAM,WAAW,GAAG,CAAC,CAAA;AACrB,MAAM,oBAAoB,GACxB,MAAA,OAAO,CAAC,GAAG,CAAC,KAAK,mCAAI,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAA;AAevD,MAAM,gBAAgB;IACpB,YAAoB,cAAsB,EAAU,WAAmB;QAAnD,mBAAc,GAAd,cAAc,CAAQ;QAAU,gBAAW,GAAX,WAAW,C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,CAAA;SACF;IACH,CAAC;CACF;AAEQ,4CAAgB","sourcesContent":["/* eslint-disable no-console */\nimport FormData from 'form-data'\nimport { createReadStream, existsSync } from 'fs'\nimport fs from 'fs/promises'\n\nimport { JsonReport, JsonTestProgress } from './report_generator'\nimport { axiosClient } from '../../configuration/axios_client'\nimport path from 'path'\nimport { logReportLink } from '../bvt_analysis_formatter'\nimport { ActionEvents, SERVICES_URI } from './constants'\n\nconst REPORT_SERVICE_URL = process.env.REPORT_SERVICE_URL ?? URL\nconst BATCH_SIZE = 10\nconst MAX_RETRIES = 3\nconst REPORT_SERVICE_TOKEN =\n process.env.TOKEN ?? process.env.REPORT_SERVICE_TOKEN\n\nexport interface RootCauseProps {\n status: boolean\n analysis: string\n failedStep: number\n failClass: string\n}\n\nexport interface FinishTestCaseResponse {\n status: true\n rootCause: RootCauseProps\n report: JsonTestProgress\n}\n\nclass RunUploadService {\n constructor(private runsApiBaseURL: string, private accessToken: string) {}\n async createRunDocument(name: string) {\n try {\n const runDocResult = await axiosClient.post(\n this.runsApiBaseURL + '/cucumber-runs/create',\n {\n name: name ? name : 'TEST',\n },\n {\n headers: {\n Authorization: 'Bearer ' + this.accessToken,\n 'x-source': 'cucumber_js',\n },\n }\n )\n if (runDocResult.status !== 200) {\n throw new Error('Failed to create run document in the server')\n }\n if (runDocResult.data.status !== true) {\n throw new Error('Failed to create run document in the server')\n }\n return runDocResult.data.run\n } catch (error) {\n if (error.response && error.response.status === 403) {\n console.log(\n 'Warning: Your trial plan has ended. Cannot create or upload reports.'\n )\n process.exit(1)\n }\n throw new Error('Failed to create run document in the server: ' + error)\n }\n }\n async upload(formData: FormData) {\n const response = await axiosClient.post(\n this.runsApiBaseURL + '/cucumber-runs/upload',\n formData,\n {\n headers: {\n ...formData.getHeaders(),\n Authorization: 'Bearer ' + this.accessToken,\n 'x-source': 'cucumber_js',\n },\n }\n )\n if (response.status === 401) {\n console.log(\n 'Warning: Your trial plan has ended. Cannot upload reports and perform retraining'\n )\n throw new Error(\n 'Warning: Your trial plan has ended. Cannot upload reports and perform retraining'\n )\n }\n if (response.status !== 200) {\n throw new Error('Failed to upload run to the server')\n }\n if (response.data.status !== true) {\n throw new Error('Failed to upload run to the server')\n }\n }\n async getPreSignedUrls(fileUris: string[], runId: string) {\n const response = await axiosClient.post(\n this.runsApiBaseURL + '/cucumber-runs/generateuploadurls',\n {\n fileUris,\n runId,\n },\n {\n headers: {\n Authorization: 'Bearer ' + this.accessToken,\n 'x-source': 'cucumber_js',\n },\n }\n )\n if (response.status === 403) {\n console.log(\n 'Warning: Your trial plan has ended. Cannot upload reports and perform retraining'\n )\n throw new Error(\n 'Warning: Your trial plan has ended. Cannot upload reports and perform retraining'\n )\n }\n if (response.status !== 200) {\n throw new Error('Failed to get pre-signed urls for the files')\n }\n if (response.data.status !== true) {\n throw new Error('Failed to get pre-signed urls for the files')\n }\n\n return response.data.uploadUrls\n }\n\n async uploadTestCase(\n testCaseReport: JsonTestProgress,\n runId: string,\n projectId: string,\n reportFolder: string,\n rerunId?: string\n ) {\n const fileUris = []\n //iterate over all the files in the JsonCommand.screenshotId and insert them into the fileUris array\n for (const step of testCaseReport.steps) {\n for (const command of step.commands) {\n if (command.screenshotId) {\n fileUris.push(\n 'screenshots' + '/' + String(command.screenshotId) + '.png'\n )\n }\n }\n }\n const preSignedUrls = await this.getPreSignedUrls(fileUris, runId)\n //upload all the files in the fileUris array\n try {\n for (let i = 0; i < fileUris.length; i += BATCH_SIZE) {\n const batch = fileUris.slice(\n i,\n Math.min(i + BATCH_SIZE, fileUris.length)\n )\n await Promise.all(\n batch\n .filter((fileUri) => preSignedUrls[fileUri])\n .map(async (fileUri) => {\n for (let j = 0; j < MAX_RETRIES; j++) {\n if (existsSync(path.join(reportFolder, fileUri))) {\n const success = await this.uploadFile(\n path.join(reportFolder, fileUri),\n preSignedUrls[fileUri]\n )\n if (success) {\n return\n }\n }\n }\n console.error('Failed to upload file:', fileUri)\n })\n )\n }\n const { data } = await axiosClient.post<FinishTestCaseResponse>(\n this.runsApiBaseURL + '/cucumber-runs/createNewTestCase',\n {\n runId,\n projectId,\n testProgressReport: testCaseReport,\n mode: process.env.MODE === 'cloud' ? 'cloud' : 'local',\n browser: process.env.BROWSER ? process.env.BROWSER : 'chromium',\n rerunId,\n },\n {\n headers: {\n Authorization: 'Bearer ' + this.accessToken,\n 'x-source': 'cucumber_js',\n },\n }\n )\n\n try {\n await axiosClient.post(\n `${SERVICES_URI.STORAGE}/event`,\n {\n event: ActionEvents.upload_report,\n },\n {\n headers: {\n Authorization: 'Bearer ' + this.accessToken,\n 'x-source': 'cucumber_js',\n 'x-bvt-project-id': projectId,\n },\n }\n )\n } catch (error) {\n // no event tracking\n }\n logReportLink(runId, projectId)\n return data\n } catch (e) {\n console.error(`failed to upload the test case: ${testCaseReport.id} ${e}`)\n return null\n }\n }\n async uploadFile(filePath: string, preSignedUrl: string) {\n const fileStream = createReadStream(filePath)\n let success = true\n try {\n const fileStats = await fs.stat(filePath)\n const fileSize = fileStats.size\n\n await axiosClient.put(preSignedUrl, fileStream, {\n headers: {\n 'Content-Type': 'application/octet-stream',\n 'Content-Length': fileSize,\n },\n })\n } catch (error) {\n if (process.env.NODE_ENV_BLINQ === 'dev') {\n console.error('Error uploading file:', error)\n }\n success = false\n } finally {\n fileStream.close()\n }\n return success\n }\n async uploadComplete(runId: string, projectId: string) {\n const response = await axiosClient.post(\n this.runsApiBaseURL + '/cucumber-runs/uploadCompletion',\n {\n runId,\n projectId,\n mode: process.env.MODE === 'cloud' ? 'cloud' : 'local',\n browser: process.env.BROWSER ? process.env.BROWSER : 'chromium',\n },\n {\n headers: {\n Authorization: 'Bearer ' + this.accessToken,\n 'x-source': 'cucumber_js',\n },\n }\n )\n if (response.status !== 200) {\n throw new Error('Failed to mark run as complete')\n }\n if (response.data.status !== true) {\n throw new Error('Failed to mark run as complete')\n }\n\n try {\n await axiosClient.post(\n `${SERVICES_URI.STORAGE}/event`,\n {\n event: ActionEvents.upload_report,\n },\n {\n headers: {\n Authorization: 'Bearer ' + this.accessToken,\n 'x-source': 'cucumber_js',\n 'x-bvt-project-id': projectId,\n },\n }\n )\n } catch (error) {\n // no event tracking\n }\n }\n async modifyTestCase(\n runId: string,\n projectId: string,\n testProgressReport: JsonTestProgress\n ) {\n try {\n const res = await axiosClient.post(\n this.runsApiBaseURL + '/cucumber-runs/modifyTestCase',\n {\n runId,\n projectId,\n testProgressReport,\n },\n {\n headers: {\n Authorization: 'Bearer ' + this.accessToken,\n 'x-source': 'cucumber_js',\n },\n }\n )\n if (res.status !== 200) {\n throw new Error('')\n }\n if (res.data.status !== true) {\n throw new Error('')\n }\n logReportLink(runId, projectId)\n } catch (e) {\n console.error(\n `failed to modify the test case: ${testProgressReport.id} ${e}`\n )\n }\n }\n}\n\nexport { RunUploadService }\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import ReportGenerator, { JsonReport, JsonTestProgress } from './report_generator';
|
|
2
|
+
export default class ReportUploader {
|
|
3
|
+
private uploadService;
|
|
4
|
+
private reportGenerator;
|
|
5
|
+
constructor(reportGenerator: ReportGenerator);
|
|
6
|
+
uploadRun(report: JsonReport, runName: string): Promise<{
|
|
7
|
+
runId: any;
|
|
8
|
+
projectId: any;
|
|
9
|
+
}>;
|
|
10
|
+
modifyTestCase(testCase: JsonTestProgress): Promise<void>;
|
|
11
|
+
createZip(reportFolder: string | null, report: JsonReport): Promise<string>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
var _a, _b;
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
const upload_serivce_1 = require("./upload_serivce");
|
|
31
|
+
const form_data_1 = __importDefault(require("form-data"));
|
|
32
|
+
const fs_1 = __importStar(require("fs"));
|
|
33
|
+
const jszip_1 = __importDefault(require("jszip"));
|
|
34
|
+
const path_1 = __importDefault(require("path"));
|
|
35
|
+
let URL;
|
|
36
|
+
switch (process.env.NODE_ENV_BLINQ) {
|
|
37
|
+
case 'stage':
|
|
38
|
+
URL = 'https://stage.api.blinq.io/api/runs';
|
|
39
|
+
break;
|
|
40
|
+
case 'dev':
|
|
41
|
+
URL = 'https://dev.api.blinq.io/api/runs';
|
|
42
|
+
break;
|
|
43
|
+
case 'local':
|
|
44
|
+
URL = 'http://localhost:5001/api/runs';
|
|
45
|
+
break;
|
|
46
|
+
default:
|
|
47
|
+
URL = 'https://api.blinq.io/api/runs';
|
|
48
|
+
}
|
|
49
|
+
const REPORT_SERVICE_URL = (_a = process.env.REPORT_SERVICE_URL) !== null && _a !== void 0 ? _a : URL;
|
|
50
|
+
const BATCH_SIZE = 10;
|
|
51
|
+
const MAX_RETRIES = 3;
|
|
52
|
+
const REPORT_SERVICE_TOKEN = (_b = process.env.TOKEN) !== null && _b !== void 0 ? _b : process.env.REPORT_SERVICE_TOKEN;
|
|
53
|
+
class ReportUploader {
|
|
54
|
+
constructor(reportGenerator) {
|
|
55
|
+
this.uploadService = new upload_serivce_1.RunUploadService(REPORT_SERVICE_URL, REPORT_SERVICE_TOKEN);
|
|
56
|
+
if (!REPORT_SERVICE_URL || !REPORT_SERVICE_TOKEN) {
|
|
57
|
+
throw new Error('REPORT_SERVICE_URL and REPORT_SERVICE_TOKEN must be set');
|
|
58
|
+
}
|
|
59
|
+
this.reportGenerator = reportGenerator;
|
|
60
|
+
}
|
|
61
|
+
async uploadRun(report, runName) {
|
|
62
|
+
const runDoc = await this.uploadService.createRunDocument(runName);
|
|
63
|
+
const runDocId = runDoc._id;
|
|
64
|
+
const reportFolder = this.reportGenerator.reportFolder;
|
|
65
|
+
if (!fs_1.default.existsSync(reportFolder)) {
|
|
66
|
+
fs_1.default.mkdirSync(reportFolder);
|
|
67
|
+
}
|
|
68
|
+
(0, fs_1.writeFileSync)(path_1.default.join(reportFolder, 'report.json'), JSON.stringify(report, null, 2));
|
|
69
|
+
if (process.env.NODE_ENV_BLINQ === 'local') {
|
|
70
|
+
const formData = new form_data_1.default();
|
|
71
|
+
const zipPath = await this.createZip(reportFolder, report);
|
|
72
|
+
formData.append(runDocId, fs_1.default.readFileSync(zipPath), 'report.zip');
|
|
73
|
+
await this.uploadService.upload(formData);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
const fileUris = [
|
|
77
|
+
...getFileUris(reportFolder, 'screenshots'),
|
|
78
|
+
...getFileUris(reportFolder, 'trace'),
|
|
79
|
+
'report.json',
|
|
80
|
+
'network.json',
|
|
81
|
+
];
|
|
82
|
+
try {
|
|
83
|
+
const preSignedUrls = await this.uploadService.getPreSignedUrls(fileUris, runDocId);
|
|
84
|
+
for (let i = 0; i < fileUris.length; i += BATCH_SIZE) {
|
|
85
|
+
const batch = fileUris.slice(i, Math.min(i + BATCH_SIZE, fileUris.length));
|
|
86
|
+
await Promise.all(batch
|
|
87
|
+
.filter((fileUri) => preSignedUrls[fileUri])
|
|
88
|
+
.map(async (fileUri) => {
|
|
89
|
+
for (let j = 0; j < MAX_RETRIES; j++) {
|
|
90
|
+
const success = await this.uploadService.uploadFile(path_1.default.join(reportFolder, fileUri), preSignedUrls[fileUri]);
|
|
91
|
+
if (success) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
console.error('Failed to upload file:', fileUri);
|
|
96
|
+
}));
|
|
97
|
+
}
|
|
98
|
+
await this.uploadService.uploadComplete(runDocId, runDoc.project_id);
|
|
99
|
+
}
|
|
100
|
+
catch (err) {
|
|
101
|
+
throw new Error('Failed to upload all the files');
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return { runId: runDoc._id, projectId: runDoc.project_id };
|
|
105
|
+
}
|
|
106
|
+
async modifyTestCase(testCase) {
|
|
107
|
+
const runId = process.env.RUN_ID;
|
|
108
|
+
if (!runId) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const projectId = process.env.PROJECT_ID;
|
|
112
|
+
if (!projectId) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
await this.uploadService.modifyTestCase(runId, projectId, testCase);
|
|
116
|
+
}
|
|
117
|
+
async createZip(reportFolder, report) {
|
|
118
|
+
if (reportFolder === null) {
|
|
119
|
+
console.error('report folder is empty');
|
|
120
|
+
console.error('it is likey that there are no scenarios to run');
|
|
121
|
+
throw new Error('Empty report folder');
|
|
122
|
+
}
|
|
123
|
+
const zip = new jszip_1.default();
|
|
124
|
+
zip.file('report.json', JSON.stringify(report, null, 2));
|
|
125
|
+
const folder = zip.folder('screenshots');
|
|
126
|
+
const files = fs_1.default.readdirSync(path_1.default.join(reportFolder, 'screenshots'));
|
|
127
|
+
files.forEach((file) => {
|
|
128
|
+
folder.file(file, fs_1.default.readFileSync(path_1.default.join(reportFolder, 'screenshots', file)));
|
|
129
|
+
});
|
|
130
|
+
const zipBuffer = await zip.generateAsync({ type: 'nodebuffer' });
|
|
131
|
+
// save zip file
|
|
132
|
+
const zipPath = path_1.default.join(reportFolder, 'report.zip');
|
|
133
|
+
fs_1.default.writeFileSync(zipPath, new Uint8Array(zipBuffer));
|
|
134
|
+
fs_1.default.writeFileSync(path_1.default.join(reportFolder, 'report.json'), JSON.stringify(report, null, 2));
|
|
135
|
+
return zipPath;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
exports.default = ReportUploader;
|
|
139
|
+
const getFileUrisScreenShotDir = (reportFolder) => {
|
|
140
|
+
const files = fs_1.default.readdirSync(path_1.default.join(reportFolder, 'screenshots'));
|
|
141
|
+
return files.map((file) => ['screenshots', file].join('/'));
|
|
142
|
+
};
|
|
143
|
+
const getFileUris = (reportFolder, targetFolder) => {
|
|
144
|
+
const resultFolder = path_1.default.join(reportFolder, targetFolder);
|
|
145
|
+
if (!fs_1.default.existsSync(resultFolder)) {
|
|
146
|
+
return [];
|
|
147
|
+
}
|
|
148
|
+
const files = fs_1.default.readdirSync(resultFolder);
|
|
149
|
+
return files.map((file) => [targetFolder, file].join('/'));
|
|
150
|
+
};
|
|
151
|
+
//# sourceMappingURL=uploader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uploader.js","sourceRoot":"","sources":["../../../src/formatter/helpers/uploader.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,qDAAmD;AAEnD,0DAAgC;AAChC,yCAAsC;AACtC,kDAAyB;AACzB,gDAAuB;AAEvB,IAAI,GAAG,CAAA;AAEP,QAAQ,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE;IAClC,KAAK,OAAO;QACV,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,CAAC,CAAC,CAAA;AAC7D,CAAC,CAAA;AAED,MAAM,WAAW,GAAG,CAAC,YAAoB,EAAE,YAAoB,EAAE,EAAE;IACjE,MAAM,YAAY,GAAG,cAAI,CAAC,IAAI,CAAC,YAAY,EAAE,YAAY,CAAC,CAAA;IAC1D,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE;QAChC,OAAO,EAAE,CAAA;KACV;IACD,MAAM,KAAK,GAAG,YAAE,CAAC,WAAW,CAAC,YAAY,CAAC,CAAA;IAC1C,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;AAC5D,CAAC,CAAA","sourcesContent":["import axios from 'axios'\nimport ReportGenerator, {\n JsonReport,\n JsonTestProgress,\n} from './report_generator'\nimport { RunUploadService } from './upload_serivce'\n\nimport FormData from 'form-data'\nimport fs, { writeFileSync } from 'fs'\nimport JSZip from 'jszip'\nimport path from 'path'\n\nlet URL\n\nswitch (process.env.NODE_ENV_BLINQ) {\n case 'stage':\n URL = 'https://stage.api.blinq.io/api/runs'\n break\n case 'dev':\n URL = 'https://dev.api.blinq.io/api/runs'\n break\n case 'local':\n URL = 'http://localhost:5001/api/runs'\n break\n default:\n URL = 'https://api.blinq.io/api/runs'\n}\n\nconst REPORT_SERVICE_URL = process.env.REPORT_SERVICE_URL ?? URL\nconst BATCH_SIZE = 10\nconst MAX_RETRIES = 3\nconst REPORT_SERVICE_TOKEN =\n process.env.TOKEN ?? process.env.REPORT_SERVICE_TOKEN\n\nexport default class ReportUploader {\n private uploadService = new RunUploadService(\n REPORT_SERVICE_URL,\n REPORT_SERVICE_TOKEN\n )\n private reportGenerator: ReportGenerator\n constructor(reportGenerator: ReportGenerator) {\n if (!REPORT_SERVICE_URL || !REPORT_SERVICE_TOKEN) {\n throw new Error('REPORT_SERVICE_URL and REPORT_SERVICE_TOKEN must be set')\n }\n this.reportGenerator = reportGenerator\n }\n\n async uploadRun(report: JsonReport, runName: string) {\n const runDoc = await this.uploadService.createRunDocument(runName)\n const runDocId = runDoc._id\n const reportFolder = this.reportGenerator.reportFolder\n if (!fs.existsSync(reportFolder)) {\n fs.mkdirSync(reportFolder)\n }\n writeFileSync(\n path.join(reportFolder, 'report.json'),\n JSON.stringify(report, null, 2)\n )\n if (process.env.NODE_ENV_BLINQ === 'local') {\n const formData = new FormData()\n const zipPath = await this.createZip(reportFolder, report)\n formData.append(runDocId, fs.readFileSync(zipPath), 'report.zip')\n await this.uploadService.upload(formData)\n } else {\n const fileUris = [\n ...getFileUris(reportFolder, 'screenshots'),\n ...getFileUris(reportFolder, 'trace'),\n 'report.json',\n 'network.json',\n ]\n try {\n const preSignedUrls = await this.uploadService.getPreSignedUrls(\n fileUris,\n runDocId\n )\n\n for (let i = 0; i < fileUris.length; i += BATCH_SIZE) {\n const batch = fileUris.slice(\n i,\n Math.min(i + BATCH_SIZE, fileUris.length)\n )\n await Promise.all(\n batch\n .filter((fileUri) => preSignedUrls[fileUri])\n .map(async (fileUri) => {\n for (let j = 0; j < MAX_RETRIES; j++) {\n const success = await this.uploadService.uploadFile(\n path.join(reportFolder, fileUri),\n preSignedUrls[fileUri]\n )\n if (success) {\n return\n }\n }\n console.error('Failed to upload file:', fileUri)\n })\n )\n }\n await this.uploadService.uploadComplete(runDocId, runDoc.project_id)\n } catch (err) {\n throw new Error('Failed to upload all the files')\n }\n }\n return { runId: runDoc._id, projectId: runDoc.project_id }\n }\n\n async modifyTestCase(testCase: JsonTestProgress) {\n const runId = process.env.RUN_ID\n if (!runId) {\n return\n }\n const projectId = process.env.PROJECT_ID\n if (!projectId) {\n return\n }\n await this.uploadService.modifyTestCase(runId, projectId, testCase)\n }\n async createZip(reportFolder: string | null, report: JsonReport) {\n if (reportFolder === null) {\n console.error('report folder is empty')\n console.error('it is likey that there are no scenarios to run')\n throw new Error('Empty report folder')\n }\n const zip = new JSZip()\n zip.file('report.json', JSON.stringify(report, null, 2))\n const folder = zip.folder('screenshots')\n const files = fs.readdirSync(path.join(reportFolder, 'screenshots'))\n files.forEach((file) => {\n folder.file(\n file,\n fs.readFileSync(path.join(reportFolder, 'screenshots', file))\n )\n })\n const zipBuffer = await zip.generateAsync({ type: 'nodebuffer' })\n // save zip file\n const zipPath = path.join(reportFolder, 'report.zip')\n fs.writeFileSync(zipPath, new Uint8Array(zipBuffer))\n fs.writeFileSync(\n path.join(reportFolder, 'report.json'),\n JSON.stringify(report, null, 2)\n )\n return zipPath\n }\n}\n\nconst getFileUrisScreenShotDir = (reportFolder: string) => {\n const files = fs.readdirSync(path.join(reportFolder, 'screenshots'))\n\n return files.map((file) => ['screenshots', file].join('/'))\n}\n\nconst getFileUris = (reportFolder: string, targetFolder: string) => {\n const resultFolder = path.join(reportFolder, targetFolder)\n if (!fs.existsSync(resultFolder)) {\n return []\n }\n const files = fs.readdirSync(resultFolder)\n return files.map((file) => [targetFolder, file].join('/'))\n}\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as messages from '@cucumber/messages';
|
|
2
|
+
import StepDefinition from '../../../models/step_definition';
|
|
3
|
+
import EventDataCollector from '../event_data_collector';
|
|
4
|
+
export interface IUsageMatch {
|
|
5
|
+
duration?: messages.Duration;
|
|
6
|
+
line: number;
|
|
7
|
+
text: string;
|
|
8
|
+
uri: string;
|
|
9
|
+
}
|
|
10
|
+
export interface IUsage {
|
|
11
|
+
code: string;
|
|
12
|
+
line: number;
|
|
13
|
+
matches: IUsageMatch[];
|
|
14
|
+
meanDuration?: messages.Duration;
|
|
15
|
+
pattern: string;
|
|
16
|
+
patternType: string;
|
|
17
|
+
uri: string;
|
|
18
|
+
}
|
|
19
|
+
export interface IGetUsageRequest {
|
|
20
|
+
eventDataCollector: EventDataCollector;
|
|
21
|
+
stepDefinitions: StepDefinition[];
|
|
22
|
+
}
|
|
23
|
+
export declare function getUsage({ stepDefinitions, eventDataCollector, }: IGetUsageRequest): IUsage[];
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.getUsage = void 0;
|
|
27
|
+
const pickle_parser_1 = require("../pickle_parser");
|
|
28
|
+
const gherkin_document_parser_1 = require("../gherkin_document_parser");
|
|
29
|
+
const messages = __importStar(require("@cucumber/messages"));
|
|
30
|
+
const value_checker_1 = require("../../../value_checker");
|
|
31
|
+
function buildEmptyMapping(stepDefinitions) {
|
|
32
|
+
const mapping = {};
|
|
33
|
+
stepDefinitions.forEach((stepDefinition) => {
|
|
34
|
+
mapping[stepDefinition.id] = {
|
|
35
|
+
code: stepDefinition.unwrappedCode.toString(),
|
|
36
|
+
line: stepDefinition.line,
|
|
37
|
+
pattern: stepDefinition.expression.source,
|
|
38
|
+
patternType: stepDefinition.expression.constructor.name,
|
|
39
|
+
matches: [],
|
|
40
|
+
uri: stepDefinition.uri,
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
return mapping;
|
|
44
|
+
}
|
|
45
|
+
const unexecutedStatuses = [
|
|
46
|
+
messages.TestStepResultStatus.AMBIGUOUS,
|
|
47
|
+
messages.TestStepResultStatus.SKIPPED,
|
|
48
|
+
messages.TestStepResultStatus.UNDEFINED,
|
|
49
|
+
];
|
|
50
|
+
function buildMapping({ stepDefinitions, eventDataCollector, }) {
|
|
51
|
+
const mapping = buildEmptyMapping(stepDefinitions);
|
|
52
|
+
eventDataCollector.getTestCaseAttempts().forEach((testCaseAttempt) => {
|
|
53
|
+
const pickleStepMap = (0, pickle_parser_1.getPickleStepMap)(testCaseAttempt.pickle);
|
|
54
|
+
const gherkinStepMap = (0, gherkin_document_parser_1.getGherkinStepMap)(testCaseAttempt.gherkinDocument);
|
|
55
|
+
testCaseAttempt.testCase.testSteps.forEach((testStep) => {
|
|
56
|
+
if ((0, value_checker_1.doesHaveValue)(testStep.pickleStepId) &&
|
|
57
|
+
testStep.stepDefinitionIds.length === 1) {
|
|
58
|
+
const stepDefinitionId = testStep.stepDefinitionIds[0];
|
|
59
|
+
const pickleStep = pickleStepMap[testStep.pickleStepId];
|
|
60
|
+
const gherkinStep = gherkinStepMap[pickleStep.astNodeIds[0]];
|
|
61
|
+
const match = {
|
|
62
|
+
line: gherkinStep.location.line,
|
|
63
|
+
text: pickleStep.text,
|
|
64
|
+
uri: testCaseAttempt.pickle.uri,
|
|
65
|
+
};
|
|
66
|
+
const { duration, status } = testCaseAttempt.stepResults[testStep.id];
|
|
67
|
+
if (!unexecutedStatuses.includes(status) && (0, value_checker_1.doesHaveValue)(duration)) {
|
|
68
|
+
match.duration = duration;
|
|
69
|
+
}
|
|
70
|
+
if ((0, value_checker_1.doesHaveValue)(mapping[stepDefinitionId])) {
|
|
71
|
+
mapping[stepDefinitionId].matches.push(match);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
return mapping;
|
|
77
|
+
}
|
|
78
|
+
function normalizeDuration(duration) {
|
|
79
|
+
if (duration == null) {
|
|
80
|
+
return Number.MIN_SAFE_INTEGER;
|
|
81
|
+
}
|
|
82
|
+
return messages.TimeConversion.durationToMilliseconds(duration);
|
|
83
|
+
}
|
|
84
|
+
function buildResult(mapping) {
|
|
85
|
+
return Object.keys(mapping)
|
|
86
|
+
.map((stepDefinitionId) => {
|
|
87
|
+
const { matches, ...rest } = mapping[stepDefinitionId];
|
|
88
|
+
const sortedMatches = matches.sort((a, b) => {
|
|
89
|
+
if (a.duration === b.duration) {
|
|
90
|
+
return a.text < b.text ? -1 : 1;
|
|
91
|
+
}
|
|
92
|
+
return normalizeDuration(b.duration) - normalizeDuration(a.duration);
|
|
93
|
+
});
|
|
94
|
+
const result = { matches: sortedMatches, ...rest };
|
|
95
|
+
const durations = matches
|
|
96
|
+
.filter((m) => m.duration != null)
|
|
97
|
+
.map((m) => m.duration);
|
|
98
|
+
if (durations.length > 0) {
|
|
99
|
+
const totalMilliseconds = durations.reduce((acc, x) => acc + messages.TimeConversion.durationToMilliseconds(x), 0);
|
|
100
|
+
result.meanDuration = messages.TimeConversion.millisecondsToDuration(totalMilliseconds / durations.length);
|
|
101
|
+
}
|
|
102
|
+
return result;
|
|
103
|
+
})
|
|
104
|
+
.sort((a, b) => normalizeDuration(b.meanDuration) - normalizeDuration(a.meanDuration));
|
|
105
|
+
}
|
|
106
|
+
function getUsage({ stepDefinitions, eventDataCollector, }) {
|
|
107
|
+
const mapping = buildMapping({ stepDefinitions, eventDataCollector });
|
|
108
|
+
return buildResult(mapping);
|
|
109
|
+
}
|
|
110
|
+
exports.getUsage = getUsage;
|
|
111
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/formatter/helpers/usage_helpers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAmD;AACnD,wEAA8D;AAC9D,6DAA8C;AAE9C,0DAAsD;AAyBtD,SAAS,iBAAiB,CACxB,eAAiC;IAEjC,MAAM,OAAO,GAA2B,EAAE,CAAA;IAC1C,eAAe,CAAC,OAAO,CAAC,CAAC,cAAc,EAAE,EAAE;QACzC,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC,GAAG;YAC3B,IAAI,EAAE,cAAc,CAAC,aAAa,CAAC,QAAQ,EAAE;YAC7C,IAAI,EAAE,cAAc,CAAC,IAAI;YACzB,OAAO,EAAE,cAAc,CAAC,UAAU,CAAC,MAAM;YACzC,WAAW,EAAE,cAAc,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI;YACvD,OAAO,EAAE,EAAE;YACX,GAAG,EAAE,cAAc,CAAC,GAAG;SACxB,CAAA;IACH,CAAC,CAAC,CAAA;IACF,OAAO,OAAO,CAAA;AAChB,CAAC;AAED,MAAM,kBAAkB,GAA6C;IACnE,QAAQ,CAAC,oBAAoB,CAAC,SAAS;IACvC,QAAQ,CAAC,oBAAoB,CAAC,OAAO;IACrC,QAAQ,CAAC,oBAAoB,CAAC,SAAS;CACxC,CAAA;AAED,SAAS,YAAY,CAAC,EACpB,eAAe,EACf,kBAAkB,GACD;IACjB,MAAM,OAAO,GAAG,iBAAiB,CAAC,eAAe,CAAC,CAAA;IAClD,kBAAkB,CAAC,mBAAmB,EAAE,CAAC,OAAO,CAAC,CAAC,eAAe,EAAE,EAAE;QACnE,MAAM,aAAa,GAAG,IAAA,gCAAgB,EAAC,eAAe,CAAC,MAAM,CAAC,CAAA;QAC9D,MAAM,cAAc,GAAG,IAAA,2CAAiB,EAAC,eAAe,CAAC,eAAe,CAAC,CAAA;QACzE,eAAe,C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CAClE,iBAAiB,GAAG,SAAS,CAAC,MAAM,CACrC,CAAA;SACF;QACD,OAAO,MAAM,CAAA;IACf,CAAC,CAAC;SACD,IAAI,CACH,CAAC,CAAS,EAAE,CAAS,EAAE,EAAE,CACvB,iBAAiB,CAAC,CAAC,CAAC,YAAY,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,YAAY,CAAC,CACxE,CAAA;AACL,CAAC;AAED,SAAgB,QAAQ,CAAC,EACvB,eAAe,EACf,kBAAkB,GACD;IACjB,MAAM,OAAO,GAAG,YAAY,CAAC,EAAE,eAAe,EAAE,kBAAkB,EAAE,CAAC,CAAA;IACrE,OAAO,WAAW,CAAC,OAAO,CAAC,CAAA;AAC7B,CAAC;AAND,4BAMC","sourcesContent":["import { getPickleStepMap } from '../pickle_parser'\nimport { getGherkinStepMap } from '../gherkin_document_parser'\nimport * as messages from '@cucumber/messages'\nimport StepDefinition from '../../../models/step_definition'\nimport { doesHaveValue } from '../../../value_checker'\nimport EventDataCollector from '../event_data_collector'\n\nexport interface IUsageMatch {\n duration?: messages.Duration\n line: number\n text: string\n uri: string\n}\n\nexport interface IUsage {\n code: string\n line: number\n matches: IUsageMatch[]\n meanDuration?: messages.Duration\n pattern: string\n patternType: string\n uri: string\n}\n\nexport interface IGetUsageRequest {\n eventDataCollector: EventDataCollector\n stepDefinitions: StepDefinition[]\n}\n\nfunction buildEmptyMapping(\n stepDefinitions: StepDefinition[]\n): Record<string, IUsage> {\n const mapping: Record<string, IUsage> = {}\n stepDefinitions.forEach((stepDefinition) => {\n mapping[stepDefinition.id] = {\n code: stepDefinition.unwrappedCode.toString(),\n line: stepDefinition.line,\n pattern: stepDefinition.expression.source,\n patternType: stepDefinition.expression.constructor.name,\n matches: [],\n uri: stepDefinition.uri,\n }\n })\n return mapping\n}\n\nconst unexecutedStatuses: readonly messages.TestStepResultStatus[] = [\n messages.TestStepResultStatus.AMBIGUOUS,\n messages.TestStepResultStatus.SKIPPED,\n messages.TestStepResultStatus.UNDEFINED,\n]\n\nfunction buildMapping({\n stepDefinitions,\n eventDataCollector,\n}: IGetUsageRequest): Record<string, IUsage> {\n const mapping = buildEmptyMapping(stepDefinitions)\n eventDataCollector.getTestCaseAttempts().forEach((testCaseAttempt) => {\n const pickleStepMap = getPickleStepMap(testCaseAttempt.pickle)\n const gherkinStepMap = getGherkinStepMap(testCaseAttempt.gherkinDocument)\n testCaseAttempt.testCase.testSteps.forEach((testStep) => {\n if (\n doesHaveValue(testStep.pickleStepId) &&\n testStep.stepDefinitionIds.length === 1\n ) {\n const stepDefinitionId = testStep.stepDefinitionIds[0]\n const pickleStep = pickleStepMap[testStep.pickleStepId]\n const gherkinStep = gherkinStepMap[pickleStep.astNodeIds[0]]\n const match: IUsageMatch = {\n line: gherkinStep.location.line,\n text: pickleStep.text,\n uri: testCaseAttempt.pickle.uri,\n }\n const { duration, status } = testCaseAttempt.stepResults[testStep.id]\n if (!unexecutedStatuses.includes(status) && doesHaveValue(duration)) {\n match.duration = duration\n }\n if (doesHaveValue(mapping[stepDefinitionId])) {\n mapping[stepDefinitionId].matches.push(match)\n }\n }\n })\n })\n return mapping\n}\n\nfunction normalizeDuration(duration?: messages.Duration): number {\n if (duration == null) {\n return Number.MIN_SAFE_INTEGER\n }\n return messages.TimeConversion.durationToMilliseconds(duration)\n}\n\nfunction buildResult(mapping: Record<string, IUsage>): IUsage[] {\n return Object.keys(mapping)\n .map((stepDefinitionId) => {\n const { matches, ...rest } = mapping[stepDefinitionId]\n const sortedMatches = matches.sort((a: IUsageMatch, b: IUsageMatch) => {\n if (a.duration === b.duration) {\n return a.text < b.text ? -1 : 1\n }\n return normalizeDuration(b.duration) - normalizeDuration(a.duration)\n })\n const result = { matches: sortedMatches, ...rest }\n const durations: messages.Duration[] = matches\n .filter((m) => m.duration != null)\n .map((m) => m.duration)\n if (durations.length > 0) {\n const totalMilliseconds = durations.reduce(\n (acc, x) => acc + messages.TimeConversion.durationToMilliseconds(x),\n 0\n )\n result.meanDuration = messages.TimeConversion.millisecondsToDuration(\n totalMilliseconds / durations.length\n )\n }\n return result\n })\n .sort(\n (a: IUsage, b: IUsage) =>\n normalizeDuration(b.meanDuration) - normalizeDuration(a.meanDuration)\n )\n}\n\nexport function getUsage({\n stepDefinitions,\n eventDataCollector,\n}: IGetUsageRequest): IUsage[] {\n const mapping = buildMapping({ stepDefinitions, eventDataCollector })\n return buildResult(mapping)\n}\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
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 _1 = __importDefault(require("."));
|
|
7
|
+
const resolve_pkg_1 = __importDefault(require("resolve-pkg"));
|
|
8
|
+
const html_formatter_1 = __importDefault(require("@cucumber/html-formatter"));
|
|
9
|
+
const stream_1 = require("stream");
|
|
10
|
+
const util_1 = require("util");
|
|
11
|
+
class HtmlFormatter extends _1.default {
|
|
12
|
+
constructor(options) {
|
|
13
|
+
super(options);
|
|
14
|
+
this._htmlStream = new html_formatter_1.default((0, resolve_pkg_1.default)('@cucumber/html-formatter', { cwd: __dirname }) +
|
|
15
|
+
'/dist/main.css', (0, resolve_pkg_1.default)('@cucumber/html-formatter', { cwd: __dirname }) +
|
|
16
|
+
'/dist/main.js');
|
|
17
|
+
options.eventBroadcaster.on('envelope', (envelope) => {
|
|
18
|
+
this._htmlStream.write(envelope);
|
|
19
|
+
});
|
|
20
|
+
this._htmlStream.on('data', (chunk) => this.log(chunk));
|
|
21
|
+
}
|
|
22
|
+
async finished() {
|
|
23
|
+
this._htmlStream.end();
|
|
24
|
+
await (0, util_1.promisify)(stream_1.finished)(this._htmlStream);
|
|
25
|
+
await super.finished();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.default = HtmlFormatter;
|
|
29
|
+
HtmlFormatter.documentation = 'Outputs HTML report';
|
|
30
|
+
//# sourceMappingURL=html_formatter.js.map
|