Configuring a headless browser for Angular

The protractor testing tool officially supports running against Chrome in headless mode. In order to execute Angular tests in a continuous integration environment, you will need to configure your test runner, Karma, to run with a headless Chrome instance:

  1. Update karma.conf.js to include a new headless browser option:
src/karma.conf.js...browsers: ['Chrome', 'ChromiumHeadless', 'ChromiumNoSandbox'],customLaunchers: {  ChromiumHeadless: {        base: 'Chrome',        flags: [          '--headless',          '--disable-gpu',          // Without a remote debugging port, Google Chrome exits immediately.          '--remote-debugging-port=9222',        ],        debug: true,      },      ChromiumNoSandbox: {        base: 'ChromiumHeadless', flags: ['--no-sandbox', '--disable-translate', ...

Get Angular 6 for Enterprise-Ready Web Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.