systelab-components-wdio-test
Version:
Widgets to be use in the E2E Tests based in WDIO
88 lines (87 loc) • 3.47 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const reporter_1 = tslib_1.__importDefault(require("@wdio/reporter"));
const colors_1 = tslib_1.__importDefault(require("colors"));
const traceability_util_js_1 = require("../utils/traceability.util.js");
const jasmineTestCaseReporter = {
specStarted: (result) => {
jasmine.getEnv().currentJasmineSpec = result;
},
specDone: (result) => {
jasmine.getEnv().currentJasmineSpec = null;
},
};
class TestCaseReporter extends reporter_1.default {
constructor(options) {
super(options);
this.indents = 0;
this.failedExpectationsLogged = 0;
options = Object.assign(options, { stdout: true });
}
onRunnerStart(runnerStats) {
jasmine.getEnv().addReporter(jasmineTestCaseReporter);
jasmine.getEnv().testCaseReporter = this;
console.log("");
}
onSuiteStart(suiteStats) {
this.indents++;
console.log(colors_1.default.blue(`${this.indent()}${suiteStats.fullTitle}`));
if (traceability_util_js_1.TraceabilityUtility.hasCoveredSpecs()) {
this.indents++;
console.log(colors_1.default.gray(`${this.indent()}Covered Specs: ${traceability_util_js_1.TraceabilityUtility.getCoveredSpecsPrettyString()}`));
this.indents--;
}
}
onTestStart(testStats) {
this.indents++;
this.startTime = new Date().getTime();
this.failedExpectationsLogged = 0;
console.log(`${this.indent()}${testStats.title}`);
}
onAssertStart(description) {
this.logLatestErrors();
}
onAssertEnd(description, exception = false) {
const nFailedExpectations = jasmine.getEnv().currentJasmineSpec.failedExpectations.length;
if (!exception && this.failedExpectationsLogged >= nFailedExpectations) {
console.log(colors_1.default.green(`${" ".repeat(6)}✓ ${description}`));
}
else {
console.log(colors_1.default.red(`${" ".repeat(6)}✖ ${description}`));
}
this.logLatestErrors();
}
onTestEnd(testStats) {
this.logLatestErrors();
this.indents++;
const endTime = new Date().getTime();
const duration = endTime - this.startTime;
console.log(colors_1.default.gray(`${this.indent()}Time: ${duration} ms`));
this.indents--;
this.indents--;
}
onSuiteEnd(suiteStats) {
this.indents--;
console.log("");
}
indent() {
return " ".repeat(this.indents);
}
logLatestErrors() {
const nFailedExpectations = jasmine.getEnv().currentJasmineSpec.failedExpectations.length;
for (let i = this.failedExpectationsLogged; i < nFailedExpectations; i++) {
const failedExpectation = jasmine.getEnv().currentJasmineSpec.failedExpectations[i];
console.log(colors_1.default.red(`${" ".repeat(8)}- ${failedExpectation.message}`));
let stackMessage = "";
const stackLines = failedExpectation.stack.split(/\n/).splice(1);
for (const line of stackLines) {
stackMessage += (stackMessage.length > 0) ? "\n" : "";
stackMessage += `${" ".repeat(8)}${line}`;
}
console.log(stackMessage);
}
this.failedExpectationsLogged = nFailedExpectations;
}
}
exports.default = TestCaseReporter;