Added game info bar

This commit is contained in:
clerie
2018-04-04 12:31:55 +02:00
parent 811ecfddfb
commit 95741499fd
271 changed files with 46086 additions and 2 deletions

487
node_modules/mocha/lib/reporters/base.js generated vendored Normal file
View File

@@ -0,0 +1,487 @@
/**
* Module dependencies.
*/
var tty = require('tty');
var diff = require('diff');
var ms = require('../ms');
var utils = require('../utils');
var supportsColor = process.browser ? null : require('supports-color');
/**
* Expose `Base`.
*/
exports = module.exports = Base;
/**
* Save timer references to avoid Sinon interfering.
* See: https://github.com/mochajs/mocha/issues/237
*/
/* eslint-disable no-unused-vars, no-native-reassign */
var Date = global.Date;
var setTimeout = global.setTimeout;
var setInterval = global.setInterval;
var clearTimeout = global.clearTimeout;
var clearInterval = global.clearInterval;
/* eslint-enable no-unused-vars, no-native-reassign */
/**
* Check if both stdio streams are associated with a tty.
*/
var isatty = tty.isatty(1) && tty.isatty(2);
/**
* Enable coloring by default, except in the browser interface.
*/
exports.useColors = !process.browser && (supportsColor || (process.env.MOCHA_COLORS !== undefined));
/**
* Inline diffs instead of +/-
*/
exports.inlineDiffs = false;
/**
* Default color map.
*/
exports.colors = {
pass: 90,
fail: 31,
'bright pass': 92,
'bright fail': 91,
'bright yellow': 93,
pending: 36,
suite: 0,
'error title': 0,
'error message': 31,
'error stack': 90,
checkmark: 32,
fast: 90,
medium: 33,
slow: 31,
green: 32,
light: 90,
'diff gutter': 90,
'diff added': 32,
'diff removed': 31
};
/**
* Default symbol map.
*/
exports.symbols = {
ok: '✓',
err: '✖',
dot: ''
};
// With node.js on Windows: use symbols available in terminal default fonts
if (process.platform === 'win32') {
exports.symbols.ok = '\u221A';
exports.symbols.err = '\u00D7';
exports.symbols.dot = '.';
}
/**
* Color `str` with the given `type`,
* allowing colors to be disabled,
* as well as user-defined color
* schemes.
*
* @param {string} type
* @param {string} str
* @return {string}
* @api private
*/
var color = exports.color = function(type, str) {
if (!exports.useColors) {
return String(str);
}
return '\u001b[' + exports.colors[type] + 'm' + str + '\u001b[0m';
};
/**
* Expose term window size, with some defaults for when stderr is not a tty.
*/
exports.window = {
width: 75
};
if (isatty) {
exports.window.width = process.stdout.getWindowSize
? process.stdout.getWindowSize(1)[0]
: tty.getWindowSize()[1];
}
/**
* Expose some basic cursor interactions that are common among reporters.
*/
exports.cursor = {
hide: function() {
isatty && process.stdout.write('\u001b[?25l');
},
show: function() {
isatty && process.stdout.write('\u001b[?25h');
},
deleteLine: function() {
isatty && process.stdout.write('\u001b[2K');
},
beginningOfLine: function() {
isatty && process.stdout.write('\u001b[0G');
},
CR: function() {
if (isatty) {
exports.cursor.deleteLine();
exports.cursor.beginningOfLine();
} else {
process.stdout.write('\r');
}
}
};
/**
* Outut the given `failures` as a list.
*
* @param {Array} failures
* @api public
*/
exports.list = function(failures) {
console.log();
failures.forEach(function(test, i) {
// format
var fmt = color('error title', ' %s) %s:\n')
+ color('error message', ' %s')
+ color('error stack', '\n%s\n');
// msg
var msg;
var err = test.err;
var message;
if (err.message && typeof err.message.toString === 'function') {
message = err.message + '';
} else if (typeof err.inspect === 'function') {
message = err.inspect() + '';
} else {
message = '';
}
var stack = err.stack || message;
var index = stack.indexOf(message);
var actual = err.actual;
var expected = err.expected;
var escape = true;
if (index === -1) {
msg = message;
} else {
index += message.length;
msg = stack.slice(0, index);
// remove msg from stack
stack = stack.slice(index + 1);
}
// uncaught
if (err.uncaught) {
msg = 'Uncaught ' + msg;
}
// explicitly show diff
if (err.showDiff !== false && sameType(actual, expected) && expected !== undefined) {
escape = false;
if (!(utils.isString(actual) && utils.isString(expected))) {
err.actual = actual = utils.stringify(actual);
err.expected = expected = utils.stringify(expected);
}
fmt = color('error title', ' %s) %s:\n%s') + color('error stack', '\n%s\n');
var match = message.match(/^([^:]+): expected/);
msg = '\n ' + color('error message', match ? match[1] : msg);
if (exports.inlineDiffs) {
msg += inlineDiff(err, escape);
} else {
msg += unifiedDiff(err, escape);
}
}
// indent stack trace
stack = stack.replace(/^/gm, ' ');
console.log(fmt, (i + 1), test.fullTitle(), msg, stack);
});
};
/**
* Initialize a new `Base` reporter.
*
* All other reporters generally
* inherit from this reporter, providing
* stats such as test duration, number
* of tests passed / failed etc.
*
* @param {Runner} runner
* @api public
*/
function Base(runner) {
var stats = this.stats = { suites: 0, tests: 0, passes: 0, pending: 0, failures: 0 };
var failures = this.failures = [];
if (!runner) {
return;
}
this.runner = runner;
runner.stats = stats;
runner.on('start', function() {
stats.start = new Date();
});
runner.on('suite', function(suite) {
stats.suites = stats.suites || 0;
suite.root || stats.suites++;
});
runner.on('test end', function() {
stats.tests = stats.tests || 0;
stats.tests++;
});
runner.on('pass', function(test) {
stats.passes = stats.passes || 0;
if (test.duration > test.slow()) {
test.speed = 'slow';
} else if (test.duration > test.slow() / 2) {
test.speed = 'medium';
} else {
test.speed = 'fast';
}
stats.passes++;
});
runner.on('fail', function(test, err) {
stats.failures = stats.failures || 0;
stats.failures++;
test.err = err;
failures.push(test);
});
runner.on('end', function() {
stats.end = new Date();
stats.duration = new Date() - stats.start;
});
runner.on('pending', function() {
stats.pending++;
});
}
/**
* Output common epilogue used by many of
* the bundled reporters.
*
* @api public
*/
Base.prototype.epilogue = function() {
var stats = this.stats;
var fmt;
console.log();
// passes
fmt = color('bright pass', ' ')
+ color('green', ' %d passing')
+ color('light', ' (%s)');
console.log(fmt,
stats.passes || 0,
ms(stats.duration));
// pending
if (stats.pending) {
fmt = color('pending', ' ')
+ color('pending', ' %d pending');
console.log(fmt, stats.pending);
}
// failures
if (stats.failures) {
fmt = color('fail', ' %d failing');
console.log(fmt, stats.failures);
Base.list(this.failures);
console.log();
}
console.log();
};
/**
* Pad the given `str` to `len`.
*
* @api private
* @param {string} str
* @param {string} len
* @return {string}
*/
function pad(str, len) {
str = String(str);
return Array(len - str.length + 1).join(' ') + str;
}
/**
* Returns an inline diff between 2 strings with coloured ANSI output
*
* @api private
* @param {Error} err with actual/expected
* @param {boolean} escape
* @return {string} Diff
*/
function inlineDiff(err, escape) {
var msg = errorDiff(err, 'WordsWithSpace', escape);
// linenos
var lines = msg.split('\n');
if (lines.length > 4) {
var width = String(lines.length).length;
msg = lines.map(function(str, i) {
return pad(++i, width) + ' |' + ' ' + str;
}).join('\n');
}
// legend
msg = '\n'
+ color('diff removed', 'actual')
+ ' '
+ color('diff added', 'expected')
+ '\n\n'
+ msg
+ '\n';
// indent
msg = msg.replace(/^/gm, ' ');
return msg;
}
/**
* Returns a unified diff between two strings.
*
* @api private
* @param {Error} err with actual/expected
* @param {boolean} escape
* @return {string} The diff.
*/
function unifiedDiff(err, escape) {
var indent = ' ';
function cleanUp(line) {
if (escape) {
line = escapeInvisibles(line);
}
if (line[0] === '+') {
return indent + colorLines('diff added', line);
}
if (line[0] === '-') {
return indent + colorLines('diff removed', line);
}
if (line.match(/\@\@/)) {
return null;
}
if (line.match(/\\ No newline/)) {
return null;
}
return indent + line;
}
function notBlank(line) {
return typeof line !== 'undefined' && line !== null;
}
var msg = diff.createPatch('string', err.actual, err.expected);
var lines = msg.split('\n').splice(4);
return '\n '
+ colorLines('diff added', '+ expected') + ' '
+ colorLines('diff removed', '- actual')
+ '\n\n'
+ lines.map(cleanUp).filter(notBlank).join('\n');
}
/**
* Return a character diff for `err`.
*
* @api private
* @param {Error} err
* @param {string} type
* @param {boolean} escape
* @return {string}
*/
function errorDiff(err, type, escape) {
var actual = escape ? escapeInvisibles(err.actual) : err.actual;
var expected = escape ? escapeInvisibles(err.expected) : err.expected;
return diff['diff' + type](actual, expected).map(function(str) {
if (str.added) {
return colorLines('diff added', str.value);
}
if (str.removed) {
return colorLines('diff removed', str.value);
}
return str.value;
}).join('');
}
/**
* Returns a string with all invisible characters in plain text
*
* @api private
* @param {string} line
* @return {string}
*/
function escapeInvisibles(line) {
return line.replace(/\t/g, '<tab>')
.replace(/\r/g, '<CR>')
.replace(/\n/g, '<LF>\n');
}
/**
* Color lines for `str`, using the color `name`.
*
* @api private
* @param {string} name
* @param {string} str
* @return {string}
*/
function colorLines(name, str) {
return str.split('\n').map(function(str) {
return color(name, str);
}).join('\n');
}
/**
* Object#toString reference.
*/
var objToString = Object.prototype.toString;
/**
* Check that a / b have the same type.
*
* @api private
* @param {Object} a
* @param {Object} b
* @return {boolean}
*/
function sameType(a, b) {
return objToString.call(a) === objToString.call(b);
}

