问题
I am trying to run Angular unit test. I want to configure karma.config file not to open headless chrome. Simply I want to see output in terminal alone.
I tried by commenting below code lines in 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
running test should not open headless chrome
回答1:
You are currently not using headless chrome. It is getting launched since your setting has [Chrome]
You need change the browser
array value.
Change
browsers: ['Chrome']
tobrowsers: ['ChromeHeadless']
回答2:
Full
karma.conf.js
file with the ability to run only in terminal using 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'
]
}
}
});
};
来源:https://stackoverflow.com/questions/55774800/karma-configuration-to-disable-headless-chrome-and-use-only-terminal