Troubleshooting Angular 5 Unit Tests with Headless Chrome on Ubuntu Server

Hey everyone,

I’m having a bit of trouble with my Angular 5 unit tests. They’re running fine on my local machine, but I’m hitting a snag when I try to run them on our Ubuntu server.

I’m using Karma and Jasmine for testing, and we’re running them with Headless Chrome for our server deployment. The weird thing is, it works perfectly when I use Firefox Headless instead.

Here’s what I’m seeing in the logs:

05 03 2018 07:43:02.132:INFO [HeadlessChrome 64.0.3282 (Ubuntu 0.0.0)]: Connected on socket 9NdPfrccf8iYNlPrAAAA with id 56814881
05 03 2018 07:45:21.364:WARN [HeadlessChrome 64.0.3282 (Ubuntu 0.0.0)]: Disconnected (1 times)
HeadlessChrome 64.0.3282 (Ubuntu 0.0.0) ERROR
  Disconnectedundefined

It looks like Headless Chrome is connecting at first, but then disconnecting after a couple of minutes. Any ideas what might be causing this or how I can fix it? I’m pretty stumped at this point.

Thanks in advance for any help you can offer!

I’ve dealt with this exact issue before, and it can be super frustrating. One thing that worked for me was tweaking the Chrome flags in my Karma config. Try adding ‘–disable-translate’ and ‘–disable-extensions’ to your Chrome options. These can sometimes conflict with Angular tests in headless mode.

Also, make sure your server has enough swap space allocated. I once spent days debugging a similar problem only to realize our server was running out of memory during test execution. Increasing the swap fixed it right up.

Lastly, double-check that all your Angular dependencies are at compatible versions. Mismatched versions can cause weird timeout issues that only show up in CI environments. Hope this helps you get those tests running smoothly!

I’ve encountered a similar issue when running Angular tests with Headless Chrome on Ubuntu servers. One thing that helped in my case was increasing the browser’s timeout and using no-sandbox settings. Try modifying your Karma configuration to include these options:

browsers: ['ChromeHeadlessNoSandbox'],
customLaunchers: {
  ChromeHeadlessNoSandbox: {
    base: 'ChromeHeadless',
    flags: ['--no-sandbox', '--disable-gpu', '--disable-dev-shm-usage']
  }
},
browserNoActivityTimeout: 60000

This configuration bypasses some security features that can cause issues in server environments and increases the timeout period. If that doesn’t work, ensure that all necessary dependencies for Headless Chrome are installed on your Ubuntu server, as missing libraries can lead to unexpected disconnections.

hey, i had similar problems. try increasing system resources for the headless chrome. sometimes it crashes due to memory limits. also, check if you have the latest chrome version installed on the server. older versions can be buggy with angular tests. good luck!