"use strict";
var report_1 = require('stryker-api/report');
var log4js = require('log4js');
var path = require('path');
var util = require('./util');
var fs = require('fs');
var HandlebarsModel_1 = require('./HandlebarsModel');
var SourceFileTreeLeaf_1 = require('./SourceFileTreeLeaf');
var log = log4js.getLogger('HtmlReporter');
var SourceFileTreeNode = (function () {
function SourceFileTreeNode(name) {
this.name = name;
this.leafs = [];
this.children = [];
}
SourceFileTreeNode.prototype.addSourceFile = function (file, pathComponents) {
if (!pathComponents) {
pathComponents = file.path.split(path.sep);
}
var nextPathComponent = pathComponents.shift();
if (!pathComponents.length) {
this.leafs.push(new SourceFileTreeLeaf_1.default(file));
}
else {
var nodeToAddTo = this.children.filter(function (node) { return node.name === nextPathComponent; }).pop();
if (!nodeToAddTo) {
nodeToAddTo = new SourceFileTreeNode(nextPathComponent);
this.children.push(nodeToAddTo);
}
nodeToAddTo.addSourceFile(file, pathComponents);
}
};
SourceFileTreeNode.prototype.addMutantResult = function (result, pathComponents) {
if (!pathComponents) {
pathComponents = result.sourceFilePath.split(path.sep);
}
var nextPathComponent = pathComponents.shift();
var childNode = this.children.filter(function (n) { return n.name === nextPathComponent; }).pop();
if (childNode) {
childNode.addMutantResult(result, pathComponents);
}
else {
var leaf = this.leafs.filter(function (leaf) { return leaf.file.path === result.sourceFilePath; }).pop();
if (leaf) {
leaf.results.push(result);
}
else {
log.warn("Reported a mutant result for \"" + result.sourceFilePath + "\" but could not find source code for a file with that name. Skipping the result. Result was " + JSON.stringify(result) + ".");
}
}
};
SourceFileTreeNode.prototype.normalizeNames = function () {
while (this.leafs.length === 0 && this.children.length === 1) {
this.name = path.join(this.name, this.children[0].name);
this.leafs = this.children[0].leafs;
this.children = this.children[0].children;
}
this.name = this.name.replace(/:/g, '');
this.children.forEach(function (child) { return child.normalizeNames(); });
};
SourceFileTreeNode.prototype.calculateModel = function (urlPrefix) {
var totalKilled = 0, totalSurvived = 0, totalUntested = 0;
this.children.forEach(function (child) {
child.calculateModel("../" + urlPrefix);
totalKilled += child.model.totalKilled;
totalSurvived += child.model.totalSurvived;
totalUntested += child.model.totalUntested;
});
this.leafs.forEach(function (leaf) {
leaf.calculateModel(urlPrefix);
totalKilled += leaf.model.totalKilled;
totalSurvived += leaf.model.totalSurvived;
totalUntested += leaf.model.totalUntested;
});
this.model = new HandlebarsModel_1.default(this.name, urlPrefix, this.name + "/index.html", totalKilled, totalSurvived, totalUntested);
};
SourceFileTreeNode.prototype.writeReportNodeRecursive = function (directory) {
util.mkdirRecursive(directory);
fs.writeFileSync(path.join(directory, 'index.html'), util.nodeTemplate(this));
this.children.forEach(function (child) { return child.writeReportNodeRecursive(path.join(directory, child.name)); });
this.leafs.forEach(function (leaf) { return leaf.writeFileReport(directory); });
};
SourceFileTreeNode.prototype.toString = function (offset) {
if (offset === void 0) { offset = 0; }
var prefix = '';
for (var i = 0; i < offset; i++) {
prefix += '.';
}
var str = "" + prefix + this.name + "\n";
this.leafs.forEach(function (l) {
str += prefix + "./" + l.name;
if (l.results.length) {
str += ' [';
l.results.forEach(function (m) { return str += SourceFileTreeNode.mutantStatusToString(m.status); });
str += ']';
}
str += '\n';
});
this.children.forEach(function (n) { return str += n.toString(offset + 1); });
return str;
};
SourceFileTreeNode.mutantStatusToString = function (status) {
switch (status) {
case report_1.MutantStatus.KILLED:
return '.';
case report_1.MutantStatus.SURVIVED:
return 'S';
case report_1.MutantStatus.TIMEDOUT:
return 'T';
case report_1.MutantStatus.UNTESTED:
return 'O';
}
};
return SourceFileTreeNode;
}());
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = SourceFileTreeNode;
//# sourceMappingURL=SourceFileTreeNode.js.map |