You can avoid this under unix based system using the Headless chrome
It's a way to run the Chrome browser in a headless environment. Essentially, running Chrome without chrome! It brings all modern web platform features provided by Chromium and the Blink rendering engine to the command line.
first:
configure your karma.conf.js
to use headless chrome e.g adding a customLaunchers
:
...
browsers: ['Chrome'],
customLaunchers: {
ChromeNoSandboxHeadless: {
base: 'ChromeHeadless',
flags: ['--no-sandbox']
}
},
second:
tell your package.json
script to use your config for testing:
"scripts": {
...
"test": "ng test --browsers=ChromeNoSandboxHeadless",
...
},
then run npm run test
or yarn test
and your tests will works without open your browser. You can open the displayed url
in your prefered browsers(firefox, chrome, chromium etc...).
second way:
You can display all your test cases in your console using Karma-mocha-reporter
- First : install
npm install karma-mocha-reporter --save-dev
- Second: require your reporter inside
karma.conf.js
under plugins
like require('karma-mocha-reporter'),
Then add the new reporter mocha
to your reporters array: reporters: ['mocha', 'progress', 'kjhtml']
Run your test using npm run test
or yarn test
will display the report into your console.
another way:
in your karma.config.json
take a look at the option singleRun
(a boolean default set to false
). Set true
, Karma will start and capture all configured browsers, run tests and then exit with an exit code of 0 or 1 depending on whether all tests passed or any tests failed. Alternativ, run it using the flag npm run test --single-run
.