Git Product home page Git Product logo

karma-sharding's Introduction

karma-sharding

npm version NSP Status npm downloads Build Status js-standard-style Maintainability dependencies Status devDependencies Status optionalDependencies Status

Karma plugin to allow tests to be distributed across multiple browsers

Notes

This is intended to avoid the memory usage problems seen with some browsers and numerous or memory intensive specs. Lower your concurrency setting if total memory is a problem running in parallel processes.

You can pass configuration to override these defaults:

{
  sharding: {
    specMatcher: /(spec|test)s?\.js/i,
    base: '/base',
    getSets: function(config, basePath, files) {
        // splitForBrowsers - some util function
        return splitForBrowsers(files.served)
            .map(oneBrowserSet => [someInitScript].concat(oneBrowserSet));
    }
  }
}

getSets might be overridden when files from karma.files config should be organized in certain view, for example:

karma.files has set - [setup.js, one.unit.js, two.unit.js] - and it must be combined for each browser as [setup.js, one.unit.js] and [setup.js, two.unit.js]

Installation

The easiest way is to install karma-sharding as a devDependency, by running

npm install karma karma-sharding --save-dev

Examples

Basic

// karma.conf.js
module.exports = function(config) {
  config.set({
    files: [
      'src/**/*.js',
      'test/**/*.js'
    ],

    frameworks: ['sharding'], // this will load the framework and beforeMiddleware

    preprocessors: {
      // source files, that you wanna generate coverage for
      // do not include tests or libraries
      // (these files will be instrumented by Istanbul)
      'src/**/*.js': ['coverage'] // coverage is loaded from karma-coverage by karma-sharding
    },

    // sharding replaces the coverage reporter inline to allow the preprocessor to run
    // preprocessor:coverage looks for reporter:coverage otherwise it would use a unique name
    reporters: ['progress', 'coverage'],

    browsers: ['ChromeHeadless', 'ChromeHeadless'] // this will split the tests into two sets
  });
};

For more information on Karma see the homepage.

karma-sharding's People

Contributors

rschuft avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

karma-sharding's Issues

only() doesn't work like it does when you don't use sharding, and not documented in the readme

Note: for support questions, please use stackoverflow. This repository's issues are reserved for feature requests and bug reports.

  • **I'm submitting a .. **

    • [ X ] bug report
    • feature request
    • support request => Please do not submit support request here, see note at the top of this template.
  • Do you want to request a feature or report a bug?
    Bug:
    only() doesn't work like it does when you don't use sharding, and not documented in the readme

  • What is the current behavior?
    readme says nothing about only() or how to get around it.

  • If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via
    https://plnkr.co or similar (you can use this template as a starting point: http://plnkr.co/edit/tpl:AvJOMERrnz94ekVua0u5).

plnkr probably not needed, as this is a simple use case.

  • Create 2 test files with 1 it() in each
  • put only() on the it() in one of the files
  • run your tests with 2 browsers

When the above is done, both tests run, one in each browser.

  • What is the expected behavior?
    It should run the only() test in 1 browser and nothing in the other browser.
    Otherwise, the docs should at least warn about this issue, and maybe suggest workarounds.

  • What is the motivation / use case for changing the behavior?
    Consistency of use and/or completeness of documentation.

  • Please tell us about your environment:

  • version: "karma-sharding": "^4.4.0",
  • Browser: [ChromeHeadless]
  • Language: [all]
  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, gitter, etc)
    Relevant dependencies:
    "istanbul": "0.4.5",
    "karma": "2.0.0",
    "karma-chai": "0.1.0",
    "karma-chrome-launcher": "2.2.0",
    "karma-coverage": "1.1.1",
    "karma-junit-reporter": "1.2.0",
    "karma-mocha": "1.3.0",
    "karma-sharding": "^4.4.0",
    "mocha": "2.3.2",

karma-sharding seems to not run with angular cli

