diff options
Diffstat (limited to 'node_modules/mocha/lib/reporters/doc.js')
-rw-r--r-- | node_modules/mocha/lib/reporters/doc.js | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/node_modules/mocha/lib/reporters/doc.js b/node_modules/mocha/lib/reporters/doc.js new file mode 100644 index 000000000..01f3fdc9d --- /dev/null +++ b/node_modules/mocha/lib/reporters/doc.js @@ -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)); + }); +} |