all files / core/ test-output.js

97.96% Statements 48/49
94.44% Branches 17/18
100% Functions 12/12
97.92% Lines 47/48
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72  99×   5342×   51×   54×   5224× 5224× 5224× 5224× 5205×   19× 13× 13×             5205× 5205×         13× 13× 13× 11× 11×         5224× 5224× 1055×   5224×   11×      
"use strict";
var _errors_1 = require("./_errors");
var _results_1 = require("./_results");
var TestOutput = (function () {
    function TestOutput(outStream) {
        this._outStream = outStream;
    }
    TestOutput.prototype._writeOut = function (message) {
        this._outStream.write(message);
    };
    TestOutput.prototype.emitVersion = function () {
        this._writeOut("TAP version 13\n");
    };
    TestOutput.prototype.emitPlan = function (testCount) {
        this._writeOut("1.." + testCount + "\n");
    };
    TestOutput.prototype.emitResult = function (testId, result) {
        var outcome = result.outcome;
        var test = result.test;
        var testCaseArguments = result.arguments;
        if (outcome === _results_1.TestOutcome.Pass) {
            this._emitPass(testId, test, testCaseArguments);
        }
        else if (outcome === _results_1.TestOutcome.Fail || outcome === _results_1.TestOutcome.Error) {
            var error = result.error;
            this._emitFail(testId, test, testCaseArguments, error);
        }
        else Eif (outcome === _results_1.TestOutcome.Skip) {
            this._emitSkip(testId, test, testCaseArguments);
        }
        else {
            throw new Error("Invalid outcome for test " + outcome);
        }
    };
    TestOutput.prototype._emitPass = function (testId, test, testCaseArguments) {
        var description = this._getTestDescription(test, testCaseArguments);
        this._writeOut("ok " + testId + " " + description + "\n");
    };
    TestOutput.prototype._emitSkip = function (testId, test, testCaseArguments) {
        var description = this._getTestDescription(test, testCaseArguments);
        // we only want to use the reason if it's not undefined
        var reasonString = "";
        if (test.ignoreReason !== undefined) {
            reasonString = " " + test.ignoreReason;
        }
        this._writeOut("ok " + testId + " " + description + " # skip" + reasonString + "\n");
    };
    TestOutput.prototype._emitFail = function (testId, test, testCaseArguments, error) {
        var description = this._getTestDescription(test, testCaseArguments);
        this._writeOut("not ok " + testId + " " + description + "\n");
        if (error instanceof _errors_1.MatchError) {
            var yaml = this._getErrorYaml(error);
            this._writeOut(yaml);
        }
        else {
            this._writeOut("# ERROR: " + error.message + "\n");
        }
    };
    TestOutput.prototype._getTestDescription = function (test, testCaseArguments) {
        var testDescription = test.description;
        if (testCaseArguments !== undefined && testCaseArguments.length > 0) {
            testDescription += " [ " + testCaseArguments.map(function (x) { return JSON.stringify(x) || "undefined"; }).join(", ") + " ]";
        }
        return testDescription;
    };
    TestOutput.prototype._getErrorYaml = function (error) {
        return " ---\n   message: \"" + error.message + "\"\n   severity: fail\n   data:\n     got: " + JSON.stringify(error.actualValue) + "\n     expect: " + JSON.stringify(error.expectedValue) + "\n ...\n";
    };
    return TestOutput;
}());
exports.TestOutput = TestOutput;
//# sourceMappingURL=test-output.js.map