Note: for support questions, please use stackoverflow. This repository's issues are reserved for feature requests and bug reports.

  • I'm submitting a ...

    • bug report
    • feature request
    • support request => Please do not submit support request here, see note at the top of this template.
  • Do you want to request a feature or report a bug?

  • What is the current behavior?
    Split my tests on multiple browsers

  • If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via
    https://plnkr.co or similar (you can use this template as a starting point: http://plnkr.co/edit/tpl:AvJOMERrnz94ekVua0u5).

module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular/cli', 'sharding'],
    browserDisconnectTimeout : 10000,
    browserDisconnectTolerance : 3,
    browserNoActivityTimeout:60000,
    plugins: [
      require('karma-jasmine'),
      require('karma-sharding'),
      require('karma-chrome-launcher'),
      require('karma-mocha-reporter'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('@angular/cli/plugins/karma')
    ],
    client:{
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    coverageIstanbulReporter: {
      reports: [ 'html', 'lcovonly' ],
      fixWebpackSourcePaths: true
    },
    angularCli: {
      environment: 'dev'
    },
    files: [
      { pattern: './src/test.ts', watched: false },
      { pattern: './node_modules/TimelineJS3/compiled/js/timeline.js', watched: false },
      { pattern: './node_modules/TimelineJS3/compiled/css/timeline.css', watched: false },
      { pattern: './node_modules/amcharts3/amcharts/amcharts.js', watched: false },
      { pattern: './node_modules/amcharts3/amcharts/pie.js', watched: false },
      { pattern: './node_modules/amcharts3/amcharts/gauge.js', watched: false },
      { pattern: './node_modules/amcharts3/amcharts/themes/light.js', watched: false }
    ],
    reporters: ['mocha', 'kjhtml'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome','ChromeNoSandbox'],
    customLaunchers: {
      ChromeNoSandbox: {
        base: 'Chrome',
        flags: ['--no-sandbox']
      }
    },
    singleRun: false
  });
};
  • What is the expected behavior?
    That the test was splitted in multiples browsers

  • What is the motivation / use case for changing the behavior?

  • Please tell us about your environment:

  • version: 4.3.0
  • Browser: Chrome 62.0.3202.94
  • Language: TypeScript 2.3
  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, gitter, etc)
    Also, running with ['Chrome', 'Chrome'] doesn't launch two browsers.

Exclusive test (.only()) do not work at all with karma 4.0.1 on latest karma-sharding

Note: for support questions, please use stackoverflow. This repository's issues are reserved for feature requests and bug reports.

  • **I'm submitting a ... **

    • bug report
    • feature request
    • support request => Please do not submit support request here, see note at the top of this template.
  • Do you want to request a feature or report a bug?
    bug

  • What is the current behavior?
    The package.json specifies a version of karma 2.0.0 or above.
    However, it appears that if you use karma 4.0.1, the sharding causes .only() to not work at all. So, even if you set .only() on an it() or describe(), it runs all of the tests (regardless of the number of browsers you set).

  • If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via
    https://plnkr.co or similar (you can use this template as a starting point: http://plnkr.co/edit/tpl:AvJOMERrnz94ekVua0u5).

Rather than setting up a plunker, you can change the package.json file to specify karma 4.0.1, add a .only() to an it(), then run your test suite with 1 browser.

  • What is the expected behavior?
    It (.only()) should work the same with 2.0.0 and 4.0.1.

  • What is the motivation / use case for changing the behavior?
    We want .only() to work the same regardless of the version of karma.

  • Please tell us about your environment:

  • version: master HEAD
  • Browser: Chrome headless
  • Language: ES5
  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, gitter, etc)
    I'm guessing that as part of the refactor of karma to NOT use classnames as part of only(), etc., they changed the architecture so that maybe the part that inspects for only() happens at a different time in the flow of the code, so it isn't working correctly with the hack that is sharding (the way the files are divided up, etc.).

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.