Details
-
Task
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
1.6.0
-
None
Description
Add Karma as additional tool for running FE tests. Karma provides great functionality and powered with a lot of useful plugins. It can improve testing experience and prevent bugs appearing before pushing your changes to git repository.
Setup
First of all there are no changes to testing with mocha-phantomjs and additional packages doesn't break any compatibility with dev and build tools.
You need node.js >= 0.10. I recommend to install node.js by nvm(Unix only).
Install required packages. Run after patch applying:
$ npm install
Now you have installed Karma in node_modules/ folder. If you want to install Karma globally run:
$ npm i -g karma@0.11.14
Run karma from project_root/ambari-web/ folder:
# for locally installed Karma $ node_modules/karma/bin/karma start # for globally installed Karma $ karma start
This command will run karma server on http://localhost:9876 and repeat tests while files changing.
PhantomJS is default browser for running, but you can open http://localhost:9876 in any browser which will run tests also.
To generate coverage summary edit project_root/ambari-web/karma.conf.js:
... preprocessors: { '!(vendor|node_modules|test)/**/!(karma_setup|tests).js': 'coverage', // uncomment this line 'app/templates/**/*.hbs': ['ember-precompiler-brunch', 'common-require'], 'app!(assets)/**/!(karma_setup|tests).js': ['common-require'], 'test/**/*.js': ['common-require'] }, .... reporters: ['progress','coverage']
Look to project_root/ambari-web/public/coverage/. You can setup custom path in #coverageReporter config property.
If you have problems with PhantomJS disconnecting, install it from download page and set shell variable PHANTOMJS_BIN with path to executable file (by default is /usr/bin/phantomjs). You can add this variable to your shell profile file, or make it session only by:
$ export PHANTOMJS_BIN=/usr/bin/phantomjs
Windows Setup
Tested with node.js v 0.10.20
You need to install, if not installed:
Karma plugin for Intellij Platform IDE
Install plugin from File -> Settings -> IDE Settings -> Plugins.
After IDE restart go to Run -> Edit Configuration.
Add configuration: press plus button, select Karma. Now fill inputs with path to: Node.js interpreter, Karma node package and Configuration file it should be project_root/ambari-web/karma.conf.js.
After setup you can run karma from Debug panel picture-1 and you will see progress in 4: Run tab picture-2. You can set Auto-test by pressing Toggle auto-test button.