UNPKG

systelab-components-wdio-test

Version:
79 lines (78 loc) 2.85 kB
import colors from "colors"; import { TraceabilityUtility } from "../utils/traceability.util.js"; export 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.blue(`${this.indent()}${suite.description}`)); if (TraceabilityUtility.hasCoveredSpecs()) { this.indents++; console.log(colors.gray(`${this.indent()}Covered Specs: ${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.green(`${" ".repeat(6)}${description}`)); } else { console.log(colors.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.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.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; } }