/
util.ts
32 lines (29 loc) · 899 Bytes
/
util.ts
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
import { spawn } from 'child_process'
import DoneCallback = jest.DoneCallback
export function setup (done: DoneCallback) {
teardown()
setTimeout(() => {
const yarnAddGlobal = spawn('yarn', ['global:add'])
yarnAddGlobal.stderr.on('error', (error) => done(error))
yarnAddGlobal.on('close', done)
}, 6000)
}
export function teardown (done?: DoneCallback) {
const yarnRemoveGlobal = spawn('yarn', ['global:remove'])
yarnRemoveGlobal.stderr.on('error', (error) => {
if (done !== undefined) done(error)
})
yarnRemoveGlobal.on('close', () => {
if (done !== undefined) done()
})
}
export function dockerCommandCleanup (done: DoneCallback) {
const cgqlCleanup = spawn('cgql', ['docker', 'cleanup', '-f'])
cgqlCleanup.stderr.on('error', (error) => {
console.error(error)
if (error) return done(error)
})
cgqlCleanup.on('close', () => {
done()
})
}