From 7cb15ebab7dfb621245a6cef2344f30cdf107036 Mon Sep 17 00:00:00 2001 From: Tim Lucas Date: Wed, 6 Feb 2019 10:55:14 +1100 Subject: Create docker-compose.integration-tests.yml --- example/docker-compose.integration-tests.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 example/docker-compose.integration-tests.yml (limited to 'example') diff --git a/example/docker-compose.integration-tests.yml b/example/docker-compose.integration-tests.yml new file mode 100644 index 0000000..65ed241 --- /dev/null +++ b/example/docker-compose.integration-tests.yml @@ -0,0 +1,16 @@ +version: '3' +services: + tests: + build: + context: . + dockerfile: Dockerfile.integration-tests + volumes: + - "./integration-tests:/integration-tests" + - "./screenshots:/screenshots" + command: mocha --recursive /integration-tests + links: + - app + app: + image: tutum/hello-world + expose: + - "80" -- cgit v1.2.3 From 3a4b164295f12e232ec73ab052f2928c6a8b539c Mon Sep 17 00:00:00 2001 From: Tim Lucas Date: Wed, 6 Feb 2019 10:56:07 +1100 Subject: Add more example files --- example/Dockerfile.integration-tests | 3 +++ example/integration-tests/index.test.js | 41 +++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 example/Dockerfile.integration-tests create mode 100644 example/integration-tests/index.test.js (limited to 'example') diff --git a/example/Dockerfile.integration-tests b/example/Dockerfile.integration-tests new file mode 100644 index 0000000..41de685 --- /dev/null +++ b/example/Dockerfile.integration-tests @@ -0,0 +1,3 @@ +FROM buildkite/puppeteer:latest +RUN npm i mocha +ENV PATH="${PATH}:/node_modules/.bin" \ No newline at end of file diff --git a/example/integration-tests/index.test.js b/example/integration-tests/index.test.js new file mode 100644 index 0000000..dd39d8a --- /dev/null +++ b/example/integration-tests/index.test.js @@ -0,0 +1,41 @@ +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` }) + }) +}) \ No newline at end of file -- cgit v1.2.3 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 --- example/README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 example/README.md (limited to 'example') 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 From 9f994586f630ebc675710563f30fcf1c5bcfcf48 Mon Sep 17 00:00:00 2001 From: Tim Lucas Date: Wed, 6 Feb 2019 11:13:02 +1100 Subject: Update docker-compose.integration-tests.yml --- example/docker-compose.integration-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'example') diff --git a/example/docker-compose.integration-tests.yml b/example/docker-compose.integration-tests.yml index 65ed241..074f4d1 100644 --- a/example/docker-compose.integration-tests.yml +++ b/example/docker-compose.integration-tests.yml @@ -7,7 +7,7 @@ services: volumes: - "./integration-tests:/integration-tests" - "./screenshots:/screenshots" - command: mocha --recursive /integration-tests + command: "wait-for-it.sh app:80 -- mocha --recursive /integration-tests" links: - app app: -- cgit v1.2.3