added unit testing, and started implementing unit tests...phew
This commit is contained in:
490
node_modules/mocha/lib/reporters/base.js
generated
vendored
Normal file
490
node_modules/mocha/lib/reporters/base.js
generated
vendored
Normal file
@ -0,0 +1,490 @@
|
||||
'use strict';
|
||||
/**
|
||||
* @module Base
|
||||
*/
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var tty = require('tty');
|
||||
var diff = require('diff');
|
||||
var milliseconds = require('ms');
|
||||
var utils = require('../utils');
|
||||
var supportsColor = process.browser ? null : require('supports-color');
|
||||
var constants = require('../runner').constants;
|
||||
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
|
||||
var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
|
||||
|
||||
/**
|
||||
* Expose `Base`.
|
||||
*/
|
||||
|
||||
exports = module.exports = Base;
|
||||
|
||||
/**
|
||||
* 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.stdout || 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: '․',
|
||||
comma: ',',
|
||||
bang: '!'
|
||||
};
|
||||
|
||||
// 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}
|
||||
* @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');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function showDiff(err) {
|
||||
return (
|
||||
err &&
|
||||
err.showDiff !== false &&
|
||||
sameType(err.actual, err.expected) &&
|
||||
err.expected !== undefined
|
||||
);
|
||||
}
|
||||
|
||||
function stringifyDiffObjs(err) {
|
||||
if (!utils.isString(err.actual) || !utils.isString(err.expected)) {
|
||||
err.actual = utils.stringify(err.actual);
|
||||
err.expected = utils.stringify(err.expected);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a diff between 2 strings with coloured ANSI output.
|
||||
*
|
||||
* The diff will be either inline or unified dependant on the value
|
||||
* of `Base.inlineDiff`.
|
||||
*
|
||||
* @param {string} actual
|
||||
* @param {string} expected
|
||||
* @return {string} Diff
|
||||
*/
|
||||
var generateDiff = (exports.generateDiff = function(actual, expected) {
|
||||
return exports.inlineDiffs
|
||||
? inlineDiff(actual, expected)
|
||||
: unifiedDiff(actual, expected);
|
||||
});
|
||||
|
||||
/**
|
||||
* Output the given `failures` as a list.
|
||||
*
|
||||
* @public
|
||||
* @memberof Mocha.reporters.Base
|
||||
* @variation 1
|
||||
* @param {Array} failures
|
||||
*/
|
||||
|
||||
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 = message ? stack.indexOf(message) : -1;
|
||||
|
||||
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 (!exports.hideDiff && showDiff(err)) {
|
||||
stringifyDiffObjs(err);
|
||||
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);
|
||||
|
||||
msg += generateDiff(err.actual, err.expected);
|
||||
}
|
||||
|
||||
// indent stack trace
|
||||
stack = stack.replace(/^/gm, ' ');
|
||||
|
||||
// indented test title
|
||||
var testTitle = '';
|
||||
test.titlePath().forEach(function(str, index) {
|
||||
if (index !== 0) {
|
||||
testTitle += '\n ';
|
||||
}
|
||||
for (var i = 0; i < index; i++) {
|
||||
testTitle += ' ';
|
||||
}
|
||||
testTitle += str;
|
||||
});
|
||||
|
||||
console.log(fmt, i + 1, testTitle, msg, stack);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialize a new `Base` reporter.
|
||||
*
|
||||
* All other reporters generally
|
||||
* inherit from this reporter.
|
||||
*
|
||||
* @memberof Mocha.reporters
|
||||
* @public
|
||||
* @class
|
||||
* @param {Runner} runner
|
||||
*/
|
||||
|
||||
function Base(runner) {
|
||||
var failures = (this.failures = []);
|
||||
|
||||
if (!runner) {
|
||||
throw new TypeError('Missing runner argument');
|
||||
}
|
||||
this.stats = runner.stats; // assigned so Reporters keep a closer reference
|
||||
this.runner = runner;
|
||||
|
||||
runner.on(EVENT_TEST_PASS, function(test) {
|
||||
if (test.duration > test.slow()) {
|
||||
test.speed = 'slow';
|
||||
} else if (test.duration > test.slow() / 2) {
|
||||
test.speed = 'medium';
|
||||
} else {
|
||||
test.speed = 'fast';
|
||||
}
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_FAIL, function(test, err) {
|
||||
if (showDiff(err)) {
|
||||
stringifyDiffObjs(err);
|
||||
}
|
||||
test.err = err;
|
||||
failures.push(test);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Output common epilogue used by many of
|
||||
* the bundled reporters.
|
||||
*
|
||||
* @memberof Mocha.reporters.Base
|
||||
* @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, milliseconds(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`.
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
* @private
|
||||
* @param {String} actual
|
||||
* @param {String} expected
|
||||
* @return {string} Diff
|
||||
*/
|
||||
function inlineDiff(actual, expected) {
|
||||
var msg = errorDiff(actual, expected);
|
||||
|
||||
// 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 with coloured ANSI output.
|
||||
*
|
||||
* @private
|
||||
* @param {String} actual
|
||||
* @param {String} expected
|
||||
* @return {string} The diff.
|
||||
*/
|
||||
function unifiedDiff(actual, expected) {
|
||||
var indent = ' ';
|
||||
function cleanUp(line) {
|
||||
if (line[0] === '+') {
|
||||
return indent + colorLines('diff added', line);
|
||||
}
|
||||
if (line[0] === '-') {
|
||||
return indent + colorLines('diff removed', line);
|
||||
}
|
||||
if (line.match(/@@/)) {
|
||||
return '--';
|
||||
}
|
||||
if (line.match(/\\ No newline/)) {
|
||||
return null;
|
||||
}
|
||||
return indent + line;
|
||||
}
|
||||
function notBlank(line) {
|
||||
return typeof line !== 'undefined' && line !== null;
|
||||
}
|
||||
var msg = diff.createPatch('string', actual, expected);
|
||||
var lines = msg.split('\n').splice(5);
|
||||
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`.
|
||||
*
|
||||
* @private
|
||||
* @param {String} actual
|
||||
* @param {String} expected
|
||||
* @return {string} the diff
|
||||
*/
|
||||
function errorDiff(actual, expected) {
|
||||
return diff
|
||||
.diffWordsWithSpace(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('');
|
||||
}
|
||||
|
||||
/**
|
||||
* Color lines for `str`, using the color `name`.
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} a
|
||||
* @param {Object} b
|
||||
* @return {boolean}
|
||||
*/
|
||||
function sameType(a, b) {
|
||||
return objToString.call(a) === objToString.call(b);
|
||||
}
|
||||
|
||||
Base.abstract = true;
|
84
node_modules/mocha/lib/reporters/doc.js
generated
vendored
Normal file
84
node_modules/mocha/lib/reporters/doc.js
generated
vendored
Normal file
@ -0,0 +1,84 @@
|
||||
'use strict';
|
||||
/**
|
||||
* @module Doc
|
||||
*/
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var Base = require('./base');
|
||||
var utils = require('../utils');
|
||||
var constants = require('../runner').constants;
|
||||
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
|
||||
var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
|
||||
var EVENT_SUITE_BEGIN = constants.EVENT_SUITE_BEGIN;
|
||||
var EVENT_SUITE_END = constants.EVENT_SUITE_END;
|
||||
|
||||
/**
|
||||
* Expose `Doc`.
|
||||
*/
|
||||
|
||||
exports = module.exports = Doc;
|
||||
|
||||
/**
|
||||
* Initialize a new `Doc` reporter.
|
||||
*
|
||||
* @class
|
||||
* @memberof Mocha.reporters
|
||||
* @extends {Base}
|
||||
* @public
|
||||
* @param {Runner} runner
|
||||
*/
|
||||
function Doc(runner) {
|
||||
Base.call(this, runner);
|
||||
|
||||
var indents = 2;
|
||||
|
||||
function indent() {
|
||||
return Array(indents).join(' ');
|
||||
}
|
||||
|
||||
runner.on(EVENT_SUITE_BEGIN, 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(EVENT_SUITE_END, function(suite) {
|
||||
if (suite.root) {
|
||||
return;
|
||||
}
|
||||
console.log('%s</dl>', indent());
|
||||
--indents;
|
||||
console.log('%s</section>', indent());
|
||||
--indents;
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_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(EVENT_TEST_FAIL, function(test, err) {
|
||||
console.log(
|
||||
'%s <dt class="error">%s</dt>',
|
||||
indent(),
|
||||
utils.escape(test.title)
|
||||
);
|
||||
var code = utils.escape(utils.clean(test.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));
|
||||
});
|
||||
}
|
||||
|
||||
Doc.description = 'HTML documentation';
|
80
node_modules/mocha/lib/reporters/dot.js
generated
vendored
Normal file
80
node_modules/mocha/lib/reporters/dot.js
generated
vendored
Normal file
@ -0,0 +1,80 @@
|
||||
'use strict';
|
||||
/**
|
||||
* @module Dot
|
||||
*/
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var Base = require('./base');
|
||||
var inherits = require('../utils').inherits;
|
||||
var constants = require('../runner').constants;
|
||||
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
|
||||
var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
|
||||
var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
|
||||
var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
|
||||
var EVENT_RUN_END = constants.EVENT_RUN_END;
|
||||
|
||||
/**
|
||||
* Expose `Dot`.
|
||||
*/
|
||||
|
||||
exports = module.exports = Dot;
|
||||
|
||||
/**
|
||||
* Initialize a new `Dot` matrix test reporter.
|
||||
*
|
||||
* @class
|
||||
* @memberof Mocha.reporters
|
||||
* @extends Mocha.reporters.Base
|
||||
* @public
|
||||
* @param {Runner} runner
|
||||
*/
|
||||
function Dot(runner) {
|
||||
Base.call(this, runner);
|
||||
|
||||
var self = this;
|
||||
var width = (Base.window.width * 0.75) | 0;
|
||||
var n = -1;
|
||||
|
||||
runner.on(EVENT_RUN_BEGIN, function() {
|
||||
process.stdout.write('\n');
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_PENDING, function() {
|
||||
if (++n % width === 0) {
|
||||
process.stdout.write('\n ');
|
||||
}
|
||||
process.stdout.write(Base.color('pending', Base.symbols.comma));
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_PASS, function(test) {
|
||||
if (++n % width === 0) {
|
||||
process.stdout.write('\n ');
|
||||
}
|
||||
if (test.speed === 'slow') {
|
||||
process.stdout.write(Base.color('bright yellow', Base.symbols.dot));
|
||||
} else {
|
||||
process.stdout.write(Base.color(test.speed, Base.symbols.dot));
|
||||
}
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_FAIL, function() {
|
||||
if (++n % width === 0) {
|
||||
process.stdout.write('\n ');
|
||||
}
|
||||
process.stdout.write(Base.color('fail', Base.symbols.bang));
|
||||
});
|
||||
|
||||
runner.once(EVENT_RUN_END, function() {
|
||||
console.log();
|
||||
self.epilogue();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit from `Base.prototype`.
|
||||
*/
|
||||
inherits(Dot, Base);
|
||||
|
||||
Dot.description = 'dot matrix representation';
|
389
node_modules/mocha/lib/reporters/html.js
generated
vendored
Normal file
389
node_modules/mocha/lib/reporters/html.js
generated
vendored
Normal file
@ -0,0 +1,389 @@
|
||||
'use strict';
|
||||
|
||||
/* eslint-env browser */
|
||||
/**
|
||||
* @module HTML
|
||||
*/
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var Base = require('./base');
|
||||
var utils = require('../utils');
|
||||
var Progress = require('../browser/progress');
|
||||
var escapeRe = require('escape-string-regexp');
|
||||
var constants = require('../runner').constants;
|
||||
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
|
||||
var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
|
||||
var EVENT_SUITE_BEGIN = constants.EVENT_SUITE_BEGIN;
|
||||
var EVENT_SUITE_END = constants.EVENT_SUITE_END;
|
||||
var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
|
||||
var escape = utils.escape;
|
||||
|
||||
/**
|
||||
* Save timer references to avoid Sinon interfering (see GH-237).
|
||||
*/
|
||||
|
||||
var Date = global.Date;
|
||||
|
||||
/**
|
||||
* 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>';
|
||||
|
||||
var playIcon = '‣';
|
||||
|
||||
/**
|
||||
* Initialize a new `HTML` reporter.
|
||||
*
|
||||
* @public
|
||||
* @class
|
||||
* @memberof Mocha.reporters
|
||||
* @extends Mocha.reporters.Base
|
||||
* @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(EVENT_SUITE_BEGIN, 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(EVENT_SUITE_END, function(suite) {
|
||||
if (suite.root) {
|
||||
updateStats();
|
||||
return;
|
||||
}
|
||||
stack.shift();
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_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">' +
|
||||
playIcon +
|
||||
'</a></h2></li>';
|
||||
var el = fragment(markup, test.speed, test.title, test.duration, url);
|
||||
self.addCodeToggle(el, test.body);
|
||||
appendToStack(el);
|
||||
updateStats();
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_FAIL, function(test) {
|
||||
var el = fragment(
|
||||
'<li class="test fail"><h2>%e <a href="%e" class="replay">' +
|
||||
playIcon +
|
||||
'</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(EVENT_TEST_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 / runner.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);
|
||||
}
|
||||
}
|
||||
|
||||
HTML.browserOnly = true;
|
19
node_modules/mocha/lib/reporters/index.js
generated
vendored
Normal file
19
node_modules/mocha/lib/reporters/index.js
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
// 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.JSONStream = exports['json-stream'] = require('./json-stream');
|
89
node_modules/mocha/lib/reporters/json-stream.js
generated
vendored
Normal file
89
node_modules/mocha/lib/reporters/json-stream.js
generated
vendored
Normal file
@ -0,0 +1,89 @@
|
||||
'use strict';
|
||||
/**
|
||||
* @module JSONStream
|
||||
*/
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var Base = require('./base');
|
||||
var constants = require('../runner').constants;
|
||||
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
|
||||
var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
|
||||
var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
|
||||
var EVENT_RUN_END = constants.EVENT_RUN_END;
|
||||
|
||||
/**
|
||||
* Expose `JSONStream`.
|
||||
*/
|
||||
|
||||
exports = module.exports = JSONStream;
|
||||
|
||||
/**
|
||||
* Constructs a new `JSONStream` reporter instance.
|
||||
*
|
||||
* @public
|
||||
* @class
|
||||
* @extends Mocha.reporters.Base
|
||||
* @memberof Mocha.reporters
|
||||
* @param {Runner} runner - Instance triggers reporter actions.
|
||||
*/
|
||||
function JSONStream(runner) {
|
||||
Base.call(this, runner);
|
||||
|
||||
var self = this;
|
||||
var total = runner.total;
|
||||
|
||||
runner.once(EVENT_RUN_BEGIN, function() {
|
||||
writeEvent(['start', {total: total}]);
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_PASS, function(test) {
|
||||
writeEvent(['pass', clean(test)]);
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_FAIL, function(test, err) {
|
||||
test = clean(test);
|
||||
test.err = err.message;
|
||||
test.stack = err.stack || null;
|
||||
writeEvent(['fail', test]);
|
||||
});
|
||||
|
||||
runner.once(EVENT_RUN_END, function() {
|
||||
writeEvent(['end', self.stats]);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Mocha event to be written to the output stream.
|
||||
* @typedef {Array} JSONStream~MochaEvent
|
||||
*/
|
||||
|
||||
/**
|
||||
* Writes Mocha event to reporter output stream.
|
||||
*
|
||||
* @private
|
||||
* @param {JSONStream~MochaEvent} event - Mocha event to be output.
|
||||
*/
|
||||
function writeEvent(event) {
|
||||
process.stdout.write(JSON.stringify(event) + '\n');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an object literal representation of `test`
|
||||
* free of cyclic properties, etc.
|
||||
*
|
||||
* @private
|
||||
* @param {Test} test - Instance used as data source.
|
||||
* @return {Object} object containing pared-down test instance data
|
||||
*/
|
||||
function clean(test) {
|
||||
return {
|
||||
title: test.title,
|
||||
fullTitle: test.fullTitle(),
|
||||
duration: test.duration,
|
||||
currentRetry: test.currentRetry()
|
||||
};
|
||||
}
|
||||
|
||||
JSONStream.description = 'newline delimited JSON events';
|
134
node_modules/mocha/lib/reporters/json.js
generated
vendored
Normal file
134
node_modules/mocha/lib/reporters/json.js
generated
vendored
Normal file
@ -0,0 +1,134 @@
|
||||
'use strict';
|
||||
/**
|
||||
* @module JSON
|
||||
*/
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var Base = require('./base');
|
||||
var constants = require('../runner').constants;
|
||||
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
|
||||
var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
|
||||
var EVENT_TEST_END = constants.EVENT_TEST_END;
|
||||
var EVENT_RUN_END = constants.EVENT_RUN_END;
|
||||
var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
|
||||
|
||||
/**
|
||||
* Expose `JSON`.
|
||||
*/
|
||||
|
||||
exports = module.exports = JSONReporter;
|
||||
|
||||
/**
|
||||
* Initialize a new `JSON` reporter.
|
||||
*
|
||||
* @public
|
||||
* @class JSON
|
||||
* @memberof Mocha.reporters
|
||||
* @extends Mocha.reporters.Base
|
||||
* @param {Runner} runner
|
||||
*/
|
||||
function JSONReporter(runner) {
|
||||
Base.call(this, runner);
|
||||
|
||||
var self = this;
|
||||
var tests = [];
|
||||
var pending = [];
|
||||
var failures = [];
|
||||
var passes = [];
|
||||
|
||||
runner.on(EVENT_TEST_END, function(test) {
|
||||
tests.push(test);
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_PASS, function(test) {
|
||||
passes.push(test);
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_FAIL, function(test) {
|
||||
failures.push(test);
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_PENDING, function(test) {
|
||||
pending.push(test);
|
||||
});
|
||||
|
||||
runner.once(EVENT_RUN_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.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} test
|
||||
* @return {Object}
|
||||
*/
|
||||
function clean(test) {
|
||||
var err = test.err || {};
|
||||
if (err instanceof Error) {
|
||||
err = errorJSON(err);
|
||||
}
|
||||
|
||||
return {
|
||||
title: test.title,
|
||||
fullTitle: test.fullTitle(),
|
||||
duration: test.duration,
|
||||
currentRetry: test.currentRetry(),
|
||||
err: cleanCycles(err)
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces any circular references inside `obj` with '[object Object]'
|
||||
*
|
||||
* @private
|
||||
* @param {Object} obj
|
||||
* @return {Object}
|
||||
*/
|
||||
function cleanCycles(obj) {
|
||||
var cache = [];
|
||||
return JSON.parse(
|
||||
JSON.stringify(obj, function(key, value) {
|
||||
if (typeof value === 'object' && value !== null) {
|
||||
if (cache.indexOf(value) !== -1) {
|
||||
// Instead of going in a circle, we'll print [object Object]
|
||||
return '' + value;
|
||||
}
|
||||
cache.push(value);
|
||||
}
|
||||
|
||||
return value;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform an Error object into a JSON object.
|
||||
*
|
||||
* @private
|
||||
* @param {Error} err
|
||||
* @return {Object}
|
||||
*/
|
||||
function errorJSON(err) {
|
||||
var res = {};
|
||||
Object.getOwnPropertyNames(err).forEach(function(key) {
|
||||
res[key] = err[key];
|
||||
}, err);
|
||||
return res;
|
||||
}
|
||||
|
||||
JSONReporter.description = 'single JSON object';
|
107
node_modules/mocha/lib/reporters/landing.js
generated
vendored
Normal file
107
node_modules/mocha/lib/reporters/landing.js
generated
vendored
Normal file
@ -0,0 +1,107 @@
|
||||
'use strict';
|
||||
/**
|
||||
* @module Landing
|
||||
*/
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var Base = require('./base');
|
||||
var inherits = require('../utils').inherits;
|
||||
var constants = require('../runner').constants;
|
||||
var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
|
||||
var EVENT_RUN_END = constants.EVENT_RUN_END;
|
||||
var EVENT_TEST_END = constants.EVENT_TEST_END;
|
||||
var STATE_FAILED = require('../runnable').constants.STATE_FAILED;
|
||||
|
||||
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.
|
||||
*
|
||||
* @public
|
||||
* @class
|
||||
* @memberof Mocha.reporters
|
||||
* @extends Mocha.reporters.Base
|
||||
* @param {Runner} runner
|
||||
*/
|
||||
function Landing(runner) {
|
||||
Base.call(this, runner);
|
||||
|
||||
var self = this;
|
||||
var width = (Base.window.width * 0.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(EVENT_RUN_BEGIN, function() {
|
||||
stream.write('\n\n\n ');
|
||||
cursor.hide();
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_END, function(test) {
|
||||
// check if the plane crashed
|
||||
var col = crashed === -1 ? ((width * ++n) / total) | 0 : crashed;
|
||||
|
||||
// show the crash
|
||||
if (test.state === 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.once(EVENT_RUN_END, function() {
|
||||
cursor.show();
|
||||
console.log();
|
||||
self.epilogue();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit from `Base.prototype`.
|
||||
*/
|
||||
inherits(Landing, Base);
|
||||
|
||||
Landing.description = 'Unicode landing strip';
|
77
node_modules/mocha/lib/reporters/list.js
generated
vendored
Normal file
77
node_modules/mocha/lib/reporters/list.js
generated
vendored
Normal file
@ -0,0 +1,77 @@
|
||||
'use strict';
|
||||
/**
|
||||
* @module List
|
||||
*/
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var Base = require('./base');
|
||||
var inherits = require('../utils').inherits;
|
||||
var constants = require('../runner').constants;
|
||||
var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
|
||||
var EVENT_RUN_END = constants.EVENT_RUN_END;
|
||||
var EVENT_TEST_BEGIN = constants.EVENT_TEST_BEGIN;
|
||||
var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
|
||||
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
|
||||
var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
|
||||
var color = Base.color;
|
||||
var cursor = Base.cursor;
|
||||
|
||||
/**
|
||||
* Expose `List`.
|
||||
*/
|
||||
|
||||
exports = module.exports = List;
|
||||
|
||||
/**
|
||||
* Initialize a new `List` test reporter.
|
||||
*
|
||||
* @public
|
||||
* @class
|
||||
* @memberof Mocha.reporters
|
||||
* @extends Mocha.reporters.Base
|
||||
* @param {Runner} runner
|
||||
*/
|
||||
function List(runner) {
|
||||
Base.call(this, runner);
|
||||
|
||||
var self = this;
|
||||
var n = 0;
|
||||
|
||||
runner.on(EVENT_RUN_BEGIN, function() {
|
||||
console.log();
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_BEGIN, function(test) {
|
||||
process.stdout.write(color('pass', ' ' + test.fullTitle() + ': '));
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_PENDING, function(test) {
|
||||
var fmt = color('checkmark', ' -') + color('pending', ' %s');
|
||||
console.log(fmt, test.fullTitle());
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_PASS, function(test) {
|
||||
var fmt =
|
||||
color('checkmark', ' ' + Base.symbols.ok) +
|
||||
color('pass', ' %s: ') +
|
||||
color(test.speed, '%dms');
|
||||
cursor.CR();
|
||||
console.log(fmt, test.fullTitle(), test.duration);
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_FAIL, function(test) {
|
||||
cursor.CR();
|
||||
console.log(color('fail', ' %d) %s'), ++n, test.fullTitle());
|
||||
});
|
||||
|
||||
runner.once(EVENT_RUN_END, self.epilogue.bind(self));
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit from `Base.prototype`.
|
||||
*/
|
||||
inherits(List, Base);
|
||||
|
||||
List.description = 'like "spec" reporter but flat';
|
111
node_modules/mocha/lib/reporters/markdown.js
generated
vendored
Normal file
111
node_modules/mocha/lib/reporters/markdown.js
generated
vendored
Normal file
@ -0,0 +1,111 @@
|
||||
'use strict';
|
||||
/**
|
||||
* @module Markdown
|
||||
*/
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var Base = require('./base');
|
||||
var utils = require('../utils');
|
||||
var constants = require('../runner').constants;
|
||||
var EVENT_RUN_END = constants.EVENT_RUN_END;
|
||||
var EVENT_SUITE_BEGIN = constants.EVENT_SUITE_BEGIN;
|
||||
var EVENT_SUITE_END = constants.EVENT_SUITE_END;
|
||||
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
|
||||
|
||||
/**
|
||||
* Constants
|
||||
*/
|
||||
|
||||
var SUITE_PREFIX = '$';
|
||||
|
||||
/**
|
||||
* Expose `Markdown`.
|
||||
*/
|
||||
|
||||
exports = module.exports = Markdown;
|
||||
|
||||
/**
|
||||
* Initialize a new `Markdown` reporter.
|
||||
*
|
||||
* @public
|
||||
* @class
|
||||
* @memberof Mocha.reporters
|
||||
* @extends Mocha.reporters.Base
|
||||
* @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(EVENT_SUITE_BEGIN, function(suite) {
|
||||
++level;
|
||||
var slug = utils.slug(suite.fullTitle());
|
||||
buf += '<a name="' + slug + '"></a>' + '\n';
|
||||
buf += title(suite.title) + '\n';
|
||||
});
|
||||
|
||||
runner.on(EVENT_SUITE_END, function() {
|
||||
--level;
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_PASS, function(test) {
|
||||
var code = utils.clean(test.body);
|
||||
buf += test.title + '.\n';
|
||||
buf += '\n```js\n';
|
||||
buf += code + '\n';
|
||||
buf += '```\n\n';
|
||||
});
|
||||
|
||||
runner.once(EVENT_RUN_END, function() {
|
||||
process.stdout.write('# TOC\n');
|
||||
process.stdout.write(generateTOC(runner.suite));
|
||||
process.stdout.write(buf);
|
||||
});
|
||||
}
|
||||
|
||||
Markdown.description = 'GitHub Flavored Markdown';
|
48
node_modules/mocha/lib/reporters/min.js
generated
vendored
Normal file
48
node_modules/mocha/lib/reporters/min.js
generated
vendored
Normal file
@ -0,0 +1,48 @@
|
||||
'use strict';
|
||||
/**
|
||||
* @module Min
|
||||
*/
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var Base = require('./base');
|
||||
var inherits = require('../utils').inherits;
|
||||
var constants = require('../runner').constants;
|
||||
var EVENT_RUN_END = constants.EVENT_RUN_END;
|
||||
var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
|
||||
|
||||
/**
|
||||
* Expose `Min`.
|
||||
*/
|
||||
|
||||
exports = module.exports = Min;
|
||||
|
||||
/**
|
||||
* Initialize a new `Min` minimal test reporter (best used with --watch).
|
||||
*
|
||||
* @public
|
||||
* @class
|
||||
* @memberof Mocha.reporters
|
||||
* @extends Mocha.reporters.Base
|
||||
* @param {Runner} runner
|
||||
*/
|
||||
function Min(runner) {
|
||||
Base.call(this, runner);
|
||||
|
||||
runner.on(EVENT_RUN_BEGIN, function() {
|
||||
// clear screen
|
||||
process.stdout.write('\u001b[2J');
|
||||
// set cursor position
|
||||
process.stdout.write('\u001b[1;3H');
|
||||
});
|
||||
|
||||
runner.once(EVENT_RUN_END, this.epilogue.bind(this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit from `Base.prototype`.
|
||||
*/
|
||||
inherits(Min, Base);
|
||||
|
||||
Min.description = 'essentially just a summary';
|
276
node_modules/mocha/lib/reporters/nyan.js
generated
vendored
Normal file
276
node_modules/mocha/lib/reporters/nyan.js
generated
vendored
Normal file
@ -0,0 +1,276 @@
|
||||
'use strict';
|
||||
/**
|
||||
* @module Nyan
|
||||
*/
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var Base = require('./base');
|
||||
var constants = require('../runner').constants;
|
||||
var inherits = require('../utils').inherits;
|
||||
var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
|
||||
var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
|
||||
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
|
||||
var EVENT_RUN_END = constants.EVENT_RUN_END;
|
||||
var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
|
||||
|
||||
/**
|
||||
* Expose `Dot`.
|
||||
*/
|
||||
|
||||
exports = module.exports = NyanCat;
|
||||
|
||||
/**
|
||||
* Initialize a new `Dot` matrix test reporter.
|
||||
*
|
||||
* @param {Runner} runner
|
||||
* @public
|
||||
* @class Nyan
|
||||
* @memberof Mocha.reporters
|
||||
* @extends Mocha.reporters.Base
|
||||
*/
|
||||
|
||||
function NyanCat(runner) {
|
||||
Base.call(this, runner);
|
||||
|
||||
var self = this;
|
||||
var width = (Base.window.width * 0.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(EVENT_RUN_BEGIN, function() {
|
||||
Base.cursor.hide();
|
||||
self.draw();
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_PENDING, function() {
|
||||
self.draw();
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_PASS, function() {
|
||||
self.draw();
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_FAIL, function() {
|
||||
self.draw();
|
||||
});
|
||||
|
||||
runner.once(EVENT_RUN_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
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
* @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
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
* @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`.
|
||||
*
|
||||
* @private
|
||||
* @param {number} n
|
||||
*/
|
||||
|
||||
NyanCat.prototype.cursorUp = function(n) {
|
||||
write('\u001b[' + n + 'A');
|
||||
};
|
||||
|
||||
/**
|
||||
* Move cursor down `n`.
|
||||
*
|
||||
* @private
|
||||
* @param {number} n
|
||||
*/
|
||||
|
||||
NyanCat.prototype.cursorDown = function(n) {
|
||||
write('\u001b[' + n + 'B');
|
||||
};
|
||||
|
||||
/**
|
||||
* Generate rainbow colors.
|
||||
*
|
||||
* @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`.
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
|
||||
NyanCat.description = '"nyan cat"';
|
104
node_modules/mocha/lib/reporters/progress.js
generated
vendored
Normal file
104
node_modules/mocha/lib/reporters/progress.js
generated
vendored
Normal file
@ -0,0 +1,104 @@
|
||||
'use strict';
|
||||
/**
|
||||
* @module Progress
|
||||
*/
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var Base = require('./base');
|
||||
var constants = require('../runner').constants;
|
||||
var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
|
||||
var EVENT_TEST_END = constants.EVENT_TEST_END;
|
||||
var EVENT_RUN_END = constants.EVENT_RUN_END;
|
||||
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.
|
||||
*
|
||||
* @public
|
||||
* @class
|
||||
* @memberof Mocha.reporters
|
||||
* @extends Mocha.reporters.Base
|
||||
* @param {Runner} runner
|
||||
* @param {Object} options
|
||||
*/
|
||||
function Progress(runner, options) {
|
||||
Base.call(this, runner);
|
||||
|
||||
var self = this;
|
||||
var width = (Base.window.width * 0.5) | 0;
|
||||
var total = runner.total;
|
||||
var complete = 0;
|
||||
var lastN = -1;
|
||||
|
||||
// default chars
|
||||
options = options || {};
|
||||
var reporterOptions = options.reporterOptions || {};
|
||||
|
||||
options.open = reporterOptions.open || '[';
|
||||
options.complete = reporterOptions.complete || '▬';
|
||||
options.incomplete = reporterOptions.incomplete || Base.symbols.dot;
|
||||
options.close = reporterOptions.close || ']';
|
||||
options.verbose = reporterOptions.verbose || false;
|
||||
|
||||
// tests started
|
||||
runner.on(EVENT_RUN_BEGIN, function() {
|
||||
console.log();
|
||||
cursor.hide();
|
||||
});
|
||||
|
||||
// tests complete
|
||||
runner.on(EVENT_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.once(EVENT_RUN_END, function() {
|
||||
cursor.show();
|
||||
console.log();
|
||||
self.epilogue();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit from `Base.prototype`.
|
||||
*/
|
||||
inherits(Progress, Base);
|
||||
|
||||
Progress.description = 'a progress bar';
|
98
node_modules/mocha/lib/reporters/spec.js
generated
vendored
Normal file
98
node_modules/mocha/lib/reporters/spec.js
generated
vendored
Normal file
@ -0,0 +1,98 @@
|
||||
'use strict';
|
||||
/**
|
||||
* @module Spec
|
||||
*/
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var Base = require('./base');
|
||||
var constants = require('../runner').constants;
|
||||
var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
|
||||
var EVENT_RUN_END = constants.EVENT_RUN_END;
|
||||
var EVENT_SUITE_BEGIN = constants.EVENT_SUITE_BEGIN;
|
||||
var EVENT_SUITE_END = constants.EVENT_SUITE_END;
|
||||
var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
|
||||
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
|
||||
var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
|
||||
var inherits = require('../utils').inherits;
|
||||
var color = Base.color;
|
||||
|
||||
/**
|
||||
* Expose `Spec`.
|
||||
*/
|
||||
|
||||
exports = module.exports = Spec;
|
||||
|
||||
/**
|
||||
* Initialize a new `Spec` test reporter.
|
||||
*
|
||||
* @public
|
||||
* @class
|
||||
* @memberof Mocha.reporters
|
||||
* @extends Mocha.reporters.Base
|
||||
* @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(EVENT_RUN_BEGIN, function() {
|
||||
console.log();
|
||||
});
|
||||
|
||||
runner.on(EVENT_SUITE_BEGIN, function(suite) {
|
||||
++indents;
|
||||
console.log(color('suite', '%s%s'), indent(), suite.title);
|
||||
});
|
||||
|
||||
runner.on(EVENT_SUITE_END, function() {
|
||||
--indents;
|
||||
if (indents === 1) {
|
||||
console.log();
|
||||
}
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_PENDING, function(test) {
|
||||
var fmt = indent() + color('pending', ' - %s');
|
||||
console.log(fmt, test.title);
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_PASS, function(test) {
|
||||
var fmt;
|
||||
if (test.speed === 'fast') {
|
||||
fmt =
|
||||
indent() +
|
||||
color('checkmark', ' ' + Base.symbols.ok) +
|
||||
color('pass', ' %s');
|
||||
console.log(fmt, test.title);
|
||||
} else {
|
||||
fmt =
|
||||
indent() +
|
||||
color('checkmark', ' ' + Base.symbols.ok) +
|
||||
color('pass', ' %s') +
|
||||
color(test.speed, ' (%dms)');
|
||||
console.log(fmt, test.title, test.duration);
|
||||
}
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_FAIL, function(test) {
|
||||
console.log(indent() + color('fail', ' %d) %s'), ++n, test.title);
|
||||
});
|
||||
|
||||
runner.once(EVENT_RUN_END, self.epilogue.bind(self));
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit from `Base.prototype`.
|
||||
*/
|
||||
inherits(Spec, Base);
|
||||
|
||||
Spec.description = 'hierarchical & verbose [default]';
|
294
node_modules/mocha/lib/reporters/tap.js
generated
vendored
Normal file
294
node_modules/mocha/lib/reporters/tap.js
generated
vendored
Normal file
@ -0,0 +1,294 @@
|
||||
'use strict';
|
||||
/**
|
||||
* @module TAP
|
||||
*/
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var util = require('util');
|
||||
var Base = require('./base');
|
||||
var constants = require('../runner').constants;
|
||||
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
|
||||
var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
|
||||
var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
|
||||
var EVENT_RUN_END = constants.EVENT_RUN_END;
|
||||
var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
|
||||
var EVENT_TEST_END = constants.EVENT_TEST_END;
|
||||
var inherits = require('../utils').inherits;
|
||||
var sprintf = util.format;
|
||||
|
||||
/**
|
||||
* Expose `TAP`.
|
||||
*/
|
||||
|
||||
exports = module.exports = TAP;
|
||||
|
||||
/**
|
||||
* Constructs a new TAP reporter with runner instance and reporter options.
|
||||
*
|
||||
* @public
|
||||
* @class
|
||||
* @extends Mocha.reporters.Base
|
||||
* @memberof Mocha.reporters
|
||||
* @param {Runner} runner - Instance triggers reporter actions.
|
||||
* @param {Object} [options] - runner options
|
||||
*/
|
||||
function TAP(runner, options) {
|
||||
Base.call(this, runner, options);
|
||||
|
||||
var self = this;
|
||||
var n = 1;
|
||||
|
||||
var tapVersion = '12';
|
||||
if (options && options.reporterOptions) {
|
||||
if (options.reporterOptions.tapVersion) {
|
||||
tapVersion = options.reporterOptions.tapVersion.toString();
|
||||
}
|
||||
}
|
||||
|
||||
this._producer = createProducer(tapVersion);
|
||||
|
||||
runner.once(EVENT_RUN_BEGIN, function() {
|
||||
var ntests = runner.grepTotal(runner.suite);
|
||||
self._producer.writeVersion();
|
||||
self._producer.writePlan(ntests);
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_END, function() {
|
||||
++n;
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_PENDING, function(test) {
|
||||
self._producer.writePending(n, test);
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_PASS, function(test) {
|
||||
self._producer.writePass(n, test);
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_FAIL, function(test, err) {
|
||||
self._producer.writeFail(n, test, err);
|
||||
});
|
||||
|
||||
runner.once(EVENT_RUN_END, function() {
|
||||
self._producer.writeEpilogue(runner.stats);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit from `Base.prototype`.
|
||||
*/
|
||||
inherits(TAP, Base);
|
||||
|
||||
/**
|
||||
* Returns a TAP-safe title of `test`.
|
||||
*
|
||||
* @private
|
||||
* @param {Test} test - Test instance.
|
||||
* @return {String} title with any hash character removed
|
||||
*/
|
||||
function title(test) {
|
||||
return test.fullTitle().replace(/#/g, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes newline-terminated formatted string to reporter output stream.
|
||||
*
|
||||
* @private
|
||||
* @param {string} format - `printf`-like format string
|
||||
* @param {...*} [varArgs] - Format string arguments
|
||||
*/
|
||||
function println(format, varArgs) {
|
||||
var vargs = Array.from(arguments);
|
||||
vargs[0] += '\n';
|
||||
process.stdout.write(sprintf.apply(null, vargs));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a `tapVersion`-appropriate TAP producer instance, if possible.
|
||||
*
|
||||
* @private
|
||||
* @param {string} tapVersion - Version of TAP specification to produce.
|
||||
* @returns {TAPProducer} specification-appropriate instance
|
||||
* @throws {Error} if specification version has no associated producer.
|
||||
*/
|
||||
function createProducer(tapVersion) {
|
||||
var producers = {
|
||||
'12': new TAP12Producer(),
|
||||
'13': new TAP13Producer()
|
||||
};
|
||||
var producer = producers[tapVersion];
|
||||
|
||||
if (!producer) {
|
||||
throw new Error(
|
||||
'invalid or unsupported TAP version: ' + JSON.stringify(tapVersion)
|
||||
);
|
||||
}
|
||||
|
||||
return producer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @summary
|
||||
* Constructs a new TAPProducer.
|
||||
*
|
||||
* @description
|
||||
* <em>Only</em> to be used as an abstract base class.
|
||||
*
|
||||
* @private
|
||||
* @constructor
|
||||
*/
|
||||
function TAPProducer() {}
|
||||
|
||||
/**
|
||||
* Writes the TAP version to reporter output stream.
|
||||
*
|
||||
* @abstract
|
||||
*/
|
||||
TAPProducer.prototype.writeVersion = function() {};
|
||||
|
||||
/**
|
||||
* Writes the plan to reporter output stream.
|
||||
*
|
||||
* @abstract
|
||||
* @param {number} ntests - Number of tests that are planned to run.
|
||||
*/
|
||||
TAPProducer.prototype.writePlan = function(ntests) {
|
||||
println('%d..%d', 1, ntests);
|
||||
};
|
||||
|
||||
/**
|
||||
* Writes that test passed to reporter output stream.
|
||||
*
|
||||
* @abstract
|
||||
* @param {number} n - Index of test that passed.
|
||||
* @param {Test} test - Instance containing test information.
|
||||
*/
|
||||
TAPProducer.prototype.writePass = function(n, test) {
|
||||
println('ok %d %s', n, title(test));
|
||||
};
|
||||
|
||||
/**
|
||||
* Writes that test was skipped to reporter output stream.
|
||||
*
|
||||
* @abstract
|
||||
* @param {number} n - Index of test that was skipped.
|
||||
* @param {Test} test - Instance containing test information.
|
||||
*/
|
||||
TAPProducer.prototype.writePending = function(n, test) {
|
||||
println('ok %d %s # SKIP -', n, title(test));
|
||||
};
|
||||
|
||||
/**
|
||||
* Writes that test failed to reporter output stream.
|
||||
*
|
||||
* @abstract
|
||||
* @param {number} n - Index of test that failed.
|
||||
* @param {Test} test - Instance containing test information.
|
||||
* @param {Error} err - Reason the test failed.
|
||||
*/
|
||||
TAPProducer.prototype.writeFail = function(n, test, err) {
|
||||
println('not ok %d %s', n, title(test));
|
||||
};
|
||||
|
||||
/**
|
||||
* Writes the summary epilogue to reporter output stream.
|
||||
*
|
||||
* @abstract
|
||||
* @param {Object} stats - Object containing run statistics.
|
||||
*/
|
||||
TAPProducer.prototype.writeEpilogue = function(stats) {
|
||||
// :TBD: Why is this not counting pending tests?
|
||||
println('# tests ' + (stats.passes + stats.failures));
|
||||
println('# pass ' + stats.passes);
|
||||
// :TBD: Why are we not showing pending results?
|
||||
println('# fail ' + stats.failures);
|
||||
};
|
||||
|
||||
/**
|
||||
* @summary
|
||||
* Constructs a new TAP12Producer.
|
||||
*
|
||||
* @description
|
||||
* Produces output conforming to the TAP12 specification.
|
||||
*
|
||||
* @private
|
||||
* @constructor
|
||||
* @extends TAPProducer
|
||||
* @see {@link https://testanything.org/tap-specification.html|Specification}
|
||||
*/
|
||||
function TAP12Producer() {
|
||||
/**
|
||||
* Writes that test failed to reporter output stream, with error formatting.
|
||||
* @override
|
||||
*/
|
||||
this.writeFail = function(n, test, err) {
|
||||
TAPProducer.prototype.writeFail.call(this, n, test, err);
|
||||
if (err.message) {
|
||||
println(err.message.replace(/^/gm, ' '));
|
||||
}
|
||||
if (err.stack) {
|
||||
println(err.stack.replace(/^/gm, ' '));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit from `TAPProducer.prototype`.
|
||||
*/
|
||||
inherits(TAP12Producer, TAPProducer);
|
||||
|
||||
/**
|
||||
* @summary
|
||||
* Constructs a new TAP13Producer.
|
||||
*
|
||||
* @description
|
||||
* Produces output conforming to the TAP13 specification.
|
||||
*
|
||||
* @private
|
||||
* @constructor
|
||||
* @extends TAPProducer
|
||||
* @see {@link https://testanything.org/tap-version-13-specification.html|Specification}
|
||||
*/
|
||||
function TAP13Producer() {
|
||||
/**
|
||||
* Writes the TAP version to reporter output stream.
|
||||
* @override
|
||||
*/
|
||||
this.writeVersion = function() {
|
||||
println('TAP version 13');
|
||||
};
|
||||
|
||||
/**
|
||||
* Writes that test failed to reporter output stream, with error formatting.
|
||||
* @override
|
||||
*/
|
||||
this.writeFail = function(n, test, err) {
|
||||
TAPProducer.prototype.writeFail.call(this, n, test, err);
|
||||
var emitYamlBlock = err.message != null || err.stack != null;
|
||||
if (emitYamlBlock) {
|
||||
println(indent(1) + '---');
|
||||
if (err.message) {
|
||||
println(indent(2) + 'message: |-');
|
||||
println(err.message.replace(/^/gm, indent(3)));
|
||||
}
|
||||
if (err.stack) {
|
||||
println(indent(2) + 'stack: |-');
|
||||
println(err.stack.replace(/^/gm, indent(3)));
|
||||
}
|
||||
println(indent(1) + '...');
|
||||
}
|
||||
};
|
||||
|
||||
function indent(level) {
|
||||
return Array(level + 1).join(' ');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit from `TAPProducer.prototype`.
|
||||
*/
|
||||
inherits(TAP13Producer, TAPProducer);
|
||||
|
||||
TAP.description = 'TAP-compatible output';
|
215
node_modules/mocha/lib/reporters/xunit.js
generated
vendored
Normal file
215
node_modules/mocha/lib/reporters/xunit.js
generated
vendored
Normal file
@ -0,0 +1,215 @@
|
||||
'use strict';
|
||||
/**
|
||||
* @module XUnit
|
||||
*/
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var Base = require('./base');
|
||||
var utils = require('../utils');
|
||||
var fs = require('fs');
|
||||
var mkdirp = require('mkdirp');
|
||||
var path = require('path');
|
||||
var errors = require('../errors');
|
||||
var createUnsupportedError = errors.createUnsupportedError;
|
||||
var constants = require('../runner').constants;
|
||||
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
|
||||
var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
|
||||
var EVENT_RUN_END = constants.EVENT_RUN_END;
|
||||
var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
|
||||
var STATE_FAILED = require('../runnable').constants.STATE_FAILED;
|
||||
var inherits = utils.inherits;
|
||||
var escape = utils.escape;
|
||||
|
||||
/**
|
||||
* Save timer references to avoid Sinon interfering (see GH-237).
|
||||
*/
|
||||
var Date = global.Date;
|
||||
|
||||
/**
|
||||
* Expose `XUnit`.
|
||||
*/
|
||||
|
||||
exports = module.exports = XUnit;
|
||||
|
||||
/**
|
||||
* Initialize a new `XUnit` reporter.
|
||||
*
|
||||
* @public
|
||||
* @class
|
||||
* @memberof Mocha.reporters
|
||||
* @extends Mocha.reporters.Base
|
||||
* @param {Runner} runner
|
||||
*/
|
||||
function XUnit(runner, options) {
|
||||
Base.call(this, runner);
|
||||
|
||||
var stats = this.stats;
|
||||
var tests = [];
|
||||
var self = this;
|
||||
|
||||
// the name of the test suite, as it will appear in the resulting XML file
|
||||
var suiteName;
|
||||
|
||||
// the default name of the test suite if none is provided
|
||||
var DEFAULT_SUITE_NAME = 'Mocha Tests';
|
||||
|
||||
if (options && options.reporterOptions) {
|
||||
if (options.reporterOptions.output) {
|
||||
if (!fs.createWriteStream) {
|
||||
throw createUnsupportedError('file output not supported in browser');
|
||||
}
|
||||
|
||||
mkdirp.sync(path.dirname(options.reporterOptions.output));
|
||||
self.fileStream = fs.createWriteStream(options.reporterOptions.output);
|
||||
}
|
||||
|
||||
// get the suite name from the reporter options (if provided)
|
||||
suiteName = options.reporterOptions.suiteName;
|
||||
}
|
||||
|
||||
// fall back to the default suite name
|
||||
suiteName = suiteName || DEFAULT_SUITE_NAME;
|
||||
|
||||
runner.on(EVENT_TEST_PENDING, function(test) {
|
||||
tests.push(test);
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_PASS, function(test) {
|
||||
tests.push(test);
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_FAIL, function(test) {
|
||||
tests.push(test);
|
||||
});
|
||||
|
||||
runner.once(EVENT_RUN_END, function() {
|
||||
self.write(
|
||||
tag(
|
||||
'testsuite',
|
||||
{
|
||||
name: suiteName,
|
||||
tests: stats.tests,
|
||||
failures: 0,
|
||||
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) {
|
||||
Base.useColors = false;
|
||||
|
||||
var attrs = {
|
||||
classname: test.parent.fullTitle(),
|
||||
name: test.title,
|
||||
time: test.duration / 1000 || 0
|
||||
};
|
||||
|
||||
if (test.state === STATE_FAILED) {
|
||||
var err = test.err;
|
||||
var diff =
|
||||
Base.hideDiff || !err.actual || !err.expected
|
||||
? ''
|
||||
: '\n' + Base.generateDiff(err.actual, err.expected);
|
||||
this.write(
|
||||
tag(
|
||||
'testcase',
|
||||
attrs,
|
||||
false,
|
||||
tag(
|
||||
'failure',
|
||||
{},
|
||||
false,
|
||||
escape(err.message) + escape(diff) + '\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;
|
||||
}
|
||||
|
||||
XUnit.description = 'XUnit-compatible XML output';
|
Reference in New Issue
Block a user