62
node_modules/mocha/lib/reporters/doc.js generated vendored Normal file
View File

@@ -0,0 +1,62 @@
/**
* Module dependencies.
*/
var Base = require('./base');
var utils = require('../utils');
/**
* Expose `Doc`.
*/
exports = module.exports = Doc;
/**
* Initialize a new `Doc` reporter.
*
* @param {Runner} runner
* @api public
*/
function Doc(runner) {
Base.call(this, runner);
var indents = 2;
function indent() {
return Array(indents).join(' ');
}
runner.on('suite', function(suite) {
if (suite.root) {
return;
}
++indents;
console.log('%s<section class="suite">', indent());
++indents;
console.log('%s<h1>%s</h1>', indent(), utils.escape(suite.title));
console.log('%s<dl>', indent());
});
runner.on('suite end', function(suite) {
if (suite.root) {
return;
}
console.log('%s</dl>', indent());
--indents;
console.log('%s</section>', indent());
--indents;
});
runner.on('pass', function(test) {
console.log('%s <dt>%s</dt>', indent(), utils.escape(test.title));
var code = utils.escape(utils.clean(test.body));
console.log('%s <dd><pre><code>%s</code></pre></dd>', indent(), code);
});
runner.on('fail', function(test, err) {
console.log('%s <dt class="error">%s</dt>', indent(), utils.escape(test.title));
var code = utils.escape(utils.clean(test.fn.body));
console.log('%s <dd class="error"><pre><code>%s</code></pre></dd>', indent(), code);
console.log('%s <dd class="error">%s</dd>', indent(), utils.escape(err));
});
}

66
node_modules/mocha/lib/reporters/dot.js generated vendored Normal file
View File

@@ -0,0 +1,66 @@
/**
* Module dependencies.
*/
var Base = require('./base');
var inherits = require('../utils').inherits;
var color = Base.color;
/**
* Expose `Dot`.
*/
exports = module.exports = Dot;
/**
* Initialize a new `Dot` matrix test reporter.
*
* @api public
* @param {Runner} runner
*/
function Dot(runner) {
Base.call(this, runner);
var self = this;
var width = Base.window.width * .75 | 0;
var n = -1;
runner.on('start', function() {
process.stdout.write('\n');
});
runner.on('pending', function() {
if (++n % width === 0) {
process.stdout.write('\n ');
}
process.stdout.write(color('pending', Base.symbols.dot));
});
runner.on('pass', function(test) {
if (++n % width === 0) {
process.stdout.write('\n ');
}
if (test.speed === 'slow') {
process.stdout.write(color('bright yellow', Base.symbols.dot));
} else {
process.stdout.write(color(test.speed, Base.symbols.dot));
}
});
runner.on('fail', function() {
if (++n % width === 0) {
process.stdout.write('\n ');
}
process.stdout.write(color('fail', Base.symbols.dot));
});
runner.on('end', function() {
console.log();
self.epilogue();
});
}
/**
* Inherit from `Base.prototype`.
*/
inherits(Dot, Base);

