videojs-generate-karma-config
Generate a standard karma config, so that plugins don't need the same script in every repository.
Last updated a year ago by brandonocasey .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install videojs-generate-karma-config 
SYNC missed versions from official npm registry.

videojs-generate-karma-config

Build Status Greenkeeper badge Slack Status

NPM

Currently our karma configs are the same for most plugins, but when the default config changes a bit, every repository has to be updated since it is a static file. This package will provide the standard config as a module, so that updates can be deployed much easier.

Lead Maintainer: Brandon Casey @brandonocasey

Maintenance Status: Stable

Table of Contents

Installation

$ npm install --save-dev karma videojs-generate-karma-config

Then in your karma config do

const generateKarmaConfig = require('videojs-generate-karma-config');

module.exports = function(config) {
  const options = {};

  config = generateKarmaConfig(config, options);
};

Options

By default all options are passed as the second argument to generateKarmaConfig.

files

Type: Function Default: none NOTE: Be very careful with this option, this will effect ci runs as well.

A function that should take one argument, the array of files that are included, and return an array of files that should be included. This is used to manually overide the files that are included ina test run

Default files that will be passed to you function

[
  'node_modules/video.js/dist/video-js.css',
  'dist/*.css',
  'node_modules/sinon/pkg/sinon.js',
  'node_modules/video.js/dist/video.js',
  'test/dist/bundle.js'
]

Example with files function:

module.exports = function(config) {
  const options = {
    files(defaultFiles) {
      return defaultFiles.concat([
        'some-other-file.js'
      ]);
    }
  };

  config = generateKarmaConfig(config, options);
};

browsers

Type: Function Default: none

NOTE: Be very careful with this option, this will effect ci runs as well.

A function that should take one argument, the array of browsers that are about to run, and return an array of browsers that should run. This is used to manually overide the browsers that should run.

Example with detected browsers:

module.exports = function(config) {
  const options = {
    browsers(aboutToRun) {
      // never test on Safari
      return aboutToRun.filter(function(launcherName) {
        return launcherName !== 'Safari';
      });
    }
  };

  config = generateKarmaConfig(config, options);
};

preferHeadless

Type: Boolean Default: true

If we should prefer running headless browsers. This will change the defaults for travisLaunchers and serverBrowsers as well as automatic browser detection. Make sure to handle this in browsers

detectBrowsers

Type: Boolean Default: true

Note: If you set this to false, you will probably want to provide browsers using the browsers option.

If we should detect browsers to run automatically. This will only be done when:

  1. We are not running ci browsers (teamcity, browserstack, or travis)
  2. We are not running in serverMode (--no-single-run passed to karma cli)

serverBrowsers

Type: Function Default: none

A function that should return an array of browsers that should run when in static server mode (--single-run=false). It should take one argument: The default serverBrowsers array which is ['ChromeHeadless'] if preferHeadless is true and ['Chrome'] otherwise.

Example:

module.exports = function(config) {
  const options = {
    serverBrowsers(defaults) {
      serverBrowsers.push('myTestLauncher');

      return serverBrowsers;
    }
  };

  config = generateKarmaConfig(config, options);
};

customLaunchers

Type: Function Default: none

A function that should return an object of karma custom launchers. It should take one argument: The default custom launchers object which is: {};

Example:

