/
resolveTaskFn.unmocked.spec.js
40 lines (33 loc) · 1.11 KB
/
resolveTaskFn.unmocked.spec.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
import { resolveTaskFn } from '../lib/resolveTaskFn'
import { getInitialState } from '../lib/state'
jest.unmock('execa')
describe('resolveTaskFn', () => {
it('should call execa with shell when configured so', async () => {
const taskFn = resolveTaskFn({
command: 'node -e "process.exit(1)" || echo $?',
files: ['package.json'],
isFn: true,
shell: true,
})
await expect(taskFn()).resolves.toMatchInlineSnapshot(`undefined`)
})
it('should kill a long running task when another fails', async () => {
const context = getInitialState()
const taskFn = resolveTaskFn({
command: 'node -e "while(true) {}"',
isFn: true,
})
const taskPromise = taskFn(context)
const taskFn2 = resolveTaskFn({
command: 'node -e "process.exit(1)"',
isFn: true,
})
const task2Promise = taskFn2(context)
await expect(task2Promise).rejects.toThrowErrorMatchingInlineSnapshot(
`"node -e \\"process.exit(1)\\" [FAILED]"`
)
await expect(taskPromise).rejects.toThrowErrorMatchingInlineSnapshot(
`"node -e \\"while(true) {}\\" [KILLED]"`
)
})
})