![Karma 单元测试无法通过 Puppeteer 在 Google Cloud Build 中运行](https://linux22.com/image/739820/Karma%20%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95%E6%97%A0%E6%B3%95%E9%80%9A%E8%BF%87%20Puppeteer%20%E5%9C%A8%20Google%20Cloud%20Build%20%E4%B8%AD%E8%BF%90%E8%A1%8C.png)
我尝试使用 puppeteer 运行 ChromeHeadless 来运行我的单元测试。但是我无法启动 ChromeHeadless 并出现以下错误。
03 07 2019 03:19:25.066:INFO [karma-server]: Karma v4.1.0 server started at http://0.0.0.0:9876/
03 07 2019 03:19:25.071:INFO [launcher]: Launching browsers ChromeHeadless with concurrency unlimited
03 07 2019 03:19:25.080:INFO [launcher]: Starting browser ChromeHeadless
03 07 2019 03:19:25.573:ERROR [launcher]: Cannot start ChromeHeadless
/workspace/node_modules/puppeteer/.local-chromium/linux-672088/chrome-linux/chrome: error while loading shared libraries: libX11-xcb.so.1: cannot open shared object file: No such file or directory
03 07 2019 03:19:25.574:ERROR [launcher]: ChromeHeadless stdout:
03 07 2019 03:19:25.574:ERROR [launcher]: ChromeHeadless stderr: /workspace/node_modules/puppeteer/.local-chromium/linux-672088/chrome-linux/chrome: error while loading shared libraries: libX11-xcb.so.1: cannot open shared object file: No such file or directory
在我的Karma.conf.js中我有::
browsers : ['ChromeHeadlessCustom'],
customLaunchers: {
ChromeHeadlessCustom: {
base: 'ChromeHeadless',
flags: ['--no-sandbox', '--disable-setuid-sandbox']
}
},
云构建.yaml ::
- name: 'gcr.io/cloud-builders/npm:node-10.10.0'
id: 'Install Puppeteer'
args: ['install', 'puppeteer']
- name: 'gcr.io/cloud-builders/npm:node-10.10.0'
id: 'Test'
args: ['run', 'test']
答案1
选定的 docker 容器没有运行 chrome 所需的软件包;您应该更改为更新的容器;
cloud build.yaml 运行 headless-chrome 测试(此外,您还应该将 puppeeter 放在 package.json 中的依赖项中):
- name: 'buildkite/puppeteer'
args: ['npm','install']
- name: 'buildkite/puppeteer'
args: ['npm', 'run', 'test', ]