integrate puppeteer in gitlab with gitlab-ci.yml

こ雲淡風輕ζ 提交于 2020-12-29 05:32:43

问题


Im currently working on e2e test in Chrome Puppeteer. I am at the stage where it would be ideal to integrate my tests in the development process.

What I want to accomplish is the following: my tests run automated before every deploy to production. If they succeed deployment goes through, if they fail deployment is canceled.

I use a pipeline on gitlab to automate my deployment process. So my main question is how can I integrate my puppeteer tests into the gitlab-ci.yml file?


回答1:


This might be a bit of a hack but mine are running like this:

test:
image: node:latest
stage: run
script:
- apt-get update
- apt-get install -yq gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget
- yarn
- yarn test

That super long list of libraries are the ones that the puppeteer needs to launch chrome. Ideally you would have a ready docker image but all the premade ones I found did not work for me.

When getting ready for prod you should build your own image that takes from node and installs the dependencies itself.




回答2:


We had the same problem, you need to run the stage on an docker image that provides puppeteer:

# run performance monitor
performanceMonitoring:
  stage: performanceMonitoring
  image: alekzonder/puppeteer
  script:
    - yarn run performanceMonitoring



回答3:


The easiest way to accomplish this is by using a docker image with Puppeteer preinstalled.

This is what your .gitlab-ci.yml` should look like:

stages:
  - test

cache:
  paths:
    - node_modules/

.node_template:
  image: buildkite/puppeteer

tests:
  extends: .node_template
  stage: test
  variables:
    CI: "true"
  before_script:
    - echo "checking node version"
    - node -v
    - echo "installing dependencies..."
    - npm install
  script:
    - npm run test

I recommend using buildkite/puppeteer over alekzonder/puppeteer, since it comes with the latest LTS version of node and alekzonder/puppeteer doesn't.




回答4:


Try this

variables:
  IMG_BUILD: node:latest
  IMG_TEST: trion/ng-cli-karma
  IMG_TESTING: alekzonder/puppeteer:latest
  IMG_TESTING_FINAL: node:8.9.1
  IMG_GITLAB_CI: juristr/angular-ci-build:1.0.0
  IMG_TESTING_GITLAB: alekzonder/puppeteer:latest
  IMG_TESTING_GITLAB2: buildkite/puppeteer

deploy_test:
  stage: test
  image: ${IMG_TESTING_GITLAB2}
  environment: Production
  cache:
    policy: pull
  artifacts:
    paths:
      - node_modules/
  only:
    - master
  script:
    - npm install
    - npm run test-ci

with package config

"test-ci": "ng test --no-watch --no-progress --browsers=ChromeHeadlessNoSandbox",


来源:https://stackoverflow.com/questions/48638875/integrate-puppeteer-in-gitlab-with-gitlab-ci-yml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!