-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunMocha.js
66 lines (49 loc) · 1.5 KB
/
runMocha.js
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
59
60
61
62
63
64
65
66
const Mocha = require("mocha");
const { Writable } = require("stream");
function runMochaTests(testPath) {
return new Promise((resolve, reject) => {
const Mocha = require('mocha');
const mocha = new Mocha({ reporter: 'json-stream' });
mocha.addFile(testPath);
const results = {
tests: [],
};
const runner = mocha.run((failures) => {
resolve(results);
});
runner.on('test', (test) => {
// Можно что то делать с тестами
});
runner.on('pass', (test) => {
results.tests.push({
title: test.title,
suite: test.parent.title,
passed: test.isPassed(),
});
});
runner.on('fail', (test, err) => {
results.tests.push({
title: test.title,
suite: test.parent.title,
passed: test.isPassed(),
err: {
message: err.message,
stack: err.stack
}
});
});
return results;
});
}
function showTestResults(results){
console.log("\n-------\n")
for (const test of results.tests) {
if (test.passed){
console.log(`✅ ${test.suite}: ${test.title}`)
} else {
console.log(`❌ ${test.suite}: ${test.title}`)
}
}
console.log("\n-------")
}
module.exports = { runMochaTests, showTestResults};