-
-
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.
* collect stats
- Loading branch information
Showing
6 changed files
with
92 additions
and
52 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
'use strict'; | ||
|
||
/** | ||
* Test statistics collector. | ||
* | ||
* @typedef {Object} StatsCollector | ||
* @property {number} suites - integer count of suites run. | ||
* @property {number} tests - integer count of tests run. | ||
* @property {number} passes - integer count of passing tests. | ||
* @property {number} pending - integer count of pending tests. | ||
* @property {number} failures - integer count of failed tests. | ||
* @property {Date} start - time when testing began. | ||
* @property {Date} end - time when testing concluded. | ||
* @property {number} duration - number of msecs that testing took. | ||
*/ | ||
|
||
/** | ||
* Provides stats such as test duration, | ||
* number of tests passed / failed etc. | ||
* | ||
* @public | ||
* @memberof Mocha | ||
* @param {Runner} runner | ||
*/ | ||
function createStatsCollector(runner) { | ||
var stats = { | ||
suites: 0, | ||
tests: 0, | ||
passes: 0, | ||
pending: 0, | ||
failures: 0 | ||
}; | ||
|
||
if (!runner) { | ||
throw new TypeError('Missing runner argument'); | ||
} | ||
|
||
runner.stats = stats; | ||
|
||
runner.once('start', function() { | ||
stats.start = new Date(); | ||
}); | ||
|
||
runner.on('suite', function(suite) { | ||
suite.root || stats.suites++; | ||
}); | ||
|
||
runner.on('pass', function() { | ||
stats.passes++; | ||
}); | ||
|
||
runner.on('fail', function() { | ||
stats.failures++; | ||
}); | ||
|
||
runner.on('pending', function() { | ||
stats.pending++; | ||
}); | ||
|
||
runner.on('test end', function() { | ||
stats.tests++; | ||
}); | ||
|
||
runner.once('end', function() { | ||
stats.end = new Date(); | ||
stats.duration = stats.end - stats.start; | ||
}); | ||
} | ||
|
||
module.exports = createStatsCollector; |
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