From 40876fe8ad7b884004ed5f47ac66ce79b0e9ad14 Mon Sep 17 00:00:00 2001 From: Tim Lucas Date: Wed, 6 Feb 2019 10:57:32 +1100 Subject: Update README.md --- README.md | 86 +++---------------------------------------------------- example/README.md | 17 +++++++++++ 2 files changed, 21 insertions(+), 82 deletions(-) create mode 100644 example/README.md diff --git a/README.md b/README.md index 20c2fd6..4b24e2d 100644 --- a/README.md +++ b/README.md @@ -2,88 +2,10 @@ 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') +## Versions -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` }) - }) -}) -``` +See the list of [Docker Hub tags](https://hub.docker.com/r/buildkite/puppeteer/tags/) for Puppeteer versions available. -Running: +## Example -```shell -docker-compose -f docker-compose.integration-tests.yml run tests -ls screenshots/ -``` +See the [example directory](example) for a complete Docker Compose example, showing how to run Puppeteer against a linked Docker Compose web service. diff --git a/example/README.md b/example/README.md new file mode 100644 index 0000000..3f1c735 --- /dev/null +++ b/example/README.md @@ -0,0 +1,17 @@ +# Docker Puppeteer Example + +This as an example of using the Docker Puppeteer docker image to run Mocha tests against a linked Docker Compose web service, and capturing a screenshot into a local `./screenshots` directory. + +## Running + +```shell +# Clone this example +git clone https://github.com/buildkite/docker-puppeteer.git +cd docker-puppeteer/example + +# Build and run the example tests +docker-compose -f docker-compose.integration-tests.yml run tests + +# See the screen that was generated +ls screenshots/ +``` -- cgit v1.2.3