GithubHelp home page GithubHelp logo

isabella232 / videojs-generate-karma-config Goto Github PK

View Code? Open in Web Editor NEW

This project forked from videojs/videojs-generate-karma-config

0.0 0.0 0.0 590 KB

Generate a standard karma config, so that plugins don't need the same script in every repository.

License: Other

JavaScript 100.00%

videojs-generate-karma-config's Introduction

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 ciLaunchers as well as automatic browser detection. Make sure to handle this in browsers

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 [].

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);
};

ciLaunchers

Type: Function Default: {}

NOTE: All browsers contained from this object will be run on ci 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 ci. It should take one argument.: The default ci launchers object which empty is:

Example:

module.exports = function(config) {
  const options = {
    ciLaunchers(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'];
};

videojs-generate-karma-config's People

Contributors

brandonocasey avatar gkatsev avatar ldayananda avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.