module.exports = function(config) {
  const options = {
    customLaunchers(defaults) {
      return Object.assign(defaults, {
        myTestLauncher: {
          base: 'ChromeHeadless'
        }
      };
    }
  };

  config = generateKarmaConfig(config, options);
};

teamcityLaunchers

Type: Function Default: none

NOTE: All browsers contained from this object will be run on teamcity, unless BROWSER_STACK_USERNAME is in the enviornment!

A function that should return an object of karma custom launchers, that should be run on teamcity. It should take one argument: The default custom launchers object which is: {};

Example:

module.exports = function(config) {
  const options = {
    teamcityLaunchers(defaults) {
      // add another browser to teamcity testing
      return Object.assign(defaults, {
        myTestLauncher: {
          base: 'ChromeHeadless'
        }
      };
    }
  };

  config = generateKarmaConfig(config, options);
};

travisLaunchers

Type: Function Default: none

NOTE: All browsers contained from this object will be run on travis, unless BROWSER_STACK_USERNAME is in the enviornment!

A function that should return an object containing karma custom launchers, that should all be run on travis. It should take one argument: The default travis launchers object which is:

Note: the base will change to non-headless browsers if preferHeadless is set to false.

{
  travisFirefox: {
    base: 'FirefoxHeadless'
  },
  travisChrome: {
    base: 'ChromeHeadless',
    flags: ['--no-sandbox']
  }

}

Example:

module.exports = function(config) {
  const options = {
    travisLaunchers(defaults) {
      // add another browser to travis testing
      return Object.assign(defaults, {
        myTestLauncher: {
          base: 'ChromeHeadless'
        }
      };
    }
  };

  config = generateKarmaConfig(config, options);
};

browserstackLaunchers

Type: Function Default: none

NOTE: all browsers contained in this list will be run if there is an enviornment variable called BROWSER_STACK_USERNAME present!

A function that should return an object containing karma custom launchers, that should all be run on browserstack. It should take one argument: The default browserstack launchers object which is:

{
  bsChrome: {
    base: 'BrowserStack',
    browser: 'chrome',
    os: 'Windows',
    os_version: '10'
  },

  bsFirefox: {
    base: 'BrowserStack',
    browser: 'firefox',
    os: 'Windows',
    os_version: '10'
  },

  bsSafariSierra: {
    base: 'BrowserStack',
    browser: 'safari',
    os: 'OS X',
    os_version: 'Sierra'
  },

  bsEdgeWin10: {
    base: 'BrowserStack',
    browser: 'edge',
    os: 'Windows',
    os_version: '10'
  },

  bsIE11Win10: {
    base: 'BrowserStack',
    browser: 'ie',
    browser_version: '11',
    os: 'Windows',
    os_version: '10'
  },

  bsIE11Win7: {
    base: 'BrowserStack',
    browser: 'ie',
    browser_version: '11',
    os: 'Windows',
    os_version: '7'
  }
}
module.exports = function(config) {
  const options = {
    BrowserstackLaunchers(defaults) {
      // only test on Edge windows 10
      return {
        bsEdgeWin10: defaults.bsEdgeWin10;
      };
    }
  };

  config = generateKarmaConfig(config, options);
};

coverage

Type: Function Default: true

If we should report test coverage or not, by default we do.

Example with coverage turned off

module.exports = function(config) {
  const options = {
    coverage: false
  };

  config = generateKarmaConfig(config, options);
};

For more information on browserstack launchers see the docs.

Code Coverage

lcov, json, and html coverage reports will be generated in test/dist/coverage after a test run. Unless coverage is set to false.

codecov.io

  1. install codecov globally in your ci of choice
  2. run codecov -f test/dist/coverage/lcov.info on your ci after testing

View the html report

NOTE: When running as a static server the "serverBrowsers" will have to finish running before you see this. See serverBrowsers

  1. Run your unit tests
  2. open test/dist/coverage/index.html

View the report after testing

  • simply run cat test/dist/coverage/text.txt or if you want a cross platform way use shx. shx cat test/dist/coverage/text.txt

Overriding Configuration Options

Any Karma settings that have not been exposed as an option can be overriden after calling generateKarmaConfig.

Example:

module.exports = function(config) {
  const options = {};

  config = generateKarmaConfig(config, options);

  // The reporters setting is not exposed as an option currently
  config.reporters = ['spec'];
};

Current Tags

  • 7.0.0                                ...           experimental (18 days ago)
  • 5.3.1                                ...           latest (a year ago)

18 Versions

  • 7.0.0                                ...           18 days ago
  • 6.0.0                                ...           2 months ago
  • 5.3.1                                ...           a year ago
  • 5.2.1                                ...           a year ago
  • 5.3.0                                ...           2 years ago
  • 5.2.0                                ...           2 years ago
  • 5.1.0                                ...           2 years ago
  • 5.0.2                                ...           2 years ago
  • 5.0.1                                ...           2 years ago
  • 5.0.0                                ...           2 years ago
  • 4.0.2                                ...           2 years ago
  • 3.1.1-1                                ...           2 years ago
  • 3.1.1-0                                ...           2 years ago
  • 3.1.0                                ...           2 years ago
  • 3.0.0                                ...           2 years ago
  • 2.0.0                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago

Copyright 2014 - 2016 © taobao.org |