我有一个角度为 15 的项目,我用 jasmine 和 karma 运行我的测试:
"devDependencies": {
"@angular-devkit/build-angular": "^15.0.0",
"@angular/cli": "~15.0.0",
"@angular/compiler-cli": "^15.0.0",
"@types/jasmine": "~4.0.0",
"autoprefixer": "^10.4.13",
"jasmine-core": "~4.3.0",
"karma": "~6.4.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.2.0",
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "~2.0.0",
"postcss": "^8.4.21",
"tailwindcss": "^3.2.4",
"typescript": "~4.8.4"
}
我有默认的业力配置来使用 Chrome 在本地运行测试,它运行良好。
我需要另一个配置来在我的 CI/CD 管道上运行测试,这就是我的问题的开始:
browsers: ['Chrome', 'ChromeHeadlessNoSandbox'],
customLaunchers: {
ChromeHeadlessNoSandbox: {
base: 'ChromeHeadless',
flags: ['--no-sandbox'],
browserNoActivityTimeout: 10000,
browserDisconnectTimeout: 10000
}
},
我的管道在带有公共 gitlab 运行器的 docker 容器上运行:
test:
stage: test
image: node:18-alpine
dependencies:
- install_dependencies
artifacts:
paths:
- coverage/
expire_in: 1 hour
script:
- apk add chromium
- export CHROME_BIN=/usr/bin/chromium-browser
- node_modules/.bin/ng test --code-coverage --browsers=ChromeHeadlessNoSandbox --watch=false
有时,但不总是,我有以下错误:
Chrome Headless 110.0.5481.177 (Linux x86_64): Executed 461 of 694 SUCCESS (0 secs / 1 min 0.636 secs)
Chrome Headless 110.0.5481.177 (Linux x86_64): Executed 462 of 694 SUCCESS (0 secs / 1 min 0.642 secs)
Chrome Headless 110.0.5481.177 (Linux x86_64): Executed 463 of 694 SUCCESS (0 secs / 1 min 1.067 secs)
Chrome Headless 110.0.5481.177 (Linux x86_64): Executed 464 of 694 SUCCESS (0 secs / 1 min 1.068 secs)
02 03 2023 18:05:23.730:WARN [Chrome Headless 110.0.5481.177 (Linux x86_64)]: Disconnected (0 times) reconnect failed before timeout of 2000ms (ping timeout)
Chrome Headless 110.0.5481.177 (Linux x86_64) ERROR
Disconnected reconnect failed before timeout of 2000ms (ping timeout)
Chrome Headless 110.0.5481.177 (Linux x86_64): Executed 464 of 694 DISCONNECTED (2 mins 26.054 secs / 1 min 1.068 secs)
Chrome Headless 110.0.5481.177 (Linux x86_64) ERROR
Disconnected reconnect failed before timeout of 2000ms (ping timeout)
Chrome Headless 110.0.5481.177 (Linux x86_64): Executed 464 of 694 DISCONNECTED (2 mins 26.054 secs / 1 min 1.068 secs)
✔ Browser application bundle generation complete.
=============================== Coverage summary ===============================
Statements : Unknown% ( 0/0 )
Branches : Unknown% ( 0/0 )
Functions : Unknown% ( 0/0 )
Lines : Unknown% ( 0/0 )
================================================================================
✔ Browser application bundle generation complete.
Cleaning up project directory and file based variables
00:04
ERROR: Job failed: exit code 1
错误永远不会在本地发生,我目前唯一的解决方案是重试该作业。你知道为什么吗?