56
node_modules/mocha/lib/reporters/html-cov.js generated vendored Normal file
View File

@@ -0,0 +1,56 @@
/**
* Module dependencies.
*/
var JSONCov = require('./json-cov');
var readFileSync = require('fs').readFileSync;
var join = require('path').join;
/**
* Expose `HTMLCov`.
*/
exports = module.exports = HTMLCov;
/**
* Initialize a new `JsCoverage` reporter.
*
* @api public
* @param {Runner} runner
*/
function HTMLCov(runner) {
var jade = require('jade');
var file = join(__dirname, '/templates/coverage.jade');
var str = readFileSync(file, 'utf8');
var fn = jade.compile(str, { filename: file });
var self = this;
JSONCov.call(this, runner, false);
runner.on('end', function() {
process.stdout.write(fn({
cov: self.cov,
coverageClass: coverageClass
}));
});
}
/**
* Return coverage class for a given coverage percentage.
*
* @api private
* @param {number} coveragePctg
* @return {string}
*/
function coverageClass(coveragePctg) {
if (coveragePctg >= 75) {
return 'high';
}
if (coveragePctg >= 50) {
return 'medium';
}
if (coveragePctg >= 25) {
return 'low';
}
return 'terrible';
}

343
node_modules/mocha/lib/reporters/html.js generated vendored Normal file
View File

@@ -0,0 +1,343 @@
/* eslint-env browser */
/**
* Module dependencies.
*/
var Base = require('./base');
var utils = require('../utils');
var Progress = require('../browser/progress');
var escapeRe = require('escape-string-regexp');
var escape = utils.escape;
/**
* Save timer references to avoid Sinon interfering (see GH-237).
*/
/* eslint-disable no-unused-vars, no-native-reassign */
var Date = global.Date;
var setTimeout = global.setTimeout;
var setInterval = global.setInterval;
var clearTimeout = global.clearTimeout;
var clearInterval = global.clearInterval;
/* eslint-enable no-unused-vars, no-native-reassign */
/**
* Expose `HTML`.
*/
exports = module.exports = HTML;
/**
* Stats template.
*/
var statsTemplate = '<ul id="mocha-stats">'
+ '<li class="progress"><canvas width="40" height="40"></canvas></li>'
+ '<li class="passes"><a href="javascript:void(0);">passes:</a> <em>0</em></li>'
+ '<li class="failures"><a href="javascript:void(0);">failures:</a> <em>0</em></li>'
+ '<li class="duration">duration: <em>0</em>s</li>'
+ '</ul>';
/**
* Initialize a new `HTML` reporter.
*
* @api public
* @param {Runner} runner
*/
function HTML(runner) {
Base.call(this, runner);
var self = this;
var stats = this.stats;
var stat = fragment(statsTemplate);
var items = stat.getElementsByTagName('li');
var passes = items[1].getElementsByTagName('em')[0];
var passesLink = items[1].getElementsByTagName('a')[0];
var failures = items[2].getElementsByTagName('em')[0];
var failuresLink = items[2].getElementsByTagName('a')[0];
var duration = items[3].getElementsByTagName('em')[0];
var canvas = stat.getElementsByTagName('canvas')[0];
var report = fragment('<ul id="mocha-report"></ul>');
var stack = [report];
var progress;
var ctx;
var root = document.getElementById('mocha');
if (canvas.getContext) {
var ratio = window.devicePixelRatio || 1;
canvas.style.width = canvas.width;
canvas.style.height = canvas.height;
canvas.width *= ratio;
canvas.height *= ratio;
ctx = canvas.getContext('2d');
ctx.scale(ratio, ratio);
progress = new Progress();
}
if (!root) {
return error('#mocha div missing, add it to your document');
}
// pass toggle
on(passesLink, 'click', function(evt) {
evt.preventDefault();
unhide();
var name = (/pass/).test(report.className) ? '' : ' pass';
report.className = report.className.replace(/fail|pass/g, '') + name;
if (report.className.trim()) {
hideSuitesWithout('test pass');
}
});
// failure toggle
on(failuresLink, 'click', function(evt) {
evt.preventDefault();
unhide();
var name = (/fail/).test(report.className) ? '' : ' fail';
report.className = report.className.replace(/fail|pass/g, '') + name;
if (report.className.trim()) {
hideSuitesWithout('test fail');
}
});
root.appendChild(stat);
root.appendChild(report);
if (progress) {
progress.size(40);
}
runner.on('suite', function(suite) {
if (suite.root) {
return;
}
// suite
var url = self.suiteURL(suite);
var el = fragment('<li class="suite"><h1><a href="%s">%s</a></h1></li>', url, escape(suite.title));
// container
stack[0].appendChild(el);
stack.unshift(document.createElement('ul'));
el.appendChild(stack[0]);
});
runner.on('suite end', function(suite) {
if (suite.root) {
return;
}
stack.shift();
});
runner.on('pass', function(test) {
var url = self.testURL(test);
var markup = '<li class="test pass %e"><h2>%e<span class="duration">%ems</span> '
+ '<a href="%s" class="replay">‣</a></h2></li>';
var el = fragment(markup, test.speed, test.title, test.duration, url);
self.addCodeToggle(el, test.body);
appendToStack(el);
updateStats();
});
runner.on('fail', function(test) {
var el = fragment('<li class="test fail"><h2>%e <a href="%e" class="replay">‣</a></h2></li>',
test.title, self.testURL(test));
var stackString; // Note: Includes leading newline
var message = test.err.toString();
// <=IE7 stringifies to [Object Error]. Since it can be overloaded, we
// check for the result of the stringifying.
if (message === '[object Error]') {
message = test.err.message;
}
if (test.err.stack) {
var indexOfMessage = test.err.stack.indexOf(test.err.message);
if (indexOfMessage === -1) {
stackString = test.err.stack;
} else {
stackString = test.err.stack.substr(test.err.message.length + indexOfMessage);
}
} else if (test.err.sourceURL && test.err.line !== undefined) {
// Safari doesn't give you a stack. Let's at least provide a source line.
stackString = '\n(' + test.err.sourceURL + ':' + test.err.line + ')';
}
stackString = stackString || '';
if (test.err.htmlMessage && stackString) {
el.appendChild(fragment('<div class="html-error">%s\n<pre class="error">%e</pre></div>',
test.err.htmlMessage, stackString));
} else if (test.err.htmlMessage) {
el.appendChild(fragment('<div class="html-error">%s</div>', test.err.htmlMessage));
} else {
el.appendChild(fragment('<pre class="error">%e%e</pre>', message, stackString));
}
self.addCodeToggle(el, test.body);
appendToStack(el);
updateStats();
});
runner.on('pending', function(test) {
var el = fragment('<li class="test pass pending"><h2>%e</h2></li>', test.title);
appendToStack(el);
updateStats();
});
function appendToStack(el) {
// Don't call .appendChild if #mocha-report was already .shift()'ed off the stack.
if (stack[0]) {
stack[0].appendChild(el);
}
}
function updateStats() {
// TODO: add to stats
var percent = stats.tests / this.total * 100 | 0;
if (progress) {
progress.update(percent).draw(ctx);
}
// update stats
var ms = new Date() - stats.start;
text(passes, stats.passes);
text(failures, stats.failures);
text(duration, (ms / 1000).toFixed(2));
}
}
/**
* Makes a URL, preserving querystring ("search") parameters.
*
* @param {string} s
* @return {string} A new URL.
*/
function makeUrl(s) {
var search = window.location.search;
// Remove previous grep query parameter if present
if (search) {
search = search.replace(/[?&]grep=[^&\s]*/g, '').replace(/^&/, '?');
}
return window.location.pathname + (search ? search + '&' : '?') + 'grep=' + encodeURIComponent(escapeRe(s));
}
/**
* Provide suite URL.
*
* @param {Object} [suite]
*/
HTML.prototype.suiteURL = function(suite) {
return makeUrl(suite.fullTitle());
};
/**
* Provide test URL.
*
* @param {Object} [test]
*/
HTML.prototype.testURL = function(test) {
return makeUrl(test.fullTitle());
};
/**
* Adds code toggle functionality for the provided test's list element.
*
* @param {HTMLLIElement} el
* @param {string} contents
*/
HTML.prototype.addCodeToggle = function(el, contents) {
var h2 = el.getElementsByTagName('h2')[0];
on(h2, 'click', function() {
pre.style.display = pre.style.display === 'none' ? 'block' : 'none';
});
var pre = fragment('<pre><code>%e</code></pre>', utils.clean(contents));
el.appendChild(pre);
pre.style.display = 'none';
};
/**
* Display error `msg`.
*
* @param {string} msg
*/
function error(msg) {
document.body.appendChild(fragment('<div id="mocha-error">%s</div>', msg));
}
/**
* Return a DOM fragment from `html`.
*
* @param {string} html
*/
function fragment(html) {
var args = arguments;
var div = document.createElement('div');
var i = 1;
div.innerHTML = html.replace(/%([se])/g, function(_, type) {
switch (type) {
case 's': return String(args[i++]);
case 'e': return escape(args[i++]);
// no default
}
});
return div.firstChild;
}
/**
* Check for suites that do not have elements
* with `classname`, and hide them.
*
* @param {text} classname
*/
function hideSuitesWithout(classname) {
var suites = document.getElementsByClassName('suite');
for (var i = 0; i < suites.length; i++) {
var els = suites[i].getElementsByClassName(classname);
if (!els.length) {
suites[i].className += ' hidden';
}
}
}
/**
* Unhide .hidden suites.
*/
function unhide() {
var els = document.getElementsByClassName('suite hidden');
for (var i = 0; i < els.length; ++i) {
els[i].className = els[i].className.replace('suite hidden', 'suite');
}
}
/**
* Set an element's text contents.
*
* @param {HTMLElement} el
* @param {string} contents
*/
function text(el, contents) {
if (el.textContent) {
el.textContent = contents;
} else {
el.innerText = contents;
}
}
/**
* Listen on `event` with callback `fn`.
*/
function on(el, event, fn) {
if (el.addEventListener) {
el.addEventListener(event, fn, false);
} else {
el.attachEvent('on' + event, fn);
}
}

19
node_modules/mocha/lib/reporters/index.js generated vendored Normal file
View File

@@ -0,0 +1,19 @@
// Alias exports to a their normalized format Mocha#reporter to prevent a need
// for dynamic (try/catch) requires, which Browserify doesn't handle.
exports.Base = exports.base = require('./base');
exports.Dot = exports.dot = require('./dot');
exports.Doc = exports.doc = require('./doc');
exports.TAP = exports.tap = require('./tap');
exports.JSON = exports.json = require('./json');
exports.HTML = exports.html = require('./html');
exports.List = exports.list = require('./list');
exports.Min = exports.min = require('./min');
exports.Spec = exports.spec = require('./spec');
exports.Nyan = exports.nyan = require('./nyan');
exports.XUnit = exports.xunit = require('./xunit');
exports.Markdown = exports.markdown = require('./markdown');
exports.Progress = exports.progress = require('./progress');
exports.Landing = exports.landing = require('./landing');
exports.JSONCov = exports['json-cov'] = require('./json-cov');
exports.HTMLCov = exports['html-cov'] = require('./html-cov');
exports.JSONStream = exports['json-stream'] = require('./json-stream');

151
node_modules/mocha/lib/reporters/json-cov.js generated vendored Normal file
View File

@@ -0,0 +1,151 @@
/**
* Module dependencies.
*/
var Base = require('./base');
/**
* Expose `JSONCov`.
*/
exports = module.exports = JSONCov;
/**
* Initialize a new `JsCoverage` reporter.
*
* @api public
* @param {Runner} runner
* @param {boolean} output
*/
function JSONCov(runner, output) {
Base.call(this, runner);
output = arguments.length === 1 || output;
var self = this;
var tests = [];
var failures = [];
var passes = [];
runner.on('test end', function(test) {
tests.push(test);
});
runner.on('pass', function(test) {
passes.push(test);
});
runner.on('fail', function(test) {
failures.push(test);
});
runner.on('end', function() {
var cov = global._$jscoverage || {};
var result = self.cov = map(cov);
result.stats = self.stats;
result.tests = tests.map(clean);
result.failures = failures.map(clean);
result.passes = passes.map(clean);
if (!output) {
return;
}
process.stdout.write(JSON.stringify(result, null, 2));
});
}
/**
* Map jscoverage data to a JSON structure
* suitable for reporting.
*
* @api private
* @param {Object} cov
* @return {Object}
*/
function map(cov) {
var ret = {
instrumentation: 'node-jscoverage',
sloc: 0,
hits: 0,
misses: 0,
coverage: 0,
files: []
};
for (var filename in cov) {
if (Object.prototype.hasOwnProperty.call(cov, filename)) {
var data = coverage(filename, cov[filename]);
ret.files.push(data);
ret.hits += data.hits;
ret.misses += data.misses;
ret.sloc += data.sloc;
}
}
ret.files.sort(function(a, b) {
return a.filename.localeCompare(b.filename);
});
if (ret.sloc > 0) {
ret.coverage = (ret.hits / ret.sloc) * 100;
}
return ret;
}
/**
* Map jscoverage data for a single source file
* to a JSON structure suitable for reporting.
*
* @api private
* @param {string} filename name of the source file
* @param {Object} data jscoverage coverage data
* @return {Object}
*/
function coverage(filename, data) {
var ret = {
filename: filename,
coverage: 0,
hits: 0,
misses: 0,
sloc: 0,
source: {}
};
data.source.forEach(function(line, num) {
num++;
if (data[num] === 0) {
ret.misses++;
ret.sloc++;
} else if (data[num] !== undefined) {
ret.hits++;
ret.sloc++;
}
ret.source[num] = {
source: line,
coverage: data[num] === undefined ? '' : data[num]
};
});
ret.coverage = ret.hits / ret.sloc * 100;
return ret;
}
/**
* Return a plain-object representation of `test`
* free of cyclic properties etc.
*
* @api private
* @param {Object} test
* @return {Object}
*/
function clean(test) {
return {
duration: test.duration,
currentRetry: test.currentRetry(),
fullTitle: test.fullTitle(),
title: test.title
};
}

