If you want to run automated tests using Headless Chrome, look no further! This article will get you all set up using Karma as a runner and Mocha+Chai for authoring tests.
**What are these things?**
Karma, Mocha, Chai, Headless Chrome, oh my!
[Karma][2]is a testing harness that works with any of the the most popular testing frameworks ([Jasmine][3],[Mocha][4],[QUnit][5]).
[Chai][6]is an assertion library that works with Node and in the browser. We need the latter.
[Headless Chrome][7]is a way to run the Chrome browser in a headless environment without the full browser UI. One of the benefits of using Headless Chrome (as opposed to testing directly in Node) is that your JavaScript tests will be executed in the same environment as users of your site. Headless Chrome gives you a real browser context without the memory overhead of running a full version of Chrome.
### Setup
### Installation
Install Karma, the relevant, plugins, and the test runners using`yarn`:
When you run your tests (`yarn test`), Headless Chrome should fire up and output the results to the terminal:
![Output from Karma](https://developers.google.com/web/updates/images/2017/06/headless-karma.png)
### Creating your own Headless Chrome launcher
The`ChromeHeadless`launcher is great because it works out of the box for testing on Headless Chrome. It includes the appropriate Chrome flags for you and launches a remote debugging version of Chrome on port`9222`.
However, sometimes you may want to pass custom flags to Chrome or change the remote debugging port the launcher uses. To do that, create a`customLaunchers`field that extends the base`ChromeHeadless`launcher: