Skip to content

Commit

Permalink
Added doc reporter. Closes #33
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Nov 17, 2011
1 parent 8a1bf99 commit f5a9941
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 0 deletions.
69 changes: 69 additions & 0 deletions lib/reporters/doc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@

/**
* Module dependencies.
*/

var Base = require('./base');

/**
* Expose `Doc`.
*/

exports = module.exports = Doc;

/**
* Initialize a new `Doc` reporter.
*
* @param {Runner} runner
* @api public
*/

function Doc(runner) {
Base.call(this, runner);

var self = this
, stats = this.stats
, total = runner.total
, 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(), 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(), test.title);
var code = strip(test.fn.toString());
console.log('%s<dd><pre><code>%s</code></pre></dd>', indent(), code);
});

runner.on('end', function(){
process.exit(stats.failures);
});
}

/**
* Strip the function definition from `str`.
*/

function strip(str) {
return str
.replace(/^function *\(.*\) *{\s*/, '')
.replace(/\s+\}$/, '');
}
1 change: 1 addition & 0 deletions lib/reporters/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

exports.Base = require('./base');
exports.Dot = require('./dot');
exports.Doc = require('./doc');
exports.TAP = require('./tap');
exports.JSON = require('./json');
exports.List = require('./list');
Expand Down
1 change: 1 addition & 0 deletions lib/suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function Suite(title) {
this.beforeEachCallbacks = [];
this.afterAllCallbacks = [];
this.afterEachCallbacks = [];
this.root = !title;
}

/**
Expand Down
10 changes: 10 additions & 0 deletions test/interfaces/bdd.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,13 @@ describe('Array', function(){
})
})
})

describe('Array', function(){
describe('#pop()', function(){
it('should remove and return the last value', function(){
var arr = [1,2,3];
arr.pop().should.equal(3);
arr.should.eql([1,2]);
})
})
})

0 comments on commit f5a9941

Please sign in to comment.