aboutsummaryrefslogtreecommitdiffhomepage
path: root/example
diff options
context:
space:
mode:
authorTim Lucas <t@toolmantim.com>2019-02-06 11:31:56 +1100
committerGitHub <noreply@github.com>2019-02-06 11:31:56 +1100
commit4e7c52141ab2170730089e93fb732aa1baba1b2f (patch)
tree4203de845f246013e763db95da3f0ea1fd4f1410 /example
parentf2ea4b9e74b9a8110490ede83d195565f57c004d (diff)
parent9f994586f630ebc675710563f30fcf1c5bcfcf48 (diff)
downloaddocker-puppeteer-4e7c52141ab2170730089e93fb732aa1baba1b2f.tar.gz
docker-puppeteer-4e7c52141ab2170730089e93fb732aa1baba1b2f.tar.zst
docker-puppeteer-4e7c52141ab2170730089e93fb732aa1baba1b2f.zip
Merge pull request #56 from buildkite/add-example
Move example into it's own folder
Diffstat (limited to 'example')
-rw-r--r--example/Dockerfile.integration-tests3
-rw-r--r--example/README.md17
-rw-r--r--example/docker-compose.integration-tests.yml16
-rw-r--r--example/integration-tests/index.test.js41
4 files changed, 77 insertions, 0 deletions
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 @@
1FROM buildkite/puppeteer:latest
2RUN npm i mocha
3ENV PATH="${PATH}:/node_modules/.bin" \ No newline at end of file
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 @@
1# Docker Puppeteer Example
2
3This 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.
4
5## Running
6
7```shell
8# Clone this example
9git clone https://github.com/buildkite/docker-puppeteer.git
10cd docker-puppeteer/example
11
12# Build and run the example tests
13docker-compose -f docker-compose.integration-tests.yml run tests
14
15# See the screen that was generated
16ls screenshots/
17```
diff --git a/example/docker-compose.integration-tests.yml b/example/docker-compose.integration-tests.yml
new file mode 100644
index 0000000..074f4d1
--- /dev/null
+++ b/example/docker-compose.integration-tests.yml
@@ -0,0 +1,16 @@
1version: '3'
2services:
3 tests:
4 build:
5 context: .
6 dockerfile: Dockerfile.integration-tests
7 volumes:
8 - "./integration-tests:/integration-tests"
9 - "./screenshots:/screenshots"
10 command: "wait-for-it.sh app:80 -- mocha --recursive /integration-tests"
11 links:
12 - app
13 app:
14 image: tutum/hello-world
15 expose:
16 - "80"
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 @@
1const assert = require('assert')
2const puppeteer = require('puppeteer')
3
4let browser
5let page
6
7before(async() => {
8 browser = await puppeteer.launch({
9 args: [
10 // Required for Docker version of Puppeteer
11 '--no-sandbox',
12 '--disable-setuid-sandbox',
13 // This will write shared memory files into /tmp instead of /dev/shm,
14 // because Docker’s default for /dev/shm is 64MB
15 '--disable-dev-shm-usage'
16 ]
17 })
18
19 const browserVersion = await browser.version()
20 console.log(`Started ${browserVersion}`)
21})
22
23beforeEach(async() => {
24 page = await browser.newPage()
25})
26
27afterEach(async() => {
28 await page.close()
29})
30
31after(async() => {
32 await browser.close()
33})
34
35describe('App', () => {
36 it('renders', async() => {
37 const response = await page.goto('http://app/')
38 assert(response.ok())
39 await page.screenshot({ path: `/screenshots/app.png` })
40 })
41}) \ No newline at end of file