-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunning-in-docker.test.js
54 lines (46 loc) · 1.49 KB
/
running-in-docker.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
43
44
45
46
47
48
49
50
51
52
53
54
import process from 'node:process'
import test from 'ava'
import {startContainer, removeContainer} from 'sidelifter'
import getStream from 'get-stream'
import dedent from 'dedent'
test('starting Chrome in a Debian Docker container without Chrome pre-installed', async (t) => {
const container = await startContainer({
image: 'node:latest',
mount: {
[process.cwd()]: '/root/puppet-strings',
},
cmd: [
'/bin/bash',
'-c',
dedent`
cd /root
wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | apt-key add -
echo 'deb http://dl.google.com/linux/chrome/deb/ stable main' >> /etc/apt/sources.list
apt-get update -yq
apt-get install -yq google-chrome-stable
cat <<JS > index.mjs
import { openBrowser } from 'puppet-strings'
async function run() {
const { puppeteer: { browser } } = await openBrowser('/opt/google/chrome/chrome')
const page = await browser.newPage()
await page.goto('http://example.com')
console.log(await page.title())
await browser.close()
}
run()
JS
yarn add --dev link:./puppet-strings &> /dev/null
node index.mjs
`,
],
})
t.teardown(async () => {
await removeContainer(container)
})
const stdout = await getStream(container.stdout)
t.log(stdout)
t.log('===')
const stderr = await getStream(container.stderr)
t.log(stderr)
t.true(stdout.includes('Example Domain'))
})