UNPKG

1.27 kBPlain TextView Raw
1import Docker from 'dockerode'
2import DockerExecutor from '../src/DockerExecutor'
3import { fixture } from './test-functions'
4
5const docker = new Docker
6const executor = new DockerExecutor
7
8jest.setTimeout(30 * 60 * 1000)
9
10/**
11 * Tests of executing container
12 */
13
14test('execute:stdout', async () => {
15
16 let build = await docker.buildImage({
17 context: fixture('dockerfile-execute-stdout'),
18 src: ['Dockerfile']
19 }, {t: 'dockerfile-execute-stdout'})
20
21 let built = await docker.modem.followProgress(build, onFinished)
22
23 async function onFinished () {
24 let output = await executor.execute('dockerfile-execute-stdout', __dirname)
25 expect(output).toEqual('hello')
26 }
27
28})
29
30test('execute:stderr', async () => {
31
32 let build = await docker.buildImage({
33 context: fixture('dockerfile-execute-stderr'),
34 src: ['Dockerfile']
35 }, {t: 'dockerfile-execute-stderr'})
36
37 let built = await docker.modem.followProgress(build, onFinished)
38
39 async function onFinished () {
40 let outputError = ''
41
42 const spy = jest.spyOn(console,'error')
43 .mockImplementation((data:string) => {
44 outputError += data
45 })
46
47 await executor.execute('dockerfile-execute-stderr', __dirname)
48
49 expect(outputError.trim()).toBe('epicfail')
50
51 spy.mockRestore()
52 }
53
54})