Giter Site home page Giter Site logo

karma-browserify's Introduction

karma-browserify

Browserify for Karma

NPM version Dependency status devDependency Status

Browserify is an awesome tool for managing front-end module dependencies with require, just like you would in Node. Karma is a killer JS test runner that's super fast and easy. But put them together and you're entering a world of pain. This plugin aims to make them play nice.

Under most circumstances, Browserify attempts to give you a single monolithic bundle of all of your JS files and their dependencies. That's perfect for fast delivery with minimal requests in a browser environment, but sucks hard if you're just trying to run your tests (over and over). This plugin hijacks the Browserify pipeline to produce a single bundle of all dependencies found in your tests (and their dependencies) which is transferred to the browser under test only once (unless it changes). A separate, minimal bundle is generated for each test which, aside from the test code, only contains references to external dependencies in the main bundle. That way dependencies are updated in the browser only when necessary (watching for changes is supported) and your tests remain lightning fast.

Installation

Install the plugin from npm:

$ npm install karma-browserify --save-dev

Or from Github:

$ npm install 'git+https://github.com/xdissent/karma-browserify.git' --save-dev

Add browserify to the frameworks and preprocessor keys in your Karma configuration:

module.exports = (config) ->
  config.set

    # frameworks to use
    frameworks: ['mocha', 'browserify']

    preprocessors:
      '**/*.coffee': ['coffee']
      'my/test/files/*': ['browserify']

    # ...

Options

The plugin may be configured using the browserify key in your Karma config:

module.exports = (config) ->
  config.set

    browserify:
      extensions: ['.coffee']
      ignore: [path.join __dirname, 'components/angular-unstable/angular.js']
      transform: ['coffeeify']
      watch: true   # Watches dependencies only (Karma watches the tests)
      debug: true   # Adds source maps to bundle
      noParse: ['jquery'] # Don't parse some modules

    # ...

Usage

Just require modules from within tests as you normally would in Node:

something = require '../some/module'

describe 'karma tests with browserify', ->

  it 'should gimme dat module', ->
    something.should.exist()

See the example for a simple working setup.

License

The MIT License (MIT)

karma-browserify's People

Contributors

alexgorbatchev avatar alexstrat avatar focusaurus avatar jasonpincin avatar mdlavin avatar refractalize avatar vojtajina avatar xdissent avatar

Watchers

 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.