60
node_modules/mocha/lib/reporters/json-stream.js generated vendored Normal file
View File

@@ -0,0 +1,60 @@
/**
* Module dependencies.
*/
var Base = require('./base');
/**
* Expose `List`.
*/
exports = module.exports = List;
/**
* Initialize a new `List` test reporter.
*
* @api public
* @param {Runner} runner
*/
function List(runner) {
Base.call(this, runner);
var self = this;
var total = runner.total;
runner.on('start', function() {
console.log(JSON.stringify(['start', { total: total }]));
});
runner.on('pass', function(test) {
console.log(JSON.stringify(['pass', clean(test)]));
});
runner.on('fail', function(test, err) {
test = clean(test);
test.err = err.message;
test.stack = err.stack || null;
console.log(JSON.stringify(['fail', test]));
});
runner.on('end', function() {
process.stdout.write(JSON.stringify(['end', self.stats]));
});
}
/**
* Return a plain-object representation of `test`
* free of cyclic properties etc.
*
* @api private
* @param {Object} test
* @return {Object}
*/
function clean(test) {
return {
title: test.title,
fullTitle: test.fullTitle(),
duration: test.duration,
currentRetry: test.currentRetry()
};
}

90
node_modules/mocha/lib/reporters/json.js generated vendored Normal file
View File

@@ -0,0 +1,90 @@
/**
* Module dependencies.
*/
var Base = require('./base');
/**
* Expose `JSON`.
*/
exports = module.exports = JSONReporter;
/**
* Initialize a new `JSON` reporter.
*
* @api public
* @param {Runner} runner
*/
function JSONReporter(runner) {
Base.call(this, runner);
var self = this;
var tests = [];
var pending = [];
var failures = [];
var passes = [];
runner.on('test end', function(test) {
tests.push(test);
});
runner.on('pass', function(test) {
passes.push(test);
});
runner.on('fail', function(test) {
failures.push(test);
});
runner.on('pending', function(test) {
pending.push(test);
});
runner.on('end', function() {
var obj = {
stats: self.stats,
tests: tests.map(clean),
pending: pending.map(clean),
failures: failures.map(clean),
passes: passes.map(clean)
};
runner.testResults = obj;
process.stdout.write(JSON.stringify(obj, null, 2));
});
}
/**
* Return a plain-object representation of `test`
* free of cyclic properties etc.
*
* @api private
* @param {Object} test
* @return {Object}
*/
function clean(test) {
return {
title: test.title,
fullTitle: test.fullTitle(),
duration: test.duration,
currentRetry: test.currentRetry(),
err: errorJSON(test.err || {})
};
}
/**
* Transform `error` into a JSON object.
*
* @api private
* @param {Error} err
* @return {Object}
*/
function errorJSON(err) {
var res = {};
Object.getOwnPropertyNames(err).forEach(function(key) {
res[key] = err[key];
}, err);
return res;
}

92
node_modules/mocha/lib/reporters/landing.js generated vendored Normal file
View File

@@ -0,0 +1,92 @@
/**
* Module dependencies.
*/
var Base = require('./base');
var inherits = require('../utils').inherits;
var cursor = Base.cursor;
var color = Base.color;
/**
* Expose `Landing`.
*/
exports = module.exports = Landing;
/**
* Airplane color.
*/
Base.colors.plane = 0;
/**
* Airplane crash color.
*/
Base.colors['plane crash'] = 31;
/**
* Runway color.
*/
Base.colors.runway = 90;
/**
* Initialize a new `Landing` reporter.
*
* @api public
* @param {Runner} runner
*/
function Landing(runner) {
Base.call(this, runner);
var self = this;
var width = Base.window.width * .75 | 0;
var total = runner.total;
var stream = process.stdout;
var plane = color('plane', '✈');
var crashed = -1;
var n = 0;
function runway() {
var buf = Array(width).join('-');
return ' ' + color('runway', buf);
}
runner.on('start', function() {
stream.write('\n\n\n ');
cursor.hide();
});
runner.on('test end', function(test) {
// check if the plane crashed
var col = crashed === -1 ? width * ++n / total | 0 : crashed;
// show the crash
if (test.state === 'failed') {
plane = color('plane crash', '✈');
crashed = col;
}
// render landing strip
stream.write('\u001b[' + (width + 1) + 'D\u001b[2A');
stream.write(runway());
stream.write('\n ');
stream.write(color('runway', Array(col).join('⋅')));
stream.write(plane);
stream.write(color('runway', Array(width - col).join('⋅') + '\n'));
stream.write(runway());
stream.write('\u001b[0m');
});
runner.on('end', function() {
cursor.show();
console.log();
self.epilogue();
});
}
/**
* Inherit from `Base.prototype`.
*/
inherits(Landing, Base);

61
node_modules/mocha/lib/reporters/list.js generated vendored Normal file
View File

@@ -0,0 +1,61 @@
/**
* Module dependencies.
*/
var Base = require('./base');
var inherits = require('../utils').inherits;
var color = Base.color;
var cursor = Base.cursor;
/**
* Expose `List`.
*/
exports = module.exports = List;
/**
* Initialize a new `List` test reporter.
*
* @api public
* @param {Runner} runner
*/
function List(runner) {
Base.call(this, runner);
var self = this;
var n = 0;
runner.on('start', function() {
console.log();
});
runner.on('test', function(test) {
process.stdout.write(color('pass', ' ' + test.fullTitle() + ': '));
});
runner.on('pending', function(test) {
var fmt = color('checkmark', ' -')
+ color('pending', ' %s');
console.log(fmt, test.fullTitle());
});
runner.on('pass', function(test) {
var fmt = color('checkmark', ' ' + Base.symbols.dot)
+ color('pass', ' %s: ')
+ color(test.speed, '%dms');
cursor.CR();
console.log(fmt, test.fullTitle(), test.duration);
});
runner.on('fail', function(test) {
cursor.CR();
console.log(color('fail', ' %d) %s'), ++n, test.fullTitle());
});
runner.on('end', self.epilogue.bind(self));
}
/**
* Inherit from `Base.prototype`.
*/
inherits(List, Base);

