Karma Test With angular 6
Asked Answered
S

2

6

I am tring to run test of angular using npm

ng test

but the problem is that chrome start and not stop after test finish so I used :

ng test --watch=false

but that cause error "Chrome 69.0.3497 (Linux 0.0.0) ERROR" which make chrome timeout I am trying to run that on continuous deployment server so this error cause fail in the process any idea how to stop that

Stomodaeum answered 8/10, 2018 at 10:31 Comment(0)
Q
6

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.

Quizmaster answered 8/10, 2018 at 11:1 Comment(0)
A
2

In your karma.conf.js, change singleRun to true.

singleRun: true
Allegory answered 8/10, 2018 at 10:32 Comment(2)
I don't have that fileStomodaeum
Did you check the same folder as your package.json?Allegory

© 2022 - 2024 — McMap. All rights reserved.