Testing - AtlasOfLivingAustralia/phylolink GitHub Wiki

Install Karma

  1. Navigate to the root directory of the profile-hub project
  2. Execute the following:
    1. brew install node.js
    2. npm install karma
    3. npm install karma-jasmine karma-chrome-launcher --save-dev
    4. npm install -g karma-cli
    5. npm install karma-coverage
  3. Install other optional browser launchers:
    1. npm install karma-firefox-launcher
    2. npm install karma-safari-launcher
    3. npm install karma-ie-launcher
    4. Update the browsers: ['Chrome'] property in karma.conf.js to add additional browsers to test against.
  4. The source repository contains a karma.conf.js file: this is configures the Karma test runner
  5. (Optional) Install the IntelliJ Karma test runner:
  6. Preferences -> Plugins -> Search for Karma -> Install (at the time of writing there was only 1 matching plugin)
  7. Create a run configuration:
    1. Run -> Edit Configurations -> New -> Karma
    2. Give it a name
    3. Select the karma.conf.js file from the root of the project directory as the Configuration File
    4. The other default values are fine.

Writing Tests

The karma.conf.js file contains a list of all Javascript resources required for testing in the files list. If you create a new file, you must update the karma.conf.js file or your tests won't work.

// list of files / patterns to load in the browser
files: [
    'web-app/js/thirdparty/angular-1.3.13.min.js',
    'web-app/js/thirdparty/angular-mocks-1.3.13.js',
    'web-app/js/thirdparty/ui-bootstrap-tpls-0.12.0.js',
    'web-app/js/angular/profiles.js',
    'web-app/js/angular/utils/*.js',
    'web-app/js/angular/services/*.js',
    'web-app/js/angular/controllers/*.js',
    'test/js/specs/**/*.js'
],

The order is important!

Jasmine tests live in the tests/js/specs/ directory. Update existing files or add new ones as necessary.

Code Coverage

You can see a code coverage report for the javascript files by following these steps:

  1. Command Line
    1. Run karma start
    2. Open coverage/<browser>/index.html
  2. IntelliJ
    1. Run the karma configuration using the Run 'karma' with Coverage option (the 3rd toolbar button after the run dropdown).
    2. Open coverage/<browser>/index.html
    3. IntelliJ will also annotate the filenames in the project explorer with a percentage of lines covered.
⚠️ **GitHub.com Fallback** ⚠️