Can't test my Angular App with Karma and Jasmine

Hello, I am trying to test my Angular application in Project IDX, but I am encountering this error when I run ng test:

amgularapp-3920773:~/amgularapp$ ng test
āœ” Browser application bundle generation complete.
02 06 2024 18:16:39.452:WARN [karma]: No captured browser, open http://localhost:9876/
02 06 2024 18:16:39.502:INFO [karma-server]: Karma v6.4.3 server started at http://localhost:9876/
02 06 2024 18:16:39.507:INFO [launcher]: Launching browsers Chrome with concurrency unlimited
02 06 2024 18:16:39.513:INFO [launcher]: Starting browser Chrome
02 06 2024 18:16:39.514:ERROR [launcher]: No binary for Chrome browser on your platform.
  Please, set "CHROME_BIN" env variable.

This is my karma.conf.js:

module.exports = function(config) {
    config.set({
      basePath: '',
      frameworks: ['jasmine', '@angular-devkit/build-angular'],
      plugins: [
        require('karma-jasmine'),
        require('karma-chrome-launcher'),
        require('karma-jasmine-html-reporter'),
        require('@angular-devkit/build-angular/plugins/karma')
      ],
      client: {
        clearContext: false
      },
      coverageIstanbulReporter: {
        dir: require('path').join(__dirname, './coverage/nombre-proyecto'),
        reports: ['html', 'lcovonly', 'text-summary'],
        fixWebpackSourcePaths: true
      },
      reporters: ['progress', 'kjhtml'],
      port: 9876,
      colors: true,
      logLevel: config.LOG_DEBUG,
      autoWatch: true,
      browsers: ['CustomChromeHeadless'],
      singleRun: false,
      restartOnFileChange: true,
      browserDisconnectTimeout: 10000,
      browserDisconnectTolerance: 3,
      browserNoActivityTimeout: 60000,
      customLaunchers: {
        CustomChromeHeadless: {
          base: 'ChromeHeadless',
          flags: ['--no-sandbox']
        }
      }
    });
  };
2 Likes

Having the same issue

Try installing chromium by adding the following snippet into dev.nix

packages = [
    # What you already have
    pkg.chromium
  ];
env = {
    # What you already have
    CHROME_BIN="/usr/bin/chromium";
  };
1 Like
> angular-app@0.0.0 test
> ng test --no-watch --code-coverage

āœ” Browser application bundle generation complete.
30 01 2025 03:56:40.608:INFO [karma-server]: Karma v6.4.4 server started at http://localhost:9876/
30 01 2025 03:56:40.620:INFO [launcher]: Launching browsers Chrome with concurrency unlimited
30 01 2025 03:56:40.628:INFO [launcher]: Starting browser Chrome
30 01 2025 03:56:42.092:ERROR [launcher]: Cannot start Chrome
        [5912:5960:0130/035642.081972:ERROR:bus.cc(407)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
[5912:5912:0130/035642.082476:ERROR:ozone_platform_x11.cc(244)] Missing X server or $DISPLAY
[5912:5912:0130/035642.082493:ERROR:env.cc(257)] The platform failed to initialize.  Exiting.

30 01 2025 03:56:42.092:ERROR [launcher]: Chrome stdout: 
30 01 2025 03:56:42.092:ERROR [launcher]: Chrome stderr: [5912:5960:0130/035642.081972:ERROR:bus.cc(407)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
[5912:5912:0130/035642.082476:ERROR:ozone_platform_x11.cc(244)] Missing X server or $DISPLAY
[5912:5912:0130/035642.082493:ERROR:env.cc(257)] The platform failed to initialize.  Exiting.

30 01 2025 03:56:42.098:INFO [launcher]: Trying to start Chrome again (1/2).
30 01 2025 03:56:42.257:ERROR [launcher]: Cannot start Chrome
        [5965:5988:0130/035642.250554:ERROR:bus.cc(407)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
[5965:5965:0130/035642.252362:ERROR:ozone_platform_x11.cc(244)] Missing X server or $DISPLAY
[5965:5965:0130/035642.252384:ERROR:env.cc(257)] The platform failed to initialize.  Exiting.

30 01 2025 03:56:42.257:ERROR [launcher]: Chrome stdout: 
30 01 2025 03:56:42.258:ERROR [launcher]: Chrome stderr: [5965:5988:0130/035642.250554:ERROR:bus.cc(407)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
[5965:5965:0130/035642.252362:ERROR:ozone_platform_x11.cc(244)] Missing X server or $DISPLAY
[5965:5965:0130/035642.252384:ERROR:env.cc(257)] The platform failed to initialize.  Exiting.

30 01 2025 03:56:42.262:INFO [launcher]: Trying to start Chrome again (2/2).
30 01 2025 03:56:42.417:ERROR [launcher]: Cannot start Chrome
        [5995:6019:0130/035642.408742:ERROR:bus.cc(407)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
[5995:5995:0130/035642.411078:ERROR:ozone_platform_x11.cc(244)] Missing X server or $DISPLAY
[5995:5995:0130/035642.411101:ERROR:env.cc(257)] The platform failed to initialize.  Exiting.

30 01 2025 03:56:42.418:ERROR [launcher]: Chrome stdout: 
30 01 2025 03:56:42.419:ERROR [launcher]: Chrome stderr: [5995:6019:0130/035642.408742:ERROR:bus.cc(407)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
[5995:5995:0130/035642.411078:ERROR:ozone_platform_x11.cc(244)] Missing X server or $DISPLAY
[5995:5995:0130/035642.411101:ERROR:env.cc(257)] The platform failed to initialize.  Exiting.

30 01 2025 03:56:42.423:ERROR [launcher]: Chrome failed 2 times (cannot start). Giving up.