Skip to content

Commit

Permalink
fix custom reporter and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
boneskull committed Feb 1, 2019
1 parent 929eeb5 commit 50bfcd7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
7 changes: 3 additions & 4 deletions docs/api-tutorials/custom-reporter.md
Expand Up @@ -22,8 +22,6 @@ const {
// this reporter outputs test results, indenting two spaces per suite
class MyReporter {
constructor(runner) {
super(runner);

this._indents = 0;

runner
Expand All @@ -46,7 +44,8 @@ class MyReporter {
`${this.indent()}fail: ${test.fullTitle()} - error: ${err.message}`
);
})
.once(EVENT_RUN_END, () => {
.once(EVENT_RUN_END, function() {
// this is Runner
console.log(
`end: ${this.stats.passes}/${this.stats.passes +
this.stats.failures} ok`
Expand Down Expand Up @@ -84,7 +83,7 @@ It's often useful--but not necessary--for a custom reporter to extend [Base].

## Statistics

Mocha adds a `stats` property of type [StatsCollector](/api/module-lib_stats-collector.html) to each reporter instance immediately following instantiation.
Mocha adds a `stats` property of type [StatsCollector](/api/module-lib_stats-collector.html) to the reporter's `Runner` instance (passed as first argument to constructor).

## Events

Expand Down
5 changes: 2 additions & 3 deletions test/integration/fixtures/simple-reporter.js
Expand Up @@ -13,8 +13,6 @@ const {
// this reporter outputs test results, indenting two spaces per suite
class MyReporter {
constructor(runner) {
super(runner);

this._indents = 0;

runner
Expand All @@ -37,7 +35,8 @@ class MyReporter {
`${this.indent()}fail: ${test.fullTitle()} - error: ${err.message}`
);
})
.once(EVENT_RUN_END, () => {
.once(EVENT_RUN_END, function () {
// this is Runner
console.log(
`end: ${this.stats.passes}/${this.stats.passes +
this.stats.failures} ok`
Expand Down

0 comments on commit 50bfcd7

Please sign in to comment.