playwright-zephyr
Version:
Zephyr reporter for the Playwright
53 lines (52 loc) • 2.44 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const picocolors_1 = require("picocolors");
const archive_report_1 = require("./archive-report");
const convert_status_1 = require("./convert-status");
const create_report_file_1 = require("./create-report-file");
const validate_options_1 = require("./validate-options");
const zephyr_cloud_service_1 = require("./zephyr-cloud.service");
class ZephyrReporter {
zephyrService;
testResults = [];
projectKey;
testCaseKeyPattern = /\[(.*?)\]/;
options;
constructor(options) {
this.options = (0, validate_options_1.validateOptions)(options);
}
async onBegin() {
this.projectKey = this.options.projectKey;
this.zephyrService = new zephyr_cloud_service_1.ZephyrService(this.options);
}
onTestEnd(test, result) {
if (test.title.match(this.testCaseKeyPattern) && test.title.match(this.testCaseKeyPattern).length > 1) {
const [, testCaseId] = test.title.match(this.testCaseKeyPattern);
const testCaseKey = `${this.projectKey}-${testCaseId}`;
const status = (0, convert_status_1.convertStatus)(result.status);
const comment = result.error
? `<b>❌ Error Message: </b> <br> <span style="color: rgb(226, 80, 65);">${result.error?.message?.replaceAll('\n', '<br>')}</span> <br> <br> <b>🧱 Stack Trace:</b> <br> <span style="color: rgb(226, 80, 65);">${result.error?.stack?.replaceAll('\n', '<br>')}</span>`
: undefined;
this.testResults.push({
result: status,
testCase: {
key: testCaseKey,
comment,
},
});
}
}
async onEnd() {
if (this.testResults.length > 0) {
const testResultsPath = 'test-results/zephyr';
const zephyrReportName = `zephyr-report-${new Date().getTime()}.json`;
(0, create_report_file_1.createJsonReport)(zephyrReportName, testResultsPath, this.testResults);
const zephyrReportPath = (0, archive_report_1.archiveReport)(zephyrReportName, testResultsPath);
await this.zephyrService.createRun(zephyrReportPath);
}
else {
console.log((0, picocolors_1.gray)(`[zephyr reporter]: There's no Zephyr test case id in this spec file`));
}
}
}
exports.default = ZephyrReporter;