Our Jenkins test steps just hangs forever even with the correct Karma configurations. Any suggestions or idea would be helpful as I've tried every configuration I can find.
Our npm test command
"test:ci": "ng test --no-watch --no-progress --browsers=ChromeHeadlessNoSandbox",
Our karma.config
Notice we have a singleRun:true
as that seemed to be the important one.
// 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'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
jasmine: {
// you can add configuration options for Jasmine here
// the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
// for example, you can disable the random execution with `random: false`
// or set a specific seed with `seed: 4321`
},
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
jasmineHtmlReporter: {
suppressAll: true // removes the duplicated traces
},
coverageReporter: {
dir: require('path').join(__dirname, './coverage/member-web'),
subdir: '.',
reporters: [
{ type: 'html' },
{ type: 'text-summary' }
]
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
// browsers: ['Chrome'],
browsers: ["ChromeHeadlessNoSandbox"],
customLaunchers: {
ChromeHeadlessNoSandbox: {
base: "ChromeHeadless",
flags: [
'--headless',
'--disable-gpu',
"--no-sandbox",
"--user-data-dir=/tmp/chrome-test-profile",
"--disable-web-security",
"--remote-debugging-address=0.0.0.0",
"--remote-debugging-port=9222",
],
debug: true,
},
},
singleRun: true,
restartOnFileChange: true
});
};
CodePudding user response:
Does the command line not complain about unknown command of --no-watch
?
Change the command to:
"test:ci": "ng test --watch=false --browsers=ChromeHeadlessNoSandbox && echo 'hello'",
--no-progress
does not exist either. Find all flags here: https://angular.io/cli/test.
CodePudding user response:
I figured it out. It was something related to the Docker Container we were using. I tried on another image making sure to include chromium and it fixed it. The dockerfile that worked for me is below.
FROM node:current-alpine3.12
RUN apk add chromium
WORKDIR /usr/src/app
ENV CHROME_BIN=/usr/bin/chromium-browser