test-filter

Filter which tests are executed by integrating issue management systems


Keywords
test, tdd, bdd, jasmine, protractor, karma-plugin, karma-preprocessor, cucumber, jira, github, bitbucket, issues
Install
npm install test-filter@0.0.1

Documentation

test-filter

Filter which tests are executed by integrating issue management systems. Uses javadoc-style annotations to associate tests/specs with issues and their current status and target release/milestone.

The system adds annotations such as @status open and @release 1.2.3 to suite/test/spec annotated with an issue. You can also add these annotations directly to your specs, and the system will update them if you also have an issue annotation on the same spec. Unless you explicitly specify a target release on the command line the system will use the version specified in package.json. These annotations are used to filter out tests that you don't want to be run.

You can also execute only tests that relate to a specific issue by providing the issue=123 argument on the command line.

Currently only Jasmine and Karma are supported. If you're using Cucumber on a java project you might be interested in cucumber-jira and jira-maven-plugin's generate-tests goal.

Usage

npm install --save-dev test-filter

This module uses the "bugs": {"url": "XXX" value in your package.json file to determine how to connect to the issue management system.

Protractor

Note: Requires protractor 1.7.0 or greater.

protractor.conf.js

exports.config = {
  ...
  framework: 'custom',
  frameworkPath: '../../node_modules/test-filter/lib/tools/protractor-jasmine.js',
  ...
  testFilterOptions: {
    // See the Optional Arguments section below
  },
  ...
  onPrepare: function() {
    var JasmineSpecFilter = require('test-filter/lib/tools/jasmine/jasmine-spec-filter'),
        issues = null,
        jasmineSpecFilter = new JasmineSpecFilter(issues, testFilterOptions);

    jasmine.getEnv().specFilter = jasmineSpecFilter.jasmineSpecFilter;
  }
  ...
}

Jasmine

Test Filter can be used as a Jasmine wrapper:

test-filter jasmine

For details on the optional arguments see below.

Add javadoc-style annotations to your spec files:

/**
 * @issue 1
 */
describe('Test suite for Issue 1', function() {
   /**
    * @issue 2
    */
    it('should skip this test if either issue 1 or 2 are open', function() {
    });
});

Karma

Test-filter can also be used as a Karma preprocessor:

test-filter karma [start|run [karma.conf.js] issue=123|release=1.2.3]

For details on the optional arguments see below.

karma.conf.js

module.exports = function(config) {
    config.set({
        frameworks: ['jasmine'],
        ...
        plugins: [
            'karma-jasmine',
            {'preprocessor:test-filter': ['factory', require('test-filter/lib/tools/karma/karma-test-filter-preprocessor')]}
        ],
        preprocessors: {
            '**/*-spec.js': ['test-filter']
        }

Optional Arguments

  • --offline - If you're unable to connect to the issue management system
  • --preserve-specs - By default test-filter will add & update the annotations in your spec files.
  • group=xxx and repo=yyy - Not required for GitHub and BitBucket
  • release=1.2.3 - By default test-filter will use the version in your package.json file, along with the target release/milestone of each issue to determine which tests to run/skip.
  • issue=123 - Run only issues associated with a specific issue.
  • system=jira - is only required if bugs.url is not specified in package.json and the URL does not imply the system used. Valid values: 'github' or 'bitbucket'.

GitHub

  • timeout=60000 - Timeout in ms (defaults to 5 seconds)
  • host=issues.domain.com and pathPrefix=prefix - Only required for GitHub Enterprise

BitBucket

When connecting to BitBucket, you must provide your BitBucket username & password:

on the command line:

test-filter jasmine username=someone password=secret

...or in ~/.netrc:

machine bitbucket.org
  login yourusername
  password yourpassword

JIRA

Not yet implemented