-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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+\}$/, ''); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters