-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelpers.test.js
42 lines (34 loc) · 963 Bytes
/
helpers.test.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
const { exec } = require('child_process')
const { onlyOnce, stop } = require('./helpers')
jest.mock('child_process')
describe('helpers', () => {
describe('onlyOnce', () => {
test('calls callback only once', () => {
const once = onlyOnce()
const callback = jest.fn()
once(callback)
once(callback)
once(callback)
expect(callback).toHaveBeenCalledTimes(1)
})
})
describe('stop', () => {
test('calls docker-compose with the correct service', async () => {
const SERVICE = 'my-super-service'
const CALLBACKS = {}
const PROCESS = {
on: (event, callback) => {
CALLBACKS[event] = callback
},
}
exec.mockImplementation(() => {
CALLBACKS.close()
})
await stop(SERVICE, PROCESS)
expect(exec).toHaveBeenCalledWith(
`docker-compose stop ${SERVICE}`,
expect.any(Function), // the callback func
)
})
})
})