I am trying to run Karma via the Angular CLI headlessly for CI, but I can't get Karma to use my custom launcher.
As per this page on the Angular website I am using a customLauncher
property in my Karma config. But when I try to run my tests with ng test --no-watch --no-progress --browsers=ChromeHeadlessCI
, I get an error that my custom launcher is not registered.
01 01 2021 14:10:10.121:INFO [karma-server]: Karma v5.2.3 server started at http://localhost:9876/
01 01 2021 14:10:10.126:INFO [launcher]: Launching browsers ChromeHeadlessCI with concurrency unlimited
01 01 2021 14:10:10.127:ERROR [launcher]: Cannot load browser "ChromeHeadlessCI": it is not registered! Perhaps you are missing some plugin?
01 01 2021 14:10:10.128:ERROR [karma-server]: Error: Found 1 load error
at Server.<anonymous> (C:UsersrimbDropbox7_Workspacesweather
ode_moduleskarmalibserver.js:213:27)
at Object.onceWrapper (events.js:421:28)
at Server.emit (events.js:327:22)
at Server.EventEmitter.emit (domain.js:467:12)
at emitListeningNT (net.js:1352:10)
at processTicksAndRejections (internal/process/task_queues.js:79:21)
npm ERR! code ELIFECYCLE
Here is my Karma config:
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/weather'),
reports: ['html', 'lcovonly', 'text-summary'],
fixWebpackSourcePaths: true
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome', 'ChromeHeadlessCI'],
browserDisconnectTolerance: 3,
browserDisconnectTimeout: 10000,
browserNoActivityTimeout: 60000,
customLaunchers: {
ChromeHeadlessCI: {
base: 'ChromeHeadless',
flags: [
'--no-sandbox'
]
}
},
singleRun: true,
restartOnFileChange: true
});
};
Here is the command I am running from my package.json via npm:
"test::cci": "ng test --no-watch --no-progress --browsers=ChromeHeadlessCI",
I am not sure where to go from here. It is a bug with Karma? A misconfiguration on my part (the more likely culprit)? I don't know. All this "code" is pretty much boilerplate stuff.