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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | 1× 1× 1× 1× 1× 1× 1× 21× 21× 21× 48× 48× 48× 48× 15× 33× 21× 1× 1× 33× 33× 33× 33× 33× 33× 33× 1× 1× 14× 14× 14× 14× 1× 1× 67× 67× 67× 67× 1× 6× 6× 6× 6× 1× 8× 8× 6× 6× 19× 19× 19× 5× 14× 6× 1× 1× 27× 27× 27× 27× 1× 8× 1× 1× 24× 24× 24× 24× 1× 1× 8× 8× 8× 1× 6× 1× 4× 1× 1× 1× 1× 37× 37× 37× 37× 985× 985× 174076× 1970× 1858× 1858× 106× 106× 6× 6× 37× 1568× 112× 1456× 4× 1452× 1452× 1346× 106× 37× 4331585× 4331585× 87038× 87038× 87038× 87038× 87038× 985× 87038× 87038× 87038× 87038× 37× 1× 3432× 3204× 228× 1× 89008× 1× 37× 37× 87038× 37× 1× 8× 1× 1× 37× 1× | "use strict"; var fs = require('fs'); var path = require('path'); var handlebars = require('handlebars'); var _ = require('lodash'); var mkdirp = require('mkdirp'); var report_1 = require('stryker-api/report'); function copyFolder(fromPath, to) { return mkdirRecursive(to).then(function () { return readdir(fromPath).then(function (files) { var promisses = []; files.forEach(function (file) { var currentPath = path.join(fromPath, file); var toCurrentPath = path.join(to, file); promisses.push(stats(currentPath).then(function (stats) { if (stats.isDirectory()) { return copyFolder(currentPath, toCurrentPath); } else { return copyFile(currentPath, toCurrentPath); } })); }); return Promise.all(promisses); }); }); } exports.copyFolder = copyFolder; function copyFile(fromFilename, toFilename) { return new Promise(function (resolve, reject) { var readStream = fs.createReadStream(fromFilename); var writeStream = fs.createWriteStream(toFilename); readStream.on('error', reject); writeStream.on('error', reject); readStream.pipe(writeStream); readStream.on('end', function () { return resolve(); }); }); } exports.copyFile = copyFile; function rmFile(path) { return new Promise(function (fileResolve, fileReject) { fs.unlink(path, function (error) { Iif (error) { fileReject(error); } else { fileResolve(); } }); }); } function mkdir(path) { return new Promise(function (resolve, reject) { fs.mkdir(path, function (error) { if (error) { reject(error); } else { resolve(); } }); }); } function stats(path) { return new Promise(function (resolve, reject) { fs.stat(path, function (error, stats) { Iif (error) { reject(error); } else { resolve(stats); } }); }); } function rmdir(dirToDelete) { return new Promise(function (resolve, reject) { fs.rmdir(dirToDelete, function (error) { Iif (error) { reject(error); } else { resolve(); } }); }); } function deleteDir(dirToDelete) { return fileOrFolderExists(dirToDelete).then(function (exists) { if (exists) { return readdir(dirToDelete).then(function (files) { var promisses = files.map(function (file) { var currentPath = path.join(dirToDelete, file); return stats(currentPath).then(function (stats) { if (stats.isDirectory()) { return deleteDir(currentPath); } else { return rmFile(currentPath); } }); }); return Promise.all(promisses).then(function () { return rmdir(dirToDelete); }); }); } }); } exports.deleteDir = deleteDir; function readdir(path) { return new Promise(function (resolve, reject) { fs.readdir(path, function (error, files) { Iif (error) { reject(error); } else { resolve(files); } }); }); } function mkdirRecursiveSync(folderName) { mkdirp.sync(folderName); } exports.mkdirRecursiveSync = mkdirRecursiveSync; function mkdirRecursive(folderName) { return new Promise(function (resolve, reject) { mkdirp(folderName, function (err) { Iif (err) { reject(err); } else { resolve(); } }); }); } exports.mkdirRecursive = mkdirRecursive; function fileOrFolderExists(path) { return new Promise(function (resolve) { fs.lstat(path, function (error, stats) { resolve(!error); }); }); } function readTemplate(name) { return fs.readFileSync(path.join(__dirname, 'templates', name + ".tpl.html"), 'utf8'); } function compileTemplate(name) { return handlebars.compile(readTemplate(name)); } var templates = { node: compileTemplate('node'), footer: compileTemplate('footer'), header: compileTemplate('header'), sourceFile: compileTemplate('sourceFile'), }; handlebars.registerPartial('resultRow', readTemplate('resultRow')); handlebars.registerPartial('resultTableHead', readTemplate('resultTableHead')); handlebars.registerHelper('code', function () { var leaf = this; var currentBackground = null; var currentCursorMutantStatusses = { killed: 0, survived: 0, timeout: 0, untested: 0 }; var maxIndex = leaf.file.content.length - 1; var numberedMutants = _.sortBy(leaf.results, function (m) { return m.range[0] * 10000 + m.range[1] * -1; }) .map(function (mutant, index) { return ({ mutant: mutant, index: index }); }); var adjustCurrentMutantResult = function (valueToAdd) { return function (numberedMutant) { switch (numberedMutant.mutant.status) { case report_1.MutantStatus.KILLED: currentCursorMutantStatusses.killed += valueToAdd; break; case report_1.MutantStatus.SURVIVED: currentCursorMutantStatusses.survived += valueToAdd; break; case report_1.MutantStatus.TIMEDOUT: currentCursorMutantStatusses.timeout += valueToAdd; break; case report_1.MutantStatus.UNTESTED: currentCursorMutantStatusses.untested += valueToAdd; break; } }; }; var determineBackground = function () { if (currentCursorMutantStatusses.survived > 0) { return getContextClassForStatus(report_1.MutantStatus.SURVIVED); } else if (currentCursorMutantStatusses.untested > 0) { return getContextClassForStatus(report_1.MutantStatus.UNTESTED); } else Iif (currentCursorMutantStatusses.timeout > 0) { return getContextClassForStatus(report_1.MutantStatus.TIMEDOUT); } else if (currentCursorMutantStatusses.killed > 0) { return getContextClassForStatus(report_1.MutantStatus.KILLED); } return null; }; var annotate = function (char, index) { var mutantsStarting = numberedMutants.filter(function (m) { return m.mutant.range[0] === index; }); var mutantsEnding = numberedMutants.filter(function (m) { return m.mutant.range[1] === index - 1; }); mutantsStarting.forEach(adjustCurrentMutantResult(1)); mutantsEnding.forEach(adjustCurrentMutantResult(-1)); var backgroundColorAnnotation = mutantsStarting.length || mutantsEnding.length || index === 0 ? "<span class=\"bg-" + determineBackground() + "\">" : ''; var backgroundColorEndAnnotation = ((mutantsStarting.length || mutantsEnding.length) && index > 0) || index === maxIndex ? '</span>' : ''; var mutantsAnnotations = mutantsStarting.map(function (m) { return ("<a href=\"#\" class=\"stryker-mutant-button\" data-mutant-status-annotation=\"" + getContextClassForStatus(m.mutant.status) + "\" data-mutant=\"" + m.index + "\">") + ("<span class=\"label label-" + getContextClassForStatus(m.mutant.status) + "\">" + m.index + "</span>") + "</a>" + ("<span class=\"label label-info stryker-mutant-replacement\" hidden data-mutant=\"" + m.index + "\">" + escape(m.mutant.replacement) + "</span>"); }); var originalCodeStartAnnotations = mutantsStarting.map(function (m) { return ("<span class=\"stryker-original-code\" data-mutant=\"" + m.index + "\">"); }); var originalCodeEndAnnotations = mutantsEnding.map(function (m) { return '</span>'; }); var mutantReplacements = mutantsEnding.map(function (m) { return ("<span class=\"label label-info stryker-mutant-replacement\" hidden data-mutant=\"" + m.index + "\">" + escape(m.mutant.replacement) + "</span>"); }); return "" + backgroundColorEndAnnotation + originalCodeEndAnnotations.join('') + mutantsAnnotations.join('') + originalCodeStartAnnotations.join('') + backgroundColorAnnotation + escape(char); }; return new handlebars.SafeString("<pre><code class=\"lang-javascript\">" + mapString(leaf.file.content, annotate).join('') + "</code></pre>"); }); function getContextClassForStatus(status) { switch (status) { case report_1.MutantStatus.KILLED: return 'success'; case report_1.MutantStatus.UNTESTED: case report_1.MutantStatus.SURVIVED: return 'danger'; case report_1.MutantStatus.TIMEDOUT: return 'warning'; } } function escape(input) { return handlebars.escapeExpression(input); } function mapString(source, fn) { var results = []; for (var i = 0; i < source.length; i++) { results.push(fn(source[i], i)); } return results; } function nodeTemplate(context) { return templates.header(context) + templates.node(context) + templates.footer(context); } exports.nodeTemplate = nodeTemplate; function sourceFileTemplate(context) { return templates.header(context) + templates.sourceFile(context) + templates.footer(context); } exports.sourceFileTemplate = sourceFileTemplate; //# sourceMappingURL=util.js.map |