Skip to content

Commit

Permalink
ci: make it able to run puppeteer on CI
Browse files Browse the repository at this point in the history
puppeteer/puppeteer#1793 (comment)

This change is fix for this error:

```
npm test

> nuxt-jest-puppeteer@1.0.0 test /nuxt-jest-puppeteer
> jest

Error: Failed to launch chrome! spawn /nuxt-jest-puppeteer/node_modules/puppeteer/.local-chromium/linux-650583/chrome-linux/chrome ENOENT

TROUBLESHOOTING: https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md

    at onClose (/nuxt-jest-puppeteer/node_modules/puppeteer/lib/Launcher.js:342:14)
    at ChildProcess.helper.addEventListener.error (/nuxt-jest-puppeteer/node_modules/puppeteer/lib/Launcher.js:333:64)
    at ChildProcess.emit (events.js:189:13)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:246:12)
    at onErrorNT (internal/child_process.js:415:16)
    at process._tickCallback (internal/process/next_tick.js:63:19)
npm ERR! Test failed.  See above for more details.
Exited with code 1
```
  • Loading branch information
tanakaworld committed May 3, 2019
1 parent 5efd0f1 commit d17c1ff
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 13 deletions.
80 changes: 68 additions & 12 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ executors:
description: a image for docker container
docker:
- image: <<parameters.image>>
environment:
CHROME_BIN: /usr/bin/chromium-browser
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: true
working_directory: /nuxt-jest-puppeteer

commands:
Expand All @@ -19,26 +22,79 @@ commands:
# https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md#running-on-alpine
name: Install dependencies
command: |
apk update && apk upgrade && \
echo @edge http://nl.alpinelinux.org/alpine/edge/community >> /etc/apk/repositories && \
echo @edge http://nl.alpinelinux.org/alpine/edge/main >> /etc/apk/repositories && \
apk add --no-cache \
chromium@edge \
nss@edge \
freetype@edge \
harfbuzz@edge \
ttf-freefont@edge
apk update \
&& apk upgrade \
&& apk add --no-cache \
udev \
ttf-freefont \
chromium \
&& npm install puppeteer@1.15.0
jobs:
build:
executor:
name: default
executor: default
steps:
- install_dependencies
- checkout
- restore_cache:
keys:
- npm-cache-{{ arch }}-{{ .Branch }}-{{ checksum "package-lock.json" }}
- npm-cache-{{ arch }}-{{ .Branch }}
- npm-cache
- run:
name: install npm dependencies
command: npm ci
- run:
name: build
command: npm run build
- save_cache:
key:
npm-cache-{{ arch }}-{{ .Branch }}-{{ checksum "package-lock.json" }}
paths:
- ~/.npm
- persist_to_workspace:
root: /nuxt-jest-puppeteer
paths:
- ./node_modules
- .nuxt

lint:
executor: default
steps:
- install_dependencies
- checkout
- restore_cache:
keys:
- npm-cache-{{ arch }}-{{ .Branch }}-{{ checksum "package-lock.json" }}
- npm-cache-{{ arch }}-{{ .Branch }}
- npm-cache
- run:
name: npm version
command: npm -v
- run:
name: Install npm dependencies
command: npm ci
- run:
name: run test
name: eslint
command: npm run lint

test:
executor: default
steps:
- install_dependencies
- checkout
- attach_workspace:
at: /nuxt-jest-puppeteer
- run:
name: test
command: npm test

workflows:
build_and_test:
jobs:
- build
- lint
- test:
requires:
- build
- lint
11 changes: 10 additions & 1 deletion test/setup/global-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@ const puppeteer = require('puppeteer')
// overwrite default setup
// https://github.com/smooth-code/jest-puppeteer/blob/db731a3a4382f3e27c4e16d9f8cf2560ee5adaff/packages/jest-environment-puppeteer/src/global.js
module.exports = async function globalSetup() {
global.browser = await puppeteer.launch()
global.browser = await puppeteer.launch({
headless: true,
executablePath: process.env.CHROME_BIN || null,
args: [
'--no-sandbox',
'--headless',
'--disable-gpu',
'--disable-dev-shm-usage'
]
})
process.env.PUPPETEER_WS_ENDPOINT = global.browser.wsEndpoint()

await setupDevServer({
Expand Down

0 comments on commit d17c1ff

Please sign in to comment.