I have an Angular 18 application. There are around 180 unit tests of which 4 passes and rest of them are skipped. Unit tests works fine locally but it fails on pipeline.
**Command -** "test-headless": "ng test --watch=false --browsers=ChromeHeadlessCI"
Error from pipeline is as follows:
06 02 2025 03:08:38.547:DEBUG [reporter]: Couldn't load color-version.
06 02 2025 03:08:38.554:DEBUG [reporter]: Trying to load reporter: kjhtml
06 02 2025 03:08:38.555:DEBUG [reporter]: Trying to load color-version of reporter: kjhtml (kjhtml_color)
06 02 2025 03:08:38.555:DEBUG [reporter]: Couldn't load color-version.
06 02 2025 03:08:38.605:INFO [karma-server]: Karma v6.4.4 server started at http://localhost:9876/
06 02 2025 03:08:38.606:INFO [launcher]: Launching browsers ChromeHeadlessCI with concurrency unlimited
06 02 2025 03:08:38.606:ERROR [karma-server]: Error: Found 1 load error
at Server.<anonymous> (/home/vsts/work/1/s/node_modules/karma/lib/server.js:243:26)
at Object.onceWrapper (node:events:631:28)
at Server.emit (node:events:529:35)
at emitListeningNT (node:net:1851:10)
at process.processTicksAndRejections (node:internal/process/task_queues:81:21)
06 02 2025 03:08:38.608:DEBUG [launcher]: Disconnecting all browsers
06 02 2025 03:08:38.620:DEBUG [proxy]: Destroying proxy agents
06 02 2025 03:08:38.651:DEBUG [launcher]: Finished all browsers
06 02 2025 03:08:45.569:DEBUG [karma-server]: Received stop event, exiting.
06 02 2025 03:08:45.569:DEBUG [launcher]: Disconnecting all browsers
06 02 2025 03:08:45.569:DEBUG [proxy]: Destroying proxy agents
##[warning]Couldn't find a debug log in the cache or working directory
##[error]Error: Npm failed with return code: 1
Finishing: Test
Initially I had code coverage also to be generated, removed that due to the same issues and tried to just run the test to see if it passes. In local it works fine without issues and 4 tests are shown as passed.
Below is the yml file part where Test is added:
- task: Npm@1
displayName: Test
inputs:
command: custom
workingDir: ''
verbose: false
customCommand: 'run test-headless'
continueOnError: false
Here is the karma.conf.js file:
// Karma configuration file, see link for more information
// .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'),
require('karma-junit-reporter')
],
client: {
jasmine: {
// you can add configuration options for Jasmine here
// the possible options are listed at .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/admin'),
subdir: '.',
reporters: [
{ type: 'html' },
{ type: 'text-summary' },
{ type: 'cobertura' },
{ type: 'lcov' }
]
},
logLevel: config.LOG_DEBUG,
reporters: ['progress', 'kjhtml'],
browsers: ['ChromeHeadless'],
customLaunchers: {
ChromeHeadlessCI: {
base: 'ChromeHeadless',
flags: ['--no-sandbox', '--disable-gpu']
}
},
restartOnFileChange: true
});
};