UNPKG

@chtsinc/ch-playwright-report

Version:

Custom Playwright Reporter that logs test and execution results to MongoDB

80 lines 4.1 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.TestReportUtil = void 0; const path_1 = __importDefault(require("path")); const ch_javascript_sdk_1 = require("@chtsinc/ch-javascript-sdk"); const test_annotations_util_1 = require("./test-annotations-util"); const execution_env_setup_1 = require("../reporter-setup/execution-env-setup"); class TestReportUtil { static createTestReport(executionContext) { const testReport = new ch_javascript_sdk_1.TestReport(executionContext.executionId, executionContext.subscriptionKey, executionContext.site); testReport.subscriptionKey = executionContext.subscriptionKey; testReport.suiteName = executionContext.suite; testReport.testType = this.resolveTestType(executionContext.testType); testReport.environmentInfo = execution_env_setup_1.ExecutionEnvSetup.createEnvironmentInfo(executionContext); return testReport; } static populateTestReport(test, result, testReport) { const annotations = test.annotations || []; testReport.startDateTime = result.startTime; testReport.setStatus(this.resolveTestStatus(result.status)); testReport.testName = test.title; testReport.testGroups = (0, test_annotations_util_1.getAnnotationDescriptions)(annotations, "tag"); testReport.testId = (0, test_annotations_util_1.getFirstAnnotationDescription)(annotations, "testId"); testReport.moduleName = (0, test_annotations_util_1.getFirstAnnotationDescription)(annotations, "module") ?? path_1.default.basename(test.location.file, path_1.default.extname(test.location.file)); testReport.priority = (0, test_annotations_util_1.getFirstAnnotationDescription)(annotations, "priority"); testReport.userStoryId = (0, test_annotations_util_1.getFirstAnnotationDescription)(annotations, "userStoryId"); // will be present for vendor session ids const sessionId = (0, test_annotations_util_1.getFirstAnnotationDescription)(annotations, "sessionId"); testReport.sessionId = sessionId ? sessionId : testReport.executionId + "-" + test.id; testReport.noOfRetries = result.retry; for (const step of result.steps || []) { const error = step.error ? new Error(step.error.message || String(step.error)) : undefined; const status = step.error ? ch_javascript_sdk_1.TestStatus.FAIL : ch_javascript_sdk_1.TestStatus.INFO; const stepInfo = new ch_javascript_sdk_1.StepInfo(step.title, status, error); stepInfo.startDateTime = step.startTime; stepInfo.endDateTime = new Date(); testReport.steps.push(stepInfo); } if (result.error) { const error = new Error(result.error.message || String(result.error)); error.stack = result.error.stack; testReport.exceptionInfo = new ch_javascript_sdk_1.ExceptionInfo(error); } return testReport; } static resolveTestType(testType) { switch (testType.toLowerCase()) { case "app": return ch_javascript_sdk_1.TestType.APP; case "api": return ch_javascript_sdk_1.TestType.API; case "web": default: return ch_javascript_sdk_1.TestType.WEB; } } static resolveTestStatus(status) { switch (status) { case "passed": return ch_javascript_sdk_1.TestStatus.PASS; case "failed": case "timedOut": return ch_javascript_sdk_1.TestStatus.FAIL; case "skipped": return ch_javascript_sdk_1.TestStatus.SKIP; default: return ch_javascript_sdk_1.TestStatus.ERROR; } } } exports.TestReportUtil = TestReportUtil; //# sourceMappingURL=test-report-util.js.map