All files / tap-bark/src/output-provider output-provider.ts

100% Statements 23/23
100% Branches 7/7
100% Functions 5/5
100% Lines 22/22
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51  1x   1x   1x 1x 102x   33x     33x     33x     3x     1x 2x     1x 2x     1x   94x   94x 5x   5x 2x             5x     89x   1x  
import { IOutputProvider } from "./output-provider.i";
import { ResultType } from "../result-type";
import { Assertion } from "../external/tap-parser";
const chalk = require("chalk");
 
export class OutputProvider implements IOutputProvider {
    public getResultMessage(type: ResultType, typeCount: number, totalCount: number): string {
        switch (type) {
            case ResultType.PASS:
                return chalk.green(`Pass: ${typeCount}/${totalCount}`);
 
            case ResultType.FAIL:
                return chalk.red(`Fail: ${typeCount}/${totalCount}`);
 
            case ResultType.IGNORE:
                return chalk.yellow(`Ignore: ${typeCount}/${totalCount}`);
        }
 
        throw new TypeError("Invalid ResultType.");
    }
 
    public getTestFixtureMessage(name: string): string {
        return `# [${name}]`;
    }
 
    public getTestMessage(name: string): string {
        return ` --- ${name}`;
    }
 
    public getFailureMessage(assertion: Assertion): string {
 
        const failureTitle = chalk.red("FAIL: ") + chalk.bold(assertion.name) + "\n";
 
        if (assertion.diag) {
            let output = failureTitle + assertion.diag.message + "\nExpected: " + assertion.diag.data.expect + "\n  Actual: " + assertion.diag.data.got;
 
            if (assertion.diag.data.stack) {
                output = output
                    + "\n=====\n"
                    + chalk.bold.white("Stack Trace") + "\n\n"
                    + assertion.diag.data.stack + "\n"
                    + "=====";
            }
 
            return output;
        }
 
        return failureTitle + "Failure reason unknown.";
    }
}