unit testing - AngularJS npm test (Karma) remote server command line -


i working through angularjs tutorial (https://docs.angularjs.org/tutorial/) , have encountered interesting problem when attempting run unit tests using 'npm test'. described @ step 2 of tutorial (https://docs.angularjs.org/tutorial/step_02).

my setup follows:

problem: tutorial discusses unit tests , says execute these 'npm test' command. trigger opening of either chrome or firefx browser , run tests. far good. but: when run 'npm test' command in putty ssh shell, there (obviously) no chrome or ff browser window can opened. hence, error:

vagrant@homestead:~/code/angular-phonecat$ npm test  > angular-phonecat@0.0.0 pretest /home/vagrant/code/angular-phonecat > npm install  npm warn install:nopt@3.0.6 eproto: protocol error, symlink '../nopt/bin/nopt.js' -> '/home/vagrant/code/angular-phonecat/node_modules/.bin/nopt'  > angular-phonecat@0.0.0 postinstall /home/vagrant/code/angular-phonecat > bower install   > angular-phonecat@0.0.0 test /home/vagrant/code/angular-phonecat > node node_modules/karma/bin/karma start test/karma.conf.js  info [karma]: karma v0.12.37 server started @ http://localhost:9876/ info [launcher]: starting browser chrome error [launcher]: no binary chrome browser on platform.   please, set "chrome_bin" env variable. info [launcher]: starting browser firefox error [launcher]: cannot start firefox  info [launcher]: trying start firefox again (1/2). error [launcher]: cannot start firefox  info [launcher]: trying start firefox again (2/2). error [launcher]: cannot start firefox  error [launcher]: firefox failed 2 times (cannot start). giving up. 

note not same types of problems reported in these posts:

setting environment variable chrome_bin not work

how fix error "please set env variable chrome_bin" when running angular.js grunt

these posts (and there may others) assume npm test tool (karma?) used on windows machine, has chrome , ff installed. remotely logging on ubuntu machine, has ff installed , firefox_bin environment variable set correctly (/usr/bin/firefox), cannot open visual windows because looged on through commnd line shell.

so, question is: how can use npm test (or karma) run unit tests using setup described above?

unfortunately don't know how ask question or state problem better this, if need other details me, please let me know.

thanks ahl

instead of running tests on chrome / firefox, run them against phantomjs, headless browsers.

npm install --save-dev phantomjs-prebuilt karma-phantomjs-launcher 

in karma.conf.js:

  • to plugins, add karma-phantomjs-launcher
  • instead of browsers: ['chrome'] set browsers: ['phantomjs']

you have add polyfills phantomjs (which lacking bind function), that, use : https://www.npmjs.com/package/phantomjs-polyfill (it's explained how use karma)


Comments