diff options
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 86 |
1 files changed, 4 insertions, 82 deletions
@@ -2,88 +2,10 @@ | |||
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 | |||
40 | ```js | ||
41 | const assert = require('assert') | ||
42 | const puppeteer = require('puppeteer') | ||
43 | 6 | ||
44 | let browser | 7 | See the list of [Docker Hub tags](https://hub.docker.com/r/buildkite/puppeteer/tags/) for Puppeteer versions available. |
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 | |||
71 | after(async() => { | ||
72 | await browser.close() | ||
73 | }) | ||
74 | |||
75 | describe('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 | 8 | ||
84 | Running: | 9 | ## Example |
85 | 10 | ||
86 | ```shell | 11 | See the [example directory](example) for a complete Docker Compose example, showing how to run Puppeteer against a linked Docker Compose web service. |
87 | docker-compose -f docker-compose.integration-tests.yml run tests | ||
88 | ls screenshots/ | ||
89 | ``` | ||