diff options
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 85 |
1 files changed, 77 insertions, 8 deletions
@@ -1,17 +1,86 @@ | |||
1 | # Docker Puppeteer | 1 | # Docker Puppeteer |
2 | 2 | ||
3 | A Puppeteer Docker image based on [Puppeteer’s own recommendations](https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md#running-puppeteer-in-docker). | 3 | Node 8 + Puppeteer docker base image. Use it to add your own tools (such as a testing framework), configure any linked containers via your Docker Compose config, and run your Puppeteer scripts. |
4 | 4 | ||
5 | An example for how to use: | 5 | ## Usage example |
6 | |||
7 | Dockerfile.integration-tests: | ||
6 | 8 | ||
7 | ```Dockerfile | 9 | ```Dockerfile |
8 | FROM buildkite/puppeteer | 10 | FROM buildkite/puppeteer:1.1.1 |
11 | RUN npm i mocha@5 | ||
12 | ENV PATH="${PATH}:/node_modules/.bin" | ||
13 | ``` | ||
14 | |||
15 | docker-compose.integration-tests.yml: | ||
16 | |||
17 | ```yml | ||
18 | version: '3' | ||
19 | services: | ||
20 | tests: | ||
21 | build: | ||
22 | context: . | ||
23 | dockerfile: Dockerfile.integration-tests | ||
24 | volumes: | ||
25 | - "./integration-tests:/integration-tests" | ||
26 | - "/screenshots" | ||
27 | command: mocha --recursive /integration-tests | ||
28 | links: | ||
29 | - app | ||
30 | app: | ||
31 | image: tutum/hello-world | ||
32 | expose: | ||
33 | - "80" | ||
34 | ``` | ||
35 | |||
36 | integration-tests/index.test.js: | ||
37 | |||
38 | ```js | ||
39 | const assert = require('assert') | ||
40 | const puppeteer = require('puppeteer') | ||
9 | 41 | ||
10 | RUN npm install mocha | 42 | let browser |
11 | ENV PATH="${PATH}:/node_modules/.bin" | 43 | let page |
44 | |||
45 | before(async() => { | ||
46 | browser = await puppeteer.launch({ | ||
47 | args: [ | ||
48 | // Required for Docker version of Puppeteer | ||
49 | '--no-sandbox', | ||
50 | '--disable-setuid-sandbox', | ||
51 | // This will write shared memory files into /tmp instead of /dev/shm, | ||
52 | // because Docker’s default for /dev/shm is 64MB | ||
53 | '--disable-dev-shm-usage' | ||
54 | ] | ||
55 | }) | ||
56 | |||
57 | const browserVersion = await browser.version() | ||
58 | console.log(`Started ${browserVersion}`) | ||
59 | }) | ||
60 | |||
61 | beforeEach(async() => { | ||
62 | page = await browser.newPage() | ||
63 | }) | ||
64 | |||
65 | afterEach(async() => { | ||
66 | await page.close() | ||
67 | }) | ||
68 | |||
69 | after(async() => { | ||
70 | await browser.close() | ||
71 | }) | ||
72 | |||
73 | describe('App', () => { | ||
74 | it('renders', async() => { | ||
75 | const response = await page.goto('http://app/') | ||
76 | assert(response.ok()) | ||
77 | await page.screenshot({ path: `/screenshots/app.png` }) | ||
78 | }) | ||
79 | }) | ||
80 | ``` | ||
12 | 81 | ||
13 | # The `tests` dir is expected to be mounted into here | 82 | Running: |
14 | WORK_DIR /home/pptr | ||
15 | 83 | ||
16 | CMD ["mocha", "--recursive", "tests"] | ||
17 | ``` | 84 | ``` |
85 | docker-compose -f integration-tests run tests | ||
86 | ``` \ No newline at end of file | ||