-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunner.js
More file actions
95 lines (76 loc) · 1.95 KB
/
runner.js
File metadata and controls
95 lines (76 loc) · 1.95 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
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
'use strict'
/* @flow */
const _atom = require('atom')
const Mocha = require('mocha')
class TestRunner {
constructor (testFile) {
this.emitter = new _atom.Emitter()
this.mocha = new Mocha({
reporter: 'json-stream'
})
this.mocha.addFile(testFile)
this.args = [testFile]
}
run () {
this.runId = 0
this.emitter.emit('stderr', { runId: this.runId, data: `> mocha ${this.args.join(' ')}` })
const runner = this.mocha.run()
runner.on('pass', (event) => {
this.emitter.emit('run-test', { testInfo: { name: event.title, durationSecs: event.duration, status: 1 } })
})
runner.on('fail', (event) => {
const durationSecs = event.duration / 1000
const status = event.timedOut ? 4 : 2
const test_json = {
className: 'n/a',
name: event.ctx.test.parent.title,
fileName: event.file,
id: 'n/a'
}
this.emitter.emit('run-test', { testInfo: { name: event.title, durationSecs, summary: 'SUMMARY', status, test_json } })
})
runner.on('test', (event) => {
++this.runId
})
runner.on('suite', (event) => {
this.emitter.emit('start', { testInfo: { name: event.title } })
})
runner.on('end', (event) => {
// this.emitter.emit('summary', { testInfo: { test_json: { id: 0 }, } })
this.finallyFn(this.runId)
})
// pending
}
do (fn) {
this.doFn = fn
return this
}
finally (fn) {
this.finallyFn = fn
return this
}
subscribe () {
for (let event of ['summary', 'run-test', 'start', 'error', 'stdout', 'stderr']) {
this.emitter.on(event, (m) => {
m.kind = event
this.doFn(m)
})
}
this.run()
return this
}
unsubscribe () {
this.emitter.dispose()
return this
}
}
module.exports = {
provideTestRunner: (service) => {
return {
label: 'Mocha',
runTest: (openFilePath) => {
return new TestRunner(openFilePath)
}
}
}
}