-
Notifications
You must be signed in to change notification settings - Fork 37
/
jest.sanity.setup.js
36 lines (33 loc) · 1.14 KB
/
jest.sanity.setup.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
const Dockerode = require('dockerode')
const path = require('path')
const { pack } = require('tar-fs')
const apps = ['whale-api']
module.exports = async function () {
console.log('\nPreloading sanity images, this may take a while...')
await Promise.all(apps.map(build))
}
/**
* Builds a new image with a :sanity tag that can be pulled into unit tests and
* run on the current state of the code base. These steps are required to
* ensure that we are sanity testing against the current code state and not
* pre-built solutions which is tested seperately during our standard unit
* tests.
*
* @remarks Images are built with tar
* @see https://github.com/apocas/dockerode/issues/432
*/
async function build (app) {
console.log(`Building '${app}:sanity' image`)
const docker = new Dockerode()
const image = pack(path.resolve(__dirname))
const stream = await docker.buildImage(image, {
t: `${app}:sanity`,
buildargs: {
APP: app
}
})
await new Promise((resolve, reject) => {
docker.modem.followProgress(stream, (err, res) => (err != null) ? reject(err) : resolve(res))
})
console.log(`Finished '${app}:sanity' image`)
}