97
node_modules/mocha/lib/reporters/markdown.js generated vendored Normal file
View File

@@ -0,0 +1,97 @@
/**
* Module dependencies.
*/
var Base = require('./base');
var utils = require('../utils');
/**
* Constants
*/
var SUITE_PREFIX = '$';
/**
* Expose `Markdown`.
*/
exports = module.exports = Markdown;
/**
* Initialize a new `Markdown` reporter.
*
* @api public
* @param {Runner} runner
*/
function Markdown(runner) {
Base.call(this, runner);
var level = 0;
var buf = '';
function title(str) {
return Array(level).join('#') + ' ' + str;
}
function mapTOC(suite, obj) {
var ret = obj;
var key = SUITE_PREFIX + suite.title;
obj = obj[key] = obj[key] || { suite: suite };
suite.suites.forEach(function(suite) {
mapTOC(suite, obj);
});
return ret;
}
function stringifyTOC(obj, level) {
++level;
var buf = '';
var link;
for (var key in obj) {
if (key === 'suite') {
continue;
}
if (key !== SUITE_PREFIX) {
link = ' - [' + key.substring(1) + ']';
link += '(#' + utils.slug(obj[key].suite.fullTitle()) + ')\n';
buf += Array(level).join(' ') + link;
}
buf += stringifyTOC(obj[key], level);
}
return buf;
}
function generateTOC(suite) {
var obj = mapTOC(suite, {});
return stringifyTOC(obj, 0);
}
generateTOC(runner.suite);
runner.on('suite', function(suite) {
++level;
var slug = utils.slug(suite.fullTitle());
buf += '<a name="' + slug + '"></a>' + '\n';
buf += title(suite.title) + '\n';
});
runner.on('suite end', function() {
--level;
});
runner.on('pass', function(test) {
var code = utils.clean(test.body);
buf += test.title + '.\n';
buf += '\n```js\n';
buf += code + '\n';
buf += '```\n\n';
});
runner.on('end', function() {
process.stdout.write('# TOC\n');
process.stdout.write(generateTOC(runner.suite));
process.stdout.write(buf);
});
}

36
node_modules/mocha/lib/reporters/min.js generated vendored Normal file
View File

@@ -0,0 +1,36 @@
/**
* Module dependencies.
*/
var Base = require('./base');
var inherits = require('../utils').inherits;
/**
* Expose `Min`.
*/
exports = module.exports = Min;
/**
* Initialize a new `Min` minimal test reporter (best used with --watch).
*
* @api public
* @param {Runner} runner
*/
function Min(runner) {
Base.call(this, runner);
runner.on('start', function() {
// clear screen
process.stdout.write('\u001b[2J');
// set cursor position
process.stdout.write('\u001b[1;3H');
});
runner.on('end', this.epilogue.bind(this));
}
/**
* Inherit from `Base.prototype`.
*/
inherits(Min, Base);

261
node_modules/mocha/lib/reporters/nyan.js generated vendored Normal file
View File

@@ -0,0 +1,261 @@
/**
* Module dependencies.
*/
var Base = require('./base');
var inherits = require('../utils').inherits;
/**
* Expose `Dot`.
*/
exports = module.exports = NyanCat;
/**
* Initialize a new `Dot` matrix test reporter.
*
* @param {Runner} runner
* @api public
*/
function NyanCat(runner) {
Base.call(this, runner);
var self = this;
var width = Base.window.width * .75 | 0;
var nyanCatWidth = this.nyanCatWidth = 11;
this.colorIndex = 0;
this.numberOfLines = 4;
this.rainbowColors = self.generateColors();
this.scoreboardWidth = 5;
this.tick = 0;
this.trajectories = [[], [], [], []];
this.trajectoryWidthMax = (width - nyanCatWidth);
runner.on('start', function() {
Base.cursor.hide();
self.draw();
});
runner.on('pending', function() {
self.draw();
});
runner.on('pass', function() {
self.draw();
});
runner.on('fail', function() {
self.draw();
});
runner.on('end', function() {
Base.cursor.show();
for (var i = 0; i < self.numberOfLines; i++) {
write('\n');
}
self.epilogue();
});
}
/**
* Inherit from `Base.prototype`.
*/
inherits(NyanCat, Base);
/**
* Draw the nyan cat
*
* @api private
*/
NyanCat.prototype.draw = function() {
this.appendRainbow();
this.drawScoreboard();
this.drawRainbow();
this.drawNyanCat();
this.tick = !this.tick;
};
/**
* Draw the "scoreboard" showing the number
* of passes, failures and pending tests.
*
* @api private
*/
NyanCat.prototype.drawScoreboard = function() {
var stats = this.stats;
function draw(type, n) {
write(' ');
write(Base.color(type, n));
write('\n');
}
draw('green', stats.passes);
draw('fail', stats.failures);
draw('pending', stats.pending);
write('\n');
this.cursorUp(this.numberOfLines);
};
/**
* Append the rainbow.
*
* @api private
*/
NyanCat.prototype.appendRainbow = function() {
var segment = this.tick ? '_' : '-';
var rainbowified = this.rainbowify(segment);
for (var index = 0; index < this.numberOfLines; index++) {
var trajectory = this.trajectories[index];
if (trajectory.length >= this.trajectoryWidthMax) {
trajectory.shift();
}
trajectory.push(rainbowified);
}
};
/**
* Draw the rainbow.
*
* @api private
*/
NyanCat.prototype.drawRainbow = function() {
var self = this;
this.trajectories.forEach(function(line) {
write('\u001b[' + self.scoreboardWidth + 'C');
write(line.join(''));
write('\n');
});
this.cursorUp(this.numberOfLines);
};
/**
* Draw the nyan cat
*
* @api private
*/
NyanCat.prototype.drawNyanCat = function() {
var self = this;
var startWidth = this.scoreboardWidth + this.trajectories[0].length;
var dist = '\u001b[' + startWidth + 'C';
var padding = '';
write(dist);
write('_,------,');
write('\n');
write(dist);
padding = self.tick ? ' ' : ' ';
write('_|' + padding + '/\\_/\\ ');
write('\n');
write(dist);
padding = self.tick ? '_' : '__';
var tail = self.tick ? '~' : '^';
write(tail + '|' + padding + this.face() + ' ');
write('\n');
write(dist);
padding = self.tick ? ' ' : ' ';
write(padding + '"" "" ');
write('\n');
this.cursorUp(this.numberOfLines);
};
/**
* Draw nyan cat face.
*
* @api private
* @return {string}
*/
NyanCat.prototype.face = function() {
var stats = this.stats;
if (stats.failures) {
return '( x .x)';
} else if (stats.pending) {
return '( o .o)';
} else if (stats.passes) {
return '( ^ .^)';
}
return '( - .-)';
};
/**
* Move cursor up `n`.
*
* @api private
* @param {number} n
*/
NyanCat.prototype.cursorUp = function(n) {
write('\u001b[' + n + 'A');
};
/**
* Move cursor down `n`.
*
* @api private
* @param {number} n
*/
NyanCat.prototype.cursorDown = function(n) {
write('\u001b[' + n + 'B');
};
/**
* Generate rainbow colors.
*
* @api private
* @return {Array}
*/
NyanCat.prototype.generateColors = function() {
var colors = [];
for (var i = 0; i < (6 * 7); i++) {
var pi3 = Math.floor(Math.PI / 3);
var n = (i * (1.0 / 6));
var r = Math.floor(3 * Math.sin(n) + 3);
var g = Math.floor(3 * Math.sin(n + 2 * pi3) + 3);
var b = Math.floor(3 * Math.sin(n + 4 * pi3) + 3);
colors.push(36 * r + 6 * g + b + 16);
}
return colors;
};
/**
* Apply rainbow to the given `str`.
*
* @api private
* @param {string} str
* @return {string}
*/
NyanCat.prototype.rainbowify = function(str) {
if (!Base.useColors) {
return str;
}
var color = this.rainbowColors[this.colorIndex % this.rainbowColors.length];
this.colorIndex += 1;
return '\u001b[38;5;' + color + 'm' + str + '\u001b[0m';
};
/**
* Stdout helper.
*
* @param {string} string A message to write to stdout.
*/
function write(string) {
process.stdout.write(string);
}

