Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save craigtaub/c8cd7fae5e6fbed56d8982c43211a9fc to your computer and use it in GitHub Desktop.
Save craigtaub/c8cd7fae5e6fbed56d8982c43211a9fc to your computer and use it in GitHub Desktop.
// lib/stats-collector.js
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(Runner.constants.EVENT_RUN_BEGIN, function () {
stats.start = new Date();
});
runner.on(Runner.constants.EVENT_SUITE_BEGIN, function (suite) {
suite.root || stats.suites++;
});
runner.on(Runner.constants.EVENT_TEST_PASS, function () {
stats.passes++;
});
runner.on(Runner.constants.EVENT_TEST_FAIL, function () {
stats.failures++;
});
runner.on(Runner.constants.EVENT_TEST_END, function () {
stats.tests++;
});
runner.once(Runner.constants.EVENT_RUN_END, function () {
stats.end = new Date();
stats.duration = stats.end - stats.start;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment