在测试步骤中,处理Angular 7应用程序的CircleCI CI / CD管道失败,CircleCI日志表明浏览器未注册,尽管它只运行一次并且可以正常工作!
我正在为Angular 7应用程序构建一个CircleCI CI / CD管道,其中包括 test 步骤,该步骤以一种奇怪的方式失败了。我试图更改karma.config.js参数以使用Puppeteer,但无济于事。
这是WUF开源项目的一部分,我正在研究 WUF-41-CI 分支。详细信息如下:
CircleCI config.yml 文件:
version: 2.0
# Acceptance Criteria
#
# Given a feature branch of WUF
# When it changes on GitHub
# Then its code is built and tested but not published
#
# Given origin/master of WUF
# When it changes on GitHub
# Then its code is built, tested, tagged and the packages pushed to NPM, and the project’s Git pages
jobs:
build:
docker:
- image: wasvic/node_dev:1.0.0-FM-188-SNAPSHOT
entrypoint: /bin/sh
working_directory: ~/wuf
environment:
- DEPLOY_BRANCH: WUF-41-CI
- TARGET_BRANCH: gh-pages
- GH_EMAIL: anvil.open.source.machine.user@gmail.com
- GH_NAME: anvil-open-source-machine-user
- CHROME_BIN: /usr/lib/chromium/chrome
# branches:
# only:
# - master
# - WUF-41-CI
steps:
- run:
name: Install OS tools
# TODO: replace with install_os_pkgs.sh script
command: |
apk update && apk add git
apk add openssh
apk add tar
apk add ca-certificates
apk update && apk upgrade && \
echo @edge http://nl.alpinelinux.org/alpine/edge/community >> /etc/apk/repositories
echo @edge http://nl.alpinelinux.org/alpine/edge/main >> /etc/apk/repositories
apk add --no-cache \
chromium@edge \
nss@edge \
freetype@edge \
harfbuzz@edge \
ttf-freefont@edge
apk add --no-cache ttf-freefont
# chekout projectt
- checkout
- restore_cache:
keys:
# when lock file changes, use increasingly general patterns to restore cache
- yarn-v1-{{ .Branch }}-{{ checksum "yarn.lock" }}
- yarn-v1-{{ .Branch }}-
- node-v1-
- run:
name: Install WUF
command: |
yarn bootstrap
- save_cache:
paths:
- ./node_modules # location depends on npm version
key: yarn-v1-{{ .Branch }}-{{ checksum "yarn.lock" }}
- run:
name: Build WUF
command: |
ng build --aot --base-href /wuf/ --deploy-url /wuf/
- run:
name: Test WUF
command: |
# ng test --browsers CircleCI_ChromeHeadless --watch=false
ng test --browsers CircleCI_ChromeHeadless
# ng test
- run:
name: Deploy WUF
# TODO: replace with a deploy.sh script
command: |
if [ $CIRCLE_BRANCH == $DEPLOY_BRANCH ]; then
git config --global user.email $GH_EMAIL
git config --global user.name $GH_NAME
git clone $CIRCLE_REPOSITORY_URL out
cd out
git checkout $TARGET_BRANCH || git checkout --orphan $TARGET_BRANCH
git rm -rf .
cd ..
cp -a dist/. out/.
mkdir -p out/.circleci && cp -a .circleci/. out/.circleci/.
cd out
git add -A
git commit -m "Automated deployment to GitHub Pages: ${CIRCLE_SHA1}" --allow-empty
git push origin $TARGET_BRANCH
fi
karma.config.js 文件:
/*
* Copyright (c) 2018 Dematic, Corp.
* Licensed under the MIT Open Source: https://opensource.org/licenses/MIT
*/
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, '../coverage'),
reports: ['html', 'lcovonly'],
fixWebpackSourcePaths: true
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: false,
browsers: ['Chrome', 'CircleCI_ChromeHeadless'],
customLaunchers: {
CircleCI_ChromeHeadless: {
base: 'ChromeHeadless',
flags: [
'--headless',
'--disable-gpu',
'--disable-translate',
'--disable-extensions',
'--no-sandbox', // Added to fix an issue where of Failed to connect to chrome browser
'--remote-debugging-port=9222',
],
}
},
singleRun: true
});
};
Circle-CI日志,表明首次启动Chrome浏览器有效:
...
1 05 2019 00:10:47.700:INFO [launcher]: Launching browsers CircleCI_ChromeHeadless with concurrency unlimited
11% building 9/12 modules 3 active .../root/wuf/src/app/app.component.spec.ts 11% building 10/12 modules 2 active ...assets/dummydata/branding/branding.scss11 05 2019 00:10:47.732:INFO [launcher]: Starting browser ChromeHeadless
...
Circle-CI日志,指示通过了第一次执行的测试:
...
HeadlessChrome 73.0.3683 (Linux 0.0.0): Executed 69 of 69 SUCCESS (0 secs / 12.127 secs)
HeadlessChrome 73.0.3683 (Linux 0.0.0): Executed 69 of 69 SUCCESS (12.186 secs / 12.127 secs)
TOTAL: 69 SUCCESS
TOTAL: 69 SUCCESS
...
Circle-CI日志,指示第二次Chrome启动 FAILED :
...
11 05 2019 00:11:29.320:INFO [launcher]: Launching browsers CircleCI_ChromeHeadless with concurrency unlimited
11 05 2019 00:11:29.320:ERROR [launcher]: Cannot load browser "CircleCI_ChromeHeadless": it is not registered! Perhaps you are missing some plugin?
11 05 2019 00:11:29.320:ERROR [karma-server]: Error: Found 1 load error
答案 0 :(得分:0)
这与Chrome 73 stop supporting headless mode in background scheduled task?一样吗
如果是,它应该可以降级到Chrome 72。
答案 1 :(得分:0)
问题的根本原因是Angular单元测试失败;他们的失败被CircleCI输出掩盖了。我通过导出CircleCI日志并仔细阅读发现了这一点。现在,修复在正常的Chrome模式下可以正常工作并且在无头模式下无法正常工作的单元测试错误...这些是测试中的错误,因为我已经找到并修复了一些错误。
答案 2 :(得分:0)
如果您在angular.json上有多个项目,例如主项目和angular lib(也被视为项目),则应发生这种情况。
每个项目都有自己的karma.conf.js
,因此您可能已经更新了主项目的karma.conf.js
,但没有更新Angular lib的。然后在所有项目上运行测试(=>多次启动业障),并且对于角度lib,CircleCI_ChromeHeadless
未注册。