我正在尝试运行Angular单元测试。我想配置karma.config文件不打开无头chrome。我只想在终端看到输出。
我尝试在karma.config中注释下面的代码行....
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
跑步测试不应该打开无头铬
您目前没有使用无头镀铬。它已经启动,因为你的设置有[Chrome]
您需要更改browser
数组值。
将
browsers: ['Chrome']
改为browsers: ['ChromeHeadless']
完整的
karma.conf.js
文件,只能使用ChromeHeadless在终端中运行
// 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', 'text-summary'],
fixWebpackSourcePaths: true
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['ChromeHeadless'],
singleRun: false,
customLaunchers:{
HeadlessChrome:{
base: 'ChromeHeadless',
flags: [
'--no-sandbox'
]
}
}
});
};