-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
58 lines (46 loc) · 1.36 KB
/
index.js
File metadata and controls
58 lines (46 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const mocha = require('mocha');
const chalk = require('chalk');
const pass = `✅`;
const error = `❌`;
const Base = mocha.reporters.Base;
function EmojiReporter(runner) {
Base.call(this, runner);
let passes = 0;
let failures = 0;
let currentIndentation = 0;
const total = runner.total;
const indent = () => {
return new Array(currentIndentation).join(' ');
};
runner.on('suite', (suite) => {
currentIndentation++;
console.log(`${indent()} ${chalk.bold.inverse(suite.title)} (${suite.file})`);
});
runner.on('suite end', (suite) => {
console.log();
currentIndentation--;
})
runner.on('test', () => {
currentIndentation++;
});
runner.on('test end', () => {
currentIndentation--;
})
runner.on('pass', (test) => {
passes++;
console.log(`${indent()} ${chalk.green.bold(`Test passed ${pass} `)} ${test.fullTitle()}`);
});
runner.on('fail', (test, err) => {
failures++;
console.log(`${indent()} ${chalk.red.bold(`Test failed ${error} `)} ${test.fullTitle()} -- error: ${err.message}`);
});
runner.on('end', () => {
if (passes === total) {
console.log (`${chalk.green.bold(`All ${total} test cases passing`)}`);
} else {
console.log(`${chalk.red.bold(`Total test cases passing: ${passes}/${total}`)}`);
}
process.exit(failures);
});
}
module.exports = EmojiReporter;