Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify runner and reporters to use JSON serializable results #685

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 12 additions & 20 deletions lib/reporters/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ exports.list = function(failures){
stack = stack.slice(index ? index + 1 : index)
.replace(/^/gm, ' ');

console.error(fmt, (i + 1), test.fullTitle(), msg, stack);
console.error(fmt, (i + 1), test.fullTitle, msg, stack);
});
};

Expand All @@ -213,8 +213,8 @@ exports.list = function(failures){
*
* All other reporters generally
* inherit from this reporter, providing
* stats such as test duration, number
* of tests passed / failed etc.
* stats such as number of tests passed /
* failed etc.
*
* @param {Runner} runner
* @api public
Expand All @@ -230,43 +230,35 @@ function Base(runner) {

runner.stats = stats;

runner.on('start', function(){
stats.start = new Date;
runner.on('start', function(time){
stats.start = new Date(time);
});

runner.on('suite', function(suite){
runner.on('suite start', function(time, suite){
stats.suites = stats.suites || 0;
suite.root || stats.suites++;
});

runner.on('test end', function(test){
runner.on('test end', function(){
stats.tests = stats.tests || 0;
stats.tests++;
});

runner.on('pass', function(test){
runner.on('pass', function(){
stats.passes = stats.passes || 0;

var medium = test.slow() / 2;
test.speed = test.duration > test.slow()
? 'slow'
: test.duration > medium
? 'medium'
: 'fast';

stats.passes++;
});

runner.on('fail', function(test, err){
runner.on('fail', function(time, 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('end', function(time){
stats.end = new Date(time);
stats.duration = stats.end - stats.start;
});

runner.on('pending', function(){
Expand Down
8 changes: 4 additions & 4 deletions lib/reporters/doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function Doc(runner) {
return Array(indents).join(' ');
}

runner.on('suite', function(suite){
runner.on('suite start', function(time, suite){
if (suite.root) return;
++indents;
console.log('%s<section class="suite">', indent());
Expand All @@ -40,17 +40,17 @@ function Doc(runner) {
console.log('%s<dl>', indent());
});

runner.on('suite end', function(suite){
runner.on('suite end', function(time, suite){
if (suite.root) return;
console.log('%s</dl>', indent());
--indents;
console.log('%s</section>', indent());
--indents;
});

runner.on('pass', function(test){
runner.on('pass', function(time, test){
console.log('%s <dt>%s</dt>', indent(), utils.escape(test.title));
var code = utils.escape(utils.clean(test.fn.toString()));
var code = utils.escape(utils.clean(test.fn));
console.log('%s <dd><pre><code>%s</code></pre></dd>', indent(), code);
});
}
6 changes: 3 additions & 3 deletions lib/reporters/dot.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ function Dot(runner) {
process.stdout.write('\n ');
});

runner.on('pending', function(test){
runner.on('pending', function(){
process.stdout.write(color('pending', Base.symbols.dot));
});

runner.on('pass', function(test){
runner.on('pass', function(time, test){
if (++n % width == 0) process.stdout.write('\n ');
if ('slow' == test.speed) {
process.stdout.write(color('bright yellow', Base.symbols.dot));
Expand All @@ -44,7 +44,7 @@ function Dot(runner) {
}
});

runner.on('fail', function(test, err){
runner.on('fail', function(){
if (++n % width == 0) process.stdout.write('\n ');
process.stdout.write(color('fail', Base.symbols.dot));
});
Expand Down
12 changes: 6 additions & 6 deletions lib/reporters/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function HTML(runner, root) {

if (progress) progress.size(40);

runner.on('suite', function(suite){
runner.on('suite start', function(time, suite){
if (suite.root) return;

// suite
Expand All @@ -110,24 +110,24 @@ function HTML(runner, root) {
el.appendChild(stack[0]);
});

runner.on('suite end', function(suite){
runner.on('suite end', function(time, suite){
if (suite.root) return;
stack.shift();
});

runner.on('fail', function(test, err){
if ('hook' == test.type) runner.emit('test end', test);
runner.on('fail', function(time, test, err){
if ('hook' == test.type) runner.emit('test end', time, test);
});

runner.on('test end', function(test){
runner.on('test end', function(time, test){
window.scrollTo(0, document.body.scrollHeight);

// 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;
var ms = new Date(time) - stats.start;
text(passes, stats.passes);
text(failures, stats.failures);
text(duration, (ms / 1000).toFixed(2));
Expand Down
6 changes: 3 additions & 3 deletions lib/reporters/json-cov.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ function JSONCov(runner, output) {
, failures = []
, passes = [];

runner.on('test end', function(test){
runner.on('test end', function(time, test){
tests.push(test);
});

runner.on('pass', function(test){
runner.on('pass', function(time, test){
passes.push(test);
});

runner.on('fail', function(test){
runner.on('fail', function(time, test){
failures.push(test);
});

Expand Down
6 changes: 3 additions & 3 deletions lib/reporters/json-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ function List(runner) {
console.log(JSON.stringify(['start', { total: total }]));
});

runner.on('pass', function(test){
runner.on('pass', function(time, test){
console.log(JSON.stringify(['pass', clean(test)]));
});

runner.on('fail', function(test, err){
runner.on('fail', function(time, test, err){
console.log(JSON.stringify(['fail', clean(test)]));
});

Expand All @@ -55,7 +55,7 @@ function List(runner) {
function clean(test) {
return {
title: test.title
, fullTitle: test.fullTitle()
, fullTitle: test.fullTitle
, duration: test.duration
}
}
8 changes: 4 additions & 4 deletions lib/reporters/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ function JSONReporter(runner) {
, failures = []
, passes = [];

runner.on('test end', function(test){
runner.on('test end', function(time, test){
tests.push(test);
});

runner.on('pass', function(test){
runner.on('pass', function(time, test){
passes.push(test);
});

runner.on('fail', function(test){
runner.on('fail', function(time, test){
failures.push(test);
});

Expand Down Expand Up @@ -64,7 +64,7 @@ function JSONReporter(runner) {
function clean(test) {
return {
title: test.title
, fullTitle: test.fullTitle()
, fullTitle: test.fullTitle
, duration: test.duration
}
}
Loading