我正在尝试运行Angular单元测试。我想将karma.config文件配置为不打开无头Chrome。我只是想仅在终端中查看输出。
我通过在 karma.config ....... p
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
运行测试不应打开无头镀铬
答案 0 :(得分:1)
完整的
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'
]
}
}
});
};
答案 1 :(得分:0)
您当前未使用无头铬。由于您的设置具有[Chrome]
您需要更改browser
数组值。
将
browsers: ['Chrome']
更改为browsers: ['ChromeHeadless']