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