node.js - Angular 单元测试卡在 GitHub Action CI 上
问题描述
我正在尝试使用 GitHub Actions 在默认 Angular 项目上设置 CI 管道。我可以在本地成功运行单元测试,但遇到 GitHub Actions 的问题。我需要更改什么才能使其成功运行?
name: Node.js CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x, 12.x, 14.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run build --if-present
- run: npm test
这是此步骤的日志输出
> ng test
Compiling @angular/core/testing : es2015 as esm2015
Compiling @angular/platform-browser/testing : es2015 as esm2015
Compiling @angular/compiler/testing : es2015 as esm2015
Compiling @angular/platform-browser-dynamic/testing : es2015 as esm2015
Compiling @angular/common/testing : es2015 as esm2015
Compiling @angular/router/testing : es2015 as esm2015
- Generating browser application bundles...
17 12 2020 20:14:02.566:WARN [karma]: No captured browser, open http://localhost:9876/
17 12 2020 20:14:02.708:INFO [karma-server]: Karma v5.1.1 server started at http://localhost:9876/
17 12 2020 20:14:02.709:INFO [launcher]: Launching browsers Chrome with concurrency unlimited
17 12 2020 20:14:02.713:INFO [launcher]: Starting browser Chrome
✔ Browser application bundle generation complete.
- Generating browser application bundles...
✔ Browser application bundle generation complete.
17 12 2020 20:14:07.847:WARN [karma]: No captured browser, open http://localhost:9876/
17 12 2020 20:14:08.707:ERROR [launcher]: Cannot start Chrome
[2646:2646:1217/201408.612463:ERROR:browser_main_loop.cc(1434)] Unable to open X display.
17 12 2020 20:14:08.707:ERROR [launcher]: Chrome stdout:
17 12 2020 20:14:08.707:ERROR [launcher]: Chrome stderr: [2646:2646:1217/201408.612463:ERROR:browser_main_loop.cc(1434)] Unable to open X display.
17 12 2020 20:14:08.712:INFO [launcher]: Trying to start Chrome again (1/2).
17 12 2020 20:14:08.860:ERROR [launcher]: Cannot start Chrome
[2682:2682:1217/201408.854964:ERROR:browser_main_loop.cc(1434)] Unable to open X display.
17 12 2020 20:14:08.861:ERROR [launcher]: Chrome stdout:
17 12 2020 20:14:08.861:ERROR [launcher]: Chrome stderr: [2682:2682:1217/201408.854964:ERROR:browser_main_loop.cc(1434)] Unable to open X display.
17 12 2020 20:14:08.863:INFO [launcher]: Trying to start Chrome again (2/2).
17 12 2020 20:14:09.006:ERROR [launcher]: Cannot start Chrome
[2711:2711:1217/201409.000191:ERROR:browser_main_loop.cc(1434)] Unable to open X display.
17 12 2020 20:14:09.006:ERROR [launcher]: Chrome stdout:
17 12 2020 20:14:09.007:ERROR [launcher]: Chrome stderr: [2711:2711:1217/201409.000191:ERROR:browser_main_loop.cc(1434)] Unable to open X display.
17 12 2020 20:14:09.008:ERROR [launcher]: Chrome failed 2 times (cannot start). Giving up.
解决方案
你需要安装 puppeteer 等等一些额外的配置
npm install puppeteer --save-dev
在 karma.conf.js 下restartOnFileChange: true,
添加
customLaunchers: {
ChromeHeadlessCustom: {
base: 'ChromeHeadless',
flags: ['--no-sandbox', '--disable-gpu']
}
}
在 package.json 中更新测试脚本为
"test": "ng test --watch=false --browsers=ChromeHeadlessCustom",
推荐阅读
- angular - 如何使 NativeScript Angular 中的 GridLayout 适合(肖像/风景)
- c# - 升级到 Android 9 后无法从 Xamarin.Forms 应用打开 ESP32 套接字
- sql - 为表中的每一行返回两行
- tensorflow - 如何在急切执行模式下冻结 tf.keras 框架内的张量流变量?
- r - 如果数据表列选择器也处于活动状态,如何选择行
- c# - 如何在不隐藏表单 C# 的情况下截取屏幕截图
- assembly - 如何声明数据向量
- python-3.x - 如何触发 dag 立即运行
- java - 如何在 Spring-WS 2.4.4 或更高版本中更改 maxOccurs 的默认限制?
- python - GroupBy 操作使用整个数据框对值进行分组