89
node_modules/mocha/lib/reporters/progress.js generated vendored Normal file
View File

@@ -0,0 +1,89 @@
/**
* Module dependencies.
*/
var Base = require('./base');
var inherits = require('../utils').inherits;
var color = Base.color;
var cursor = Base.cursor;
/**
* Expose `Progress`.
*/
exports = module.exports = Progress;
/**
* General progress bar color.
*/
Base.colors.progress = 90;
/**
* Initialize a new `Progress` bar test reporter.
*
* @api public
* @param {Runner} runner
* @param {Object} options
*/
function Progress(runner, options) {
Base.call(this, runner);
var self = this;
var width = Base.window.width * .50 | 0;
var total = runner.total;
var complete = 0;
var lastN = -1;
// default chars
options = options || {};
options.open = options.open || '[';
options.complete = options.complete || '▬';
options.incomplete = options.incomplete || Base.symbols.dot;
options.close = options.close || ']';
options.verbose = false;
// tests started
runner.on('start', function() {
console.log();
cursor.hide();
});
// tests complete
runner.on('test end', function() {
complete++;
var percent = complete / total;
var n = width * percent | 0;
var i = width - n;
if (n === lastN && !options.verbose) {
// Don't re-render the line if it hasn't changed
return;
}
lastN = n;
cursor.CR();
process.stdout.write('\u001b[J');
process.stdout.write(color('progress', ' ' + options.open));
process.stdout.write(Array(n).join(options.complete));
process.stdout.write(Array(i).join(options.incomplete));
process.stdout.write(color('progress', options.close));
if (options.verbose) {
process.stdout.write(color('progress', ' ' + complete + ' of ' + total));
}
});
// tests are complete, output some stats
// and the failures if any
runner.on('end', function() {
cursor.show();
console.log();
self.epilogue();
});
}
/**
* Inherit from `Base.prototype`.
*/
inherits(Progress, Base);

83
node_modules/mocha/lib/reporters/spec.js generated vendored Normal file
View File

@@ -0,0 +1,83 @@
/**
* Module dependencies.
*/
var Base = require('./base');
var inherits = require('../utils').inherits;
var color = Base.color;
var cursor = Base.cursor;
/**
* Expose `Spec`.
*/
exports = module.exports = Spec;
/**
* Initialize a new `Spec` test reporter.
*
* @api public
* @param {Runner} runner
*/
function Spec(runner) {
Base.call(this, runner);
var self = this;
var indents = 0;
var n = 0;
function indent() {
return Array(indents).join(' ');
}
runner.on('start', function() {
console.log();
});
runner.on('suite', function(suite) {
++indents;
console.log(color('suite', '%s%s'), indent(), suite.title);
});
runner.on('suite end', function() {
--indents;
if (indents === 1) {
console.log();
}
});
runner.on('pending', function(test) {
var fmt = indent() + color('pending', ' - %s');
console.log(fmt, test.title);
});
runner.on('pass', function(test) {
var fmt;
if (test.speed === 'fast') {
fmt = indent()
+ color('checkmark', ' ' + Base.symbols.ok)
+ color('pass', ' %s');
cursor.CR();
console.log(fmt, test.title);
} else {
fmt = indent()
+ color('checkmark', ' ' + Base.symbols.ok)
+ color('pass', ' %s')
+ color(test.speed, ' (%dms)');
cursor.CR();
console.log(fmt, test.title, test.duration);
}
});
runner.on('fail', function(test) {
cursor.CR();
console.log(indent() + color('fail', ' %d) %s'), ++n, test.title);
});
runner.on('end', self.epilogue.bind(self));
}
/**
* Inherit from `Base.prototype`.
*/
inherits(Spec, Base);

68
node_modules/mocha/lib/reporters/tap.js generated vendored Normal file
View File

