-
Notifications
You must be signed in to change notification settings - Fork 1
/
index-with-reporter.js
96 lines (84 loc) · 2.38 KB
/
index-with-reporter.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const { execFile } = require('child_process')
const path = require('path')
const supposed = require('supposed')
const reporter = supposed.reporterFactory.get('list')
let started = false
const suites = [
'./first-module/first-suite.js',
'./second-module/second-suite.js'
]
const promises = suites.map((suite) => new Promise((resolve, reject) => {
execFile('node', [path.join(__dirname, suite)], (error, stdout, stderr) => {
if (error) {
return reject(error)
}
try {
const events = JSON.parse(stdout).map((row) => row.event)
if (!started) {
started = true
reporter.write(events.find((event) => event.type === 'START'))
}
events.forEach((event) => {
if (event.type === 'TEST') {
reporter.write(event)
}
})
resolve({ suite, events })
} catch (e) {
e.stdout = stdout
throw e
}
})
}))
Promise.all(promises)
.then((results) => {
const errors = []
const totals = results
.map((result) => {
const endEvent = result.events.find((event) => event.type === 'END')
if (endEvent.totals.failed > 0) {
errors.push(result)
}
return {
suite: result.suite,
total: endEvent.totals.total,
passed: endEvent.totals.passed,
failed: endEvent.totals.failed,
broken: endEvent.totals.broken,
skipped: endEvent.totals.skipped,
duration: endEvent.totals.duration
}
})
.reduce((totals, row) => {
totals.total += row.total
totals.passed += row.passed
totals.failed += row.failed
totals.broken += row.broken
totals.skipped += row.skipped
totals.duration.seconds += row.duration.seconds
totals.duration.milliseconds += row.duration.milliseconds
totals.duration.microseconds += row.duration.microseconds
totals.duration.nanoseconds += row.duration.nanoseconds
return totals
}, {
total: 0,
passed: 0,
failed: 0,
broken: 0,
skipped: 0,
duration: {
seconds: 0,
milliseconds: 0,
microseconds: 0,
nanoseconds: 0
}
})
reporter.write({ type: 'END', totals })
if (errors.length) {
console.log(errors)
process.exit(1)
}
}).catch((err) => {
console.log(err)
process.exit(1)
})