LoginSignup
6
2

More than 3 years have passed since last update.

CircleCI で puppeteer のテストを実行する

Last updated at Posted at 2019-08-06

はじめに

CircleCI で puppeteer のテストを実行する準備・設定について、検索してもあまり見当たらなかったため、備忘録として投稿させていただきます。

テストスクリプト

CircleCIでPuppeteerを実行する場合は、puppeteer.launchにパラメータを追加する必要があります。

// ローカル環境などでPuppeteerを利用する場合、
// const browser = await puppeteer.launch();

// CircleCIでPuppeteerを利用する場合、
const browser = await puppeteer.launch({ args: ['--no-sandbox', '--disable-setuid-sandbox'] });

// ...(略)

パラメータを追加せずにテストスクリプトを実行した場合、以下のようなエラーが発生します。

====>> run test
  #!/bin/bash -eo pipefail
node xxx.js

(node:67) UnhandledPromiseRejectionWarning: Error: Failed to launch chrome!
[0806/065833.390539:FATAL:zygote_host_impl_linux.cc(116)] No usable sandbox! Update your kernel or see https://chromium.googlesource.com/chromium/src/+/master/docs/linux_suid_sandbox_development.md for more information on developing with the SUID sandbox. If you want to live dangerously and need an immediate workaround, you can try using --no-sandbox.
...

.circleci/config.yml

以下のコンフィグではpuppeteerのインストールテストスクリプトの実行を実行しています。

version: 2
jobs:
  test:
    docker:
      - image: circleci/node:latest-browsers
    steps:
      - checkout
      - run: 
          name: install puppeteer
          command: yarn add puppeteer
      - run: 
          name: run test
          command: node response.js

workflows:
  Puppeteer Test:
    jobs:
    - test
  version: 2

補足

ローカルのCircleCIで実行する場合は以下のコマンドを実行します。

$ circleci local execute --job test

参考:CircleCI のローカル CLI の使用 - CircleCI

参考

本投稿にあたって以下のサイトを参考にさせていただきました。

6
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
2