aiotests-playwright-reporter
Version:
AIO Tests reporter for reporting results from Playwright to AIO Tests
82 lines (81 loc) • 3.42 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const aio_utils_1 = require("./aio-utils");
const AioTestsLogger_1 = __importDefault(require("./AioTestsLogger"));
class AioReporter {
constructor(options = {}) {
this.testSummary = [];
this.multiBrowser = false;
this.multiBrowserRetry = new Map();
this.customOption = options;
}
onBegin(config, suite) {
for (const project of config.projects) {
this.multiBrowserRetry.set(project.name, project.retries);
}
if (AioReporter.start) {
AioTestsLogger_1.default.logStartEnd("AIO Tests Playwright Reporter - Reporting results - test 2");
AioReporter.start = false;
}
if (this.customOption.aioConfig == null || this.customOption.aioConfig == undefined) {
AioTestsLogger_1.default.error("AIO config is not defined.");
return;
}
this.aioConfig = (0, aio_utils_1.validateAIOConfig)(this.customOption.aioConfig, true);
if (!this.aioConfig) {
return;
}
if (suite.entries().length > 1) {
this.multiBrowser = true;
}
}
onTestBegin(test) { }
onTestEnd(test, result) {
var _a;
// @ts-ignore
if (!((_a = this.aioConfig) === null || _a === void 0 ? void 0 : _a.createNewRunForRetries) && result.status != 'passed' && result.retry < this.multiBrowserRetry.get(test._projectId))
return;
let pattern = new RegExp("\\w+-TC-\\d+", "gi");
let match;
test.tags.forEach((tag) => {
do {
match = pattern.exec(tag);
if (match) {
this.testSummary.push({ test: test, result: result });
break;
}
} while (match != null);
});
}
onEnd(result) { }
onExit() {
return __awaiter(this, void 0, void 0, function* () {
if (this.aioConfig) {
yield (0, aio_utils_1.reportTestResults)(this.aioConfig, this.testSummary, this.multiBrowser);
}
if (AioReporter.end) {
AioTestsLogger_1.default.logStartEnd("AIO Tests Playwright Reporter - Reporting results completed");
AioReporter.end = false;
}
return Promise.resolve();
});
}
onError(error) {
AioTestsLogger_1.default.error(error.message || "Playwright error occurred.");
}
}
AioReporter.start = true;
AioReporter.end = true;
exports.default = AioReporter;