| 1 |
'use strict'; |
| 2 |
|
| 3 |
const Mocha = require('../../..'); |
| 4 |
const { |
| 5 |
EVENT_RUN_BEGIN, |
| 6 |
EVENT_RUN_END, |
| 7 |
EVENT_TEST_FAIL, |
| 8 |
EVENT_TEST_PASS, |
| 9 |
EVENT_SUITE_BEGIN, |
| 10 |
EVENT_SUITE_END |
| 11 |
} = Mocha.Runner.constants; |
| 12 |
|
| 13 |
|
| 14 |
class MyReporter { |
| 15 |
constructor(runner) { |
| 16 |
this._indents = 0; |
| 17 |
const stats = runner.stats; |
| 18 |
|
| 19 |
runner |
| 20 |
.once(EVENT_RUN_BEGIN, () => { |
| 21 |
console.log('start'); |
| 22 |
}) |
| 23 |
.on(EVENT_SUITE_BEGIN, () => { |
| 24 |
this.increaseIndent(); |
| 25 |
}) |
| 26 |
.on(EVENT_SUITE_END, () => { |
| 27 |
this.decreaseIndent(); |
| 28 |
}) |
| 29 |
.on(EVENT_TEST_PASS, test => { |
| 30 |
|
| 31 |
|
| 32 |
console.log(`${this.indent()}pass: ${test.fullTitle()}`); |
| 33 |
}) |
| 34 |
.on(EVENT_TEST_FAIL, (test, err) => { |
| 35 |
console.log( |
| 36 |
`${this.indent()}fail: ${test.fullTitle()} - error: ${err.message}` |
| 37 |
); |
| 38 |
}) |
| 39 |
.once(EVENT_RUN_END, () => { |
| 40 |
console.log(`end: ${stats.passes}/${stats.passes + stats.failures} ok`); |
| 41 |
}); |
| 42 |
} |
| 43 |
|
| 44 |
indent() { |
| 45 |
return Array(this._indents).join(' '); |
| 46 |
} |
| 47 |
|
| 48 |
increaseIndent() { |
| 49 |
this._indents++; |
| 50 |
} |
| 51 |
|
| 52 |
decreaseIndent() { |
| 53 |
this._indents--; |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
module.exports = MyReporter; |