8

I am trying to do unit tests with AngularJS. I already have bower and grunt installed, so I should be able to do the tests. However, when I run "grunt test" from the terminal (Git Bash in my case), I get the error "Please set env variable CHROME_BIN." According to this StackOverflow question, I should change karma.conf.js and karma-e2e.conf.js, but I can't change them because other people on the project will have issues.

Community
  • 1
  • 1
trysis
  • 8,086
  • 17
  • 51
  • 80

5 Answers5

6

You need to set CHROME_BIN as a new environmental variable. Set the value to the path to chrome.exe. This value is usually: C:/Program Files (x86)/Google/Chrome/Application/chrome.exe

Here are the docs that describe how to configure each type of OS.

Davin Tryon
  • 66,517
  • 15
  • 143
  • 132
  • Yes, but I have several other people on this same project, and I'm on Windows, but others are running other OSes. What could we change it to so all of us can successfully test? Assume only major OSes like Mac & Linux. – trysis Sep 21 '13 at 15:03
  • All of these OSes have a concept of a PATH environmental variable. So, it would fall under how to set up a dev environment for your project. This is the documented (and suggested) way to run karma tests. – Davin Tryon Sep 21 '13 at 16:13
  • Sorry, it is not just enough to add it to the PATH variable. CHROME_BIN needs to be a new environmental variable. But the same holds true. All OSes will support adding a persistent environmental variable. – Davin Tryon Sep 21 '13 at 16:29
  • But will they all support the same variable? Or if not can we assign a different variable for each OS? – trysis Sep 22 '13 at 00:26
  • 1
    Here is the docs. If you follow this, you should be fine: https://github.com/karma-runner/karma/blob/master/docs/config/03-browsers.md#correct-path-to-browser-binary – Davin Tryon Sep 22 '13 at 08:56
  • I couldn't get this to work. Setting CHROME_BIN to `C:\Program Files (x86)\Google\Chrome\Application\Chrome.exe` and the echoing resulted in `C:\Program` is not recognized as an internal or external command, operable program or batch file.' and Grunt still failed. However, setting it on the cmd line worked. But it would be nice to set it once as an environment variable. – Jack Nov 10 '13 at 11:19
  • @Jack, what OS were you doing this on? Windows allows spaces in environment variables, but on other OS's it's more complicated. You may need backslashes or quotes or something else. – trysis Mar 10 '14 at 23:58
2

The browser binary path varies by OS.

Changing the path to the Chrome binary:

$ export CHROME_BIN=/usr/local/bin/my-chrome-build

Changing the path to the Chrome Canary binary:

$ export CHROME_CANARY_BIN=/usr/local/bin/my-chrome-build

Changing the path to the PhantomJs binary:

$ export PHANTOMJS_BIN=$HOME/local/bin/phantomjs
Kobi
  • 135,331
  • 41
  • 252
  • 292
2

Try the below command:

export CHROME_BIN="/mnt/c/Program Files/Google/Chrome/Application/chrome.exe"

Check for location of Google Chrome application in C:\ disk,
The above command is for WSL2 users.

Tyler2P
  • 2,324
  • 26
  • 22
  • 31
1

https://github.com/karma-runner/karma/blob/master/docs/config/03-browsers.md#correct-path-to-browser-binary

For Windows/Chrome, per the cmd box, this would be (by default)

C:\SET CHROME_BIN=C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
beauXjames
  • 8,222
  • 3
  • 49
  • 66
1

Install pupeeter and than it should work for linux and windows

karma.conf.js

module.exports = function (config) {
  process.env.CHROME_BIN = require('puppeteer').executablePath();

  config.set({ ...
Sanid Sa
  • 264
  • 3
  • 9