UNPKG

@qualitywatcher/wdio-reporter

Version:

WebdriverIO Reporter for QualityWatcher

88 lines (87 loc) 3.2 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const reporter_1 = __importDefault(require("@wdio/reporter")); const fs_1 = __importDefault(require("fs")); const REGEX_SUITE_AND_TEST_ID = /\bS(\d+)C(\d+)\b/g; class QualityWatcherReporter extends reporter_1.default { constructor(options) { super(options); this._stateCounts = { passed: 0, failed: 0, skipped: 0, total: 0 }; this.results = new Map(); this.dir = "./QualityWatcher"; options = Object.assign(options, { stdout: true }); } onTestPass() { this._stateCounts.passed++; } onTestFail() { this._stateCounts.failed++; } onTestSkip() { this._stateCounts.skipped++; } onTestEnd(test) { var _a, _b, _c; try { const { suite_id, test_id } = this.getSuiteAndCaseIds(test.title); const testCaseDetails = { comment: ((_a = test.error) === null || _a === void 0 ? void 0 : _a.message) ? (_c = (_b = test.error) === null || _b === void 0 ? void 0 : _b.message) === null || _c === void 0 ? void 0 : _c.replace(/\x1b\[[0-9;]*m/g, '') : test.title, status: test.state, time: test.duration || 0, attachments: [], suite_id: suite_id || undefined, test_id: test_id || undefined, }; if (testCaseDetails.suite_id && testCaseDetails.test_id) { const testKey = `${testCaseDetails.suite_id}-${testCaseDetails.test_id}`; this.results.set(testKey, testCaseDetails); } else { const newCaseData = Object.assign({ case: { suiteTitle: test.parent, testCaseTitle: test.title, steps: "" } }, testCaseDetails); const testKey = `${test.parent}-${test.title}`; this.results.set(testKey, newCaseData); } } catch (error) { console.error(error); } } onSuiteEnd(suite) { try { this.checkDirectory(this.dir); fs_1.default.writeFileSync(this.dir + `/${suite.title}.json`, JSON.stringify(Array.from(this.results.values()), null, 2)); } catch (err) { console.error(err); } } getSuiteAndCaseIds(title) { let suiteAndCaseIds; let suiteId; let caseId; while ((suiteAndCaseIds = REGEX_SUITE_AND_TEST_ID.exec(title)) != null) { suiteId = suiteAndCaseIds[1]; caseId = suiteAndCaseIds[2]; } return { suite_id: Number(suiteId), test_id: Number(caseId), }; } checkDirectory(dir) { if (!fs_1.default.existsSync(dir)) { fs_1.default.mkdirSync(dir); } } generateRandomString() { return (Math.random() + 1).toString(36).substring(7); } } exports.default = QualityWatcherReporter;