]> git.immae.eu Git - github/fretlink/docker-puppeteer.git/blame_incremental - README.md
Update node Docker tag to v10.5.0-slim
[github/fretlink/docker-puppeteer.git] / README.md
... / ...
CommitLineData
1# Docker Puppeteer
2
3A Node + Puppeteer base image for running Puppeteer scripts. Add your own tools (such as Jest, Mocha, etc), link services you want to test via Docker Compose, and run your Puppeteer scripts with a headless Chromium.
4
5See the list of [Docker Hub tags](https://hub.docker.com/r/buildkite/puppeteer/tags/) for Puppeteer versions available.
6
7## Usage example
8
9Dockerfile.integration-tests:
10
11```Dockerfile
12FROM buildkite/puppeteer:version
13RUN npm i mocha
14ENV PATH="${PATH}:/node_modules/.bin"
15```
16
17docker-compose.integration-tests.yml:
18
19```yml
20version: '3'
21services:
22 tests:
23 build:
24 context: .
25 dockerfile: Dockerfile.integration-tests
26 volumes:
27 - "./integration-tests:/integration-tests"
28 - "/screenshots"
29 command: mocha --recursive /integration-tests
30 links:
31 - app
32 app:
33 image: tutum/hello-world
34 expose:
35 - "80"
36```
37
38integration-tests/index.test.js:
39
40```js
41const assert = require('assert')
42const puppeteer = require('puppeteer')
43
44let browser
45let page
46
47before(async() => {
48 browser = await puppeteer.launch({
49 args: [
50 // Required for Docker version of Puppeteer
51 '--no-sandbox',
52 '--disable-setuid-sandbox',
53 // This will write shared memory files into /tmp instead of /dev/shm,
54 // because Docker’s default for /dev/shm is 64MB
55 '--disable-dev-shm-usage'
56 ]
57 })
58
59 const browserVersion = await browser.version()
60 console.log(`Started ${browserVersion}`)
61})
62
63beforeEach(async() => {
64 page = await browser.newPage()
65})
66
67afterEach(async() => {
68 await page.close()
69})
70
71after(async() => {
72 await browser.close()
73})
74
75describe('App', () => {
76 it('renders', async() => {
77 const response = await page.goto('http://app/')
78 assert(response.ok())
79 await page.screenshot({ path: `/screenshots/app.png` })
80 })
81})
82```
83
84Running:
85
86```
87docker-compose -f integration-tests run tests
88```