aboutsummaryrefslogtreecommitdiffhomepage
path: root/README.md
blob: 20c2fd69101d269029deb88e833cf3756d9eab9e (plain) (blame)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# Docker Puppeteer

A 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.

See the list of [Docker Hub tags](https://hub.docker.com/r/buildkite/puppeteer/tags/) for Puppeteer versions available.

## Usage example

Dockerfile.integration-tests:

```Dockerfile
FROM buildkite/puppeteer:latest
RUN  npm i mocha
ENV  PATH="${PATH}:/node_modules/.bin"
```

docker-compose.integration-tests.yml:

```yml
version: '3'
services:
  tests:
    build:
      context: .
      dockerfile: Dockerfile.integration-tests
    volumes:
      - "./integration-tests:/integration-tests"
      - "/screenshots"
    command: mocha --recursive /integration-tests
    links:
      - app
  app:
    image: tutum/hello-world
    expose:
      - "80"
```

integration-tests/index.test.js:

```js
const assert = require('assert')
const puppeteer = require('puppeteer')

let browser
let page

before(async() => {
  browser = await puppeteer.launch({
    args: [
      // Required for Docker version of Puppeteer
      '--no-sandbox',
      '--disable-setuid-sandbox',
      // This will write shared memory files into /tmp instead of /dev/shm,
      // because Docker’s default for /dev/shm is 64MB
      '--disable-dev-shm-usage'
    ]
  })

  const browserVersion = await browser.version()
  console.log(`Started ${browserVersion}`)
})

beforeEach(async() => {
  page = await browser.newPage()
})

afterEach(async() => {
  await page.close()
})

after(async() => {
  await browser.close()
})

describe('App', () => {
  it('renders', async() => {
    const response = await page.goto('http://app/')
    assert(response.ok())
    await page.screenshot({ path: `/screenshots/app.png` })
  })
})
```

Running:

```shell
docker-compose -f docker-compose.integration-tests.yml run tests
ls screenshots/
```