systelab-components-wdio-test
Version:
Widgets to be use in the E2E Tests based in WDIO
84 lines (83 loc) • 3.21 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.StandaloneTestCaseReporter = void 0;
const tslib_1 = require("tslib");
const colors_1 = tslib_1.__importDefault(require("colors"));
const traceability_util_js_1 = require("../utils/traceability.util.js");
class StandaloneTestCaseReporter {
constructor() {
this.indents = 0;
this.currentSpec = null;
this.startTime = null;
this.failedExpectationsLogged = 0;
}
jasmineStarted(suiteInfo) {
jasmine.getEnv().testCaseReporter = this;
console.log("");
}
suiteStarted(suite) {
this.indents++;
console.log(colors_1.default.blue(`${this.indent()}${suite.description}`));
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--;
}
}
specStarted(spec) {
this.indents++;
this.currentSpec = spec;
this.startTime = new Date().getTime();
this.failedExpectationsLogged = 0;
console.log(`${this.indent()}${spec.description}`);
}
onAssertStart(description) {
this.logLatestErrors();
}
onAssertEnd(description, exception = false) {
const nFailedExpectations = this.currentSpec.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();
}
specDone(result) {
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--;
this.currentSpec = null;
this.startTime = null;
}
suiteDone(result) {
this.indents--;
console.log("");
}
jasmineDone(runDetails) {
}
indent() {
return " ".repeat(this.indents);
}
logLatestErrors() {
const nFailedExpectations = this.currentSpec.failedExpectations.length;
for (let i = this.failedExpectationsLogged; i < nFailedExpectations; i++) {
const failedExpectation = this.currentSpec.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.StandaloneTestCaseReporter = StandaloneTestCaseReporter;