diff options
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 86 |
1 files changed, 6 insertions, 80 deletions
@@ -2,88 +2,14 @@ | |||
2 | 2 | ||
3 | 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. | 3 | 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. |
4 | 4 | ||
5 | See the list of [Docker Hub tags](https://hub.docker.com/r/buildkite/puppeteer/tags/) for Puppeteer versions available. | 5 | ## Versions |
6 | |||
7 | ## Usage example | ||
8 | |||
9 | Dockerfile.integration-tests: | ||
10 | |||
11 | ```Dockerfile | ||
12 | FROM buildkite/puppeteer:latest | ||
13 | RUN npm i mocha | ||
14 | ENV PATH="${PATH}:/node_modules/.bin" | ||
15 | ``` | ||
16 | |||
17 | docker-compose.integration-tests.yml: | ||
18 | |||
19 | ```yml | ||
20 | version: '3' | ||
21 | services: | ||
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 | |||
38 | integration-tests/index.test.js: | ||
39 | 6 | ||
40 | ```js | 7 | See the list of [Docker Hub tags](https://hub.docker.com/r/buildkite/puppeteer/tags/) for Puppeteer versions available. |
41 | const assert = require('assert') | ||
42 | const puppeteer = require('puppeteer') | ||
43 | |||
44 | let browser | ||
45 | let page | ||
46 | |||
47 | before(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 | |||
63 | beforeEach(async() => { | ||
64 | page = await browser.newPage() | ||
65 | }) | ||
66 | |||
67 | afterEach(async() => { | ||
68 | await page.close() | ||
69 | }) | ||
70 | 8 | ||
71 | after(async() => { | 9 | ## Example |
72 | await browser.close() | ||
73 | }) | ||
74 | 10 | ||
75 | describe('App', () => { | 11 | See the [example directory](example) for a complete Docker Compose example, showing how to run Puppeteer against a linked Docker Compose web service. |
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 | 12 | ||
84 | Running: | 13 | ## Dependent Services |
85 | 14 | ||
86 | ```shell | 15 | This image includes [wait-for-it.sh](https://github.com/vishnubob/wait-for-it) which can be useful if you need to wait for a dependent web service to start accepting requests before your Puppeteer container attempts connecting to it. See [the example](example) for usage. |
87 | docker-compose -f docker-compose.integration-tests.yml run tests | ||
88 | ls screenshots/ | ||
89 | ``` | ||