UNPKG

playwright-zephyr

Version:
54 lines (53 loc) 1.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const zephyr_service_1 = require("./zephyr.service"); function convertPwStatusToZephyr(status) { if (status === 'passed') return 'Pass'; if (status === 'failed') return 'Fail'; if (status === 'skipped') return 'Not Executed'; if (status === 'timedOut') return 'Blocked'; return 'Not Executed'; } class ZephyrReporter { zephyrService; testResults = []; projectKey; testCaseKeyPattern = /\[(.*?)\]/; options; environment; constructor(options) { this.options = options; } async onBegin() { this.projectKey = this.options.projectKey; this.environment = this.options.environment; this.zephyrService = new zephyr_service_1.ZephyrService(this.options); } onTestEnd(test, result) { if (test.title.match(this.testCaseKeyPattern) && test.title.match(this.testCaseKeyPattern).length > 1) { const [, projectName] = test.titlePath(); const [, testCaseId] = test.title.match(this.testCaseKeyPattern); const testCaseKey = `${this.projectKey}-${testCaseId}`; const status = convertPwStatusToZephyr(result.status); this.testResults.push({ testCaseKey, status, environment: this.environment ?? projectName ?? 'Playwright Test', executionDate: new Date().toISOString(), }); } } async onEnd() { if (this.testResults.length > 0) { await this.zephyrService.createRun(this.testResults); } else { console.log(`There are no tests with such ${this.testCaseKeyPattern} key pattern`); } } } exports.default = ZephyrReporter;