"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 |