forked from ArnaudBuchholz/ui5-test-runner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
104 lines (97 loc) · 2.45 KB
/
index.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
97
98
99
100
101
102
103
104
#!/usr/bin/env node
'use strict'
const { serve } = require('reserve')
const { fromCmdLine } = require('./src/job')
const { getOutput } = require('./src/output')
const reserveConfigurationFactory = require('./src/reserve')
const { execute } = require('./src/tests')
const { capabilities } = require('./src/capabilities')
const { watch } = require('fs')
const { recreateDir } = require('./src/tools')
function send (message) {
if (process.send) {
process.send({
pid: process.pid,
...message
})
}
}
async function notifyAndExecuteTests (job, output) {
send({ msg: 'begin' })
try {
await execute(job)
let status
if (job.failed) {
status = -1
} else {
status = 0
}
send({ msg: 'end', status })
} catch (error) {
getOutput(job).genericError(error)
send({ msg: 'error', error })
}
}
let job
let output
async function main () {
job = fromCmdLine(process.cwd(), process.argv.slice(2))
output = getOutput(job)
await recreateDir(job.reportDir)
if (job.mode === 'capabilities') {
output.version()
return capabilities(job)
}
const configuration = await reserveConfigurationFactory(job)
const server = serve(configuration)
if (job.logServer) {
server.on('redirected', output.redirected)
}
server
.on('ready', async ({ url, port }) => {
job.port = port
send({ msg: 'ready', port: job.port })
output.serving(url)
output.reportOnJobProgress()
if (job.serveOnly) {
job.status = 'Serving'
return
}
await notifyAndExecuteTests(job)
if (job.watch) {
delete job.start
if (!job.watching) {
output.watching(job.webapp)
watch(job.webapp, { recursive: true }, (eventType, filename) => {
output.changeDetected(eventType, filename)
if (!job.start) {
notifyAndExecuteTests(job)
}
})
job.watching = true
}
} else if (job.keepAlive) {
job.status = 'Serving'
} else if (job.failed) {
output.stop()
process.exit(-1)
} else {
output.stop()
process.exit(0)
}
})
.on('error', error => {
output.serverError(error)
send({ msg: 'error', error })
})
}
main()
.catch(reason => {
if (output) {
output.genericError(reason)
output.stop()
} else if (reason.name !== 'CommanderError') {
console.error(reason)
}
process.exit(-1)
})