@@ -0,0 +1,68 @@
/**
* Module dependencies.
*/
var Base = require('./base');
/**
* Expose `TAP`.
*/
exports = module.exports = TAP;
/**
* Initialize a new `TAP` reporter.
*
* @api public
* @param {Runner} runner
*/
function TAP(runner) {
Base.call(this, runner);
var n = 1;
var passes = 0;
var failures = 0;
runner.on('start', function() {
var total = runner.grepTotal(runner.suite);
console.log('%d..%d', 1, total);
});
runner.on('test end', function() {
++n;
});
runner.on('pending', function(test) {
console.log('ok %d %s # SKIP -', n, title(test));
});
runner.on('pass', function(test) {
passes++;
console.log('ok %d %s', n, title(test));
});
runner.on('fail', function(test, err) {
failures++;
console.log('not ok %d %s', n, title(test));
if (err.stack) {
console.log(err.stack.replace(/^/gm, ' '));
}
});
runner.on('end', function() {
console.log('# tests ' + (passes + failures));
console.log('# pass ' + passes);
console.log('# fail ' + failures);
});
}
/**
* Return a TAP-safe title of `test`
*
* @api private
* @param {Object} test
* @return {String}
*/
function title(test) {
return test.fullTitle().replace(/#/g, '');
}

View File

@@ -0,0 +1,51 @@
doctype html
html
head
title Coverage
meta(charset='utf-8')
include script.html
include style.html
body
#coverage
h1#overview Coverage
include menu
#stats(class=coverageClass(cov.coverage))
.percentage #{cov.coverage | 0}%
.sloc= cov.sloc
.hits= cov.hits
.misses= cov.misses
#files
for file in cov.files
.file
h2(id=file.filename)= file.filename
#stats(class=coverageClass(file.coverage))
.percentage #{file.coverage | 0}%
.sloc= file.sloc
.hits= file.hits
.misses= file.misses
table#source
thead
tr
th Line
th Hits
th Source
tbody
for line, number in file.source
if line.coverage > 0
tr.hit
td.line= number
td.hits= line.coverage
td.source= line.source
else if 0 === line.coverage
tr.miss
td.line= number
td.hits 0
td.source= line.source
else
tr
td.line= number
td.hits
td.source= line.source || ' '

13
node_modules/mocha/lib/reporters/templates/menu.jade generated vendored Normal file
View File

@@ -0,0 +1,13 @@
#menu
li
a(href='#overview') overview
for file in cov.files
li
span.cov(class=coverageClass(file.coverage)) #{file.coverage | 0}
a(href='##{file.filename}')
segments = file.filename.split('/')
basename = segments.pop()
if segments.length
span.dirname= segments.join('/') + '/'
span.basename= basename
a#logo(href='http://mochajs.org/') m

34
node_modules/mocha/lib/reporters/templates/script.html generated vendored Normal file
View File

@@ -0,0 +1,34 @@
<script>
headings = [];
onload = function(){
headings = document.querySelectorAll('h2');
};
onscroll = function(e){
var heading = find(window.scrollY);
if (!heading) return;
var links = document.querySelectorAll('#menu a')
, link;
for (var i = 0, len = links.length; i < len; ++i) {
link = links[i];
link.className = link.getAttribute('href') == '#' + heading.id
? 'active'
: '';
}
};
function find(y) {
var i = headings.length
, heading;
while (i--) {
heading = headings[i];
if (y >= heading.offsetTop) {
return heading;
}
}
}
</script>

324
node_modules/mocha/lib/reporters/templates/style.html generated vendored Normal file

File diff suppressed because one or more lines are too long

166
node_modules/mocha/lib/reporters/xunit.js generated vendored Normal file
View File

@@ -0,0 +1,166 @@
/**
* Module dependencies.
*/
var Base = require('./base');
var utils = require('../utils');
var inherits = utils.inherits;
var fs = require('fs');
var escape = utils.escape;
var mkdirp = require('mkdirp');
var path = require('path');
/**
* Save timer references to avoid Sinon interfering (see GH-237).
*/
/* eslint-disable no-unused-vars, no-native-reassign */
var Date = global.Date;
var setTimeout = global.setTimeout;
var setInterval = global.setInterval;
var clearTimeout = global.clearTimeout;
var clearInterval = global.clearInterval;
/* eslint-enable no-unused-vars, no-native-reassign */
/**
* Expose `XUnit`.
*/
exports = module.exports = XUnit;
/**
* Initialize a new `XUnit` reporter.
*
* @api public
* @param {Runner} runner
*/
function XUnit(runner, options) {
Base.call(this, runner);
var stats = this.stats;
var tests = [];
var self = this;
if (options.reporterOptions && options.reporterOptions.output) {
if (!fs.createWriteStream) {
throw new Error('file output not supported in browser');
}
mkdirp.sync(path.dirname(options.reporterOptions.output));
self.fileStream = fs.createWriteStream(options.reporterOptions.output);
}
runner.on('pending', function(test) {
tests.push(test);
});
runner.on('pass', function(test) {
tests.push(test);
});
runner.on('fail', function(test) {
tests.push(test);
});
runner.on('end', function() {
self.write(tag('testsuite', {
name: 'Mocha Tests',
tests: stats.tests,
failures: stats.failures,
errors: stats.failures,
skipped: stats.tests - stats.failures - stats.passes,
timestamp: (new Date()).toUTCString(),
time: (stats.duration / 1000) || 0
}, false));
tests.forEach(function(t) {
self.test(t);
});
self.write('</testsuite>');
});
}
/**
* Inherit from `Base.prototype`.
*/
inherits(XUnit, Base);
/**
* Override done to close the stream (if it's a file).
*
* @param failures
* @param {Function} fn
*/
XUnit.prototype.done = function(failures, fn) {
if (this.fileStream) {
this.fileStream.end(function() {
fn(failures);
});
} else {
fn(failures);
}
};
/**
* Write out the given line.
*
* @param {string} line
*/
XUnit.prototype.write = function(line) {
if (this.fileStream) {
this.fileStream.write(line + '\n');
} else if (typeof process === 'object' && process.stdout) {
process.stdout.write(line + '\n');
} else {
console.log(line);
}
};
/**
* Output tag for the given `test.`
*
* @param {Test} test
*/
XUnit.prototype.test = function(test) {
var attrs = {
classname: test.parent.fullTitle(),
name: test.title,
time: (test.duration / 1000) || 0
};
if (test.state === 'failed') {
var err = test.err;
this.write(tag('testcase', attrs, false, tag('failure', {}, false, escape(err.message) + '\n' + escape(err.stack))));
} else if (test.isPending()) {
this.write(tag('testcase', attrs, false, tag('skipped', {}, true)));
} else {
this.write(tag('testcase', attrs, true));
}
};
/**
* HTML tag helper.
*
* @param name
* @param attrs
* @param close
* @param content
* @return {string}
*/
function tag(name, attrs, close, content) {
var end = close ? '/>' : '>';
var pairs = [];
var tag;
for (var key in attrs) {
if (Object.prototype.hasOwnProperty.call(attrs, key)) {
pairs.push(key + '="' + escape(attrs[key]) + '"');
}
}
tag = '<' + name + (pairs.length ? ' ' + pairs.join(' ') : '') + end;
if (content) {
tag += content + '</' + name + end;
}
return tag;
}