创建我的CI管道时。我添加了一些测试,它们在本地工作得很好。但是,当在Gitlab运行程序中运行它们时,由于某种未知的原因,我似乎无法启动Chrome。这是我的gitlab ci YML文件,因此您可以看到我用于Angular测试的图像:
cache:
paths:
- /usr/local/lib/node
- node_modules
stages:
- compile
- test
build:
stage: compile
image: node:12-stretch
tags:
- dev
script:
- 'npm set registry $repository'
- 'npm ci'
- 'npm install -g @angular/cli'
- 'ng build'
artifacts:
paths:
- dist/
test:
stage: test
image: jramcast/karma-chrome-xvfb
tags:
- dev
script:
- 'npm set registry $repository'
- 'npm install -g @angular/cli'
- 'ng test'
我需要使用--no-sandbox参数启动chrome,否则会给我一个错误。所以这是Angular项目中的Karma配置:
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/suitless'),
reports: ['html', 'lcovonly', 'text-summary'],
fixWebpackSourcePaths: true
},
customLaunchers: {
ChromeDocker: {
base: 'Chrome',
flags: ['--headless', '--no-sandbox', '--disable-gpu']
},
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['ChromeDocker'],
singleRun: true,
restartOnFileChange: true
});
};
最后一件事情是偏离路线运行单元测试时出现的错误:
我认为这与chrome参数或Linux不支持的字体样式有关。因为gitlab管道在Linux docker环境上运行。帮助将不胜感激。