Giter VIP home page Giter VIP logo

karma-browserify's Introduction

karma-browserify

CI

karma-browserify is a fast Browserify integration for Karma that handles large projects with ease.

Installation

Get the plug-in via npm.

You will also need to install browserify and watchify (for auto-watch only) with it.

npm install --save-dev karma-browserify browserify watchify

Usage

Add browserify as a framework to your Karma configuration file. For each file that should be processed and bundled by Karma, configure the browserify preprocessor. Optionally use the browserify config entry to configure how the bundle gets created.

module.exports = function(karma) {
  karma.set({

    frameworks: [ 'browserify', 'jasmine', 'or', 'any', 'other', 'framework' ],
    files: ['test/**/*.js'],
    preprocessors: {
      'test/**/*.js': [ 'browserify' ]
    },

    browserify: {
      debug: true,
      transform: [ 'brfs' ]
    }
  });
}

Look at the example directory for a simple browserify + jasmine project that uses this plug-in.

Browserify Config

Test bundles can be configured through the browserify Karma configuration property. Configuration options are passed directly to browserify.

For example to generate source maps for easier debugging, specify:

    browserify: {
      debug: true
    }

There are three properties that are not passed directly:

Transforms

If you use CoffeeScript, JSX or other tools that need to transform the source file before bundling, specify a browserify transform (Karma preprocessors are not supported).

    browserify: {
      transform: [ 'reactify', 'coffeeify', 'brfs' ]

      // don't forget to register the extensions
      extensions: ['.js', '.jsx', '.coffee']
    }

You can also specify options for the transformations:

    browserify: {
      transform: [ ['reactify', {'es6': true}], 'coffeeify', 'brfs' ]
    }

Plugins

The browserify plugin option supports the same syntax as transform.

    browserify: {
      plugin: [ 'stringify' ]
    }

Additional Bundle Configuration

You may perform additional configuration in a function passed as the configure option and that receives the browserify instance as an argument. A custom prebundle event is emitted on the bundle right before a bundling operation takes place. This is useful when setting up things like externals:

    browserify: {
      configure: function(bundle) {
        bundle.on('prebundle', function() {
          bundle.external('foobar');
        });
      }
    }

You'll also need to use the 'prebundle' event for full control over the order of transforms and plugins:

    browserify: {
      configure: function(bundle) {
        bundle.once('prebundle', function() {
          bundle.transform('babelify').plugin('proxyquireify/plugin');
        });
      }
    }

Note that transforms must only be added once.

Watchify Config

You can configure the underlying watchify instance via config.watchify. This is helpful if you need to fine tune the change detection used during autoWatch=true.

    watchify: {
      poll: true
    }

How it Works

This project is a preprocessor for Karma that combines test files and dependencies into a browserified bundle. It relies on watchify to generate the bundle and to keep it updated during autoWatch=true.

Before the initial test run we build one browserify bundle for all test cases and dependencies. Once any of the files change, it incrementally updates the bundle. Each file included in Karma is required from the file bundle via a stub. Thereby it ensures tests are only executed once per test run.

Detailed Configuration

The following code snippet shows a Karma configuration file with all browserify-related options.

module.exports = function(karma) {
  karma.set({

    // include browserify first in used frameworks
    frameworks: [ 'browserify', 'jasmine' ],

    // add all your files here,
    // including non-commonJS files you need to load before your test cases
    files: [
      'some-non-cjs-library.js',
      'test/**/*.js'
    ],

    // add preprocessor to the files that should be
    // processed via browserify
    preprocessors: {
      'test/**/*.js': [ 'browserify' ]
    },

    // see what is going on
    logLevel: 'LOG_DEBUG',

    // use autoWatch=true for quick and easy test re-execution once files change
    autoWatch: true,

    // add additional browserify configuration properties here
    // such as transform and/or debug=true to generate source maps
    browserify: {
      debug: true,
      transform: [ 'brfs' ],
      configure: function(bundle) {
        bundle.on('prebundle', function() {
          bundle.external('foobar');
        });
      }
    }
  });
};

Related

Credit goes to to the original karma-browserify and karma-browserifast. This library builds on the lessons learned in these projects and offers improved configurability, speed and/or the ability to handle large projects.

Maintainers

License

MIT

karma-browserify's People

Contributors

andrewswerlick-hmn avatar anthony-redfox avatar bendrucker avatar bengro avatar etpinard avatar hypercubed avatar joris-van-der-wel avatar jsdir avatar morganrallen avatar nikku avatar nylen avatar ossdev07 avatar petrbela avatar pmowrer avatar ricardomatias avatar sdtsui avatar smrq avatar steffenmllr avatar thaiat avatar xdissent avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar  avatar

karma-browserify's Issues

How to add es6ify's $traceurRuntime

I have an app using angular, browserify, es6ify which isn't using any ES6 features that require traceur-runtime. Currently I'm able to run my test suite with:

package.json

browserify gulp task

var options = {
  cache: {},
  packagecache: {},
  fullpaths: true
};

var bundler = browserify(es6ify.runtime, options);

bundler
  .add(config.browserify.entries)
  .transform(es6ify);

karma config

config.set({
  basePath: '../',
  frameworks: ['browserify'],
  preprocessors: {
    'app/js/**/*.js': ['browserify']
  },
  browsers: ['Firefox', 'Chrome', 'PhantomJS'],
  reporters: ['progress'],

  autoWatch: true,

  proxies: {
    '/': 'http://localhost:9876/'
  },

  urlRoot: '/__karma__/',

  files: [
    'bower_components/angular-mocks/angular-mocks.js',
    'app/js/main.js',
    'test/unit/**/*.js'
  ],

  browserify: {
    debug: true,
    transform: [ 'es6ify' ]
  }
});

But now that I'm using ES6 classes which require the runtime it's raising errors when trying to run the tests:

PhantomJS 1.9.8 (Mac OS X) ERROR
  ReferenceError: Can't find variable: $traceurRuntime

Firefox 33.0.0 (Mac OS X 10.9) ERROR
  ReferenceError: $traceurRuntime is not defined

Chrome 39.0.2171 (Mac OS X 10.9.5) ERROR
  Uncaught ReferenceError: $traceurRuntime is not defined

So I'd like to know how do I add the runtime to the browserify's karma configuration? At least that's what i think is causing it.

How to apply `browser` package.json field type behaviour before plugins are run

I've wrapped proxyquire in a wrapper and would like to swap it out for proxyquireify before the proxyquerify plugin is run. Sorry to ask for support but I have been banging my head against this for 8 hours now lol.

Here is my current attempt:

karma: {
    jasmine: {
        frameworks: ['browserify', 'jasmine'],
        singleRun: true,
        port: 9876,
        runnerPort: 9100,
        autoWatch: false,
        captureTimeout: 60000,
        exclude: ['**/*.md'],
        reporters: ['story'],
        browsers: ['Chrome'],
        client: {
            captureConsole: true
        },
        preprocessors: {
            './spec/*': ['browserify']
        },
        browserify: {
            alias: ['request:browser-request', './proxyquire-wrapper:proxyquireify'],
            debug: true,
            plugin: ['proxyquireify/plugin'],
        },
        configFile: './jasmine.karma.conf.js'
    }
}

It seems as if the plugin is run before the aliases are applied? Perhaps the aliases are never applied. Any support would be very appreciated. Thanks

Requiring relative coffeescript files does not work, even with coffeeify installed

When trying to include coffeescript files from other coffeescript files when using coffeeify with karma-browserify, I get an error:

karma start karma.conf.js

Uncaught Error: Cannot find module '/Users/doved/source/app/test/config.coffee'

This is my directory structure:

test
----app_test.coffee
----config.coffee
----something.js

My karma config looks like:

module.exports = function(karma) {
  karma.set({
    frameworks: [ 'browserify', 'mocha' ],
    files: ['test/**/*.coffee', 'test/**/*.js'],
    preprocessors: {
      'test/**/*.coffee': [ 'browserify' ]
    },

    browserify: {
      debug: true,
      transform: [ 'coffeeify' ],
      extensions: [ ".coffee"]
    }
  });
}

In app_test.coffee:

something = require('./something')
config = require('./config')

I'm only getting an error when including the config.coffee file, and not when including the something.js file.

Running browserify from the shell works without an error:

browserify -t coffeeify --extension=".coffee" test/app_test.coffee

Safari caches old bundles

I'm not sure this is a karma-bro bug or karma-safari-launcher bug, but I'm finding that when I fix a test, it continues to fail in Safari because the karma-bro output has been cached. I opened the issue here first because I haven't run into this issue (so far) with the other karma browserify adapters). Can the url to the bundle be changed between builds? Either with a new url or even just a cache-busting parameter?

How do you split into external bundles?

First off, as the other commenters said, thanks for this great package. I tried a bunch of others, was very happy when I came across this.

I saw in the README that it supports external packages via prebundle:

    browserify: {
      prebundle: function(bundle) {
        bundle.external(['angular','angular-route']);
      }
    }

So in the above, it will browserify my app, but assume angular is available from "elsewhere". How do you get that "elsewhere"? For general build, I have a script (grunt, or gulp, or just straight "npm script") to build:vendor and build:app, but how do you work this into karma-bro?

bundle.require doesn't appear to work in prebundle hook

I'm currently in the process of trying to work out why a set of tests have recently started failing, and while I'm not certain that karma-browserify is at fault, I have been able to reduce the testcase to a point where I figured it would be useful to open a discussion here.

Here's the code, in the form of a gist: https://gist.github.com/nickstenning/d70fea282c5897658452

Specifically, I was previously able to call bundle.require(...) in a prebundle hook in order to expose a library to the browserify bundle with a specific name (using browserify's expose option). This no longer appears to work.

Here's the output of karma start karma.conf.js --single-run on the above-linked project:

INFO [karma]: Karma v0.12.28 server started at http://localhost:9876/
INFO [launcher]: Starting browser PhantomJS
ERROR [framework.browserify]: bundle error
ERROR [framework.browserify]: Error: Cannot find module 'foo' from '<homedir>/bundlerequire'
INFO [PhantomJS 1.9.8 (Mac OS X)]: Connected on socket ghbV-cdMt-BQHjVpAzsV with id 46640088
PhantomJS 1.9.8 (Mac OS X) ERROR
  TEST RUN WAS CANCELLED because this file contains some errors:
    /var/folders/8r/_p3vfgtn6d991_lrz2vw1w1m0000gn/T/c1e197606dd046b68f412728a2f0b12dbb763706.browserify
PhantomJS 1.9.8 (Mac OS X): Executed 0 of 0 ERROR (0.01 secs / 0 secs)

Passing paths option

Is it possible to pass the paths option to browserify?

Iยดm trying to get a previous setup with gulp-mocha running where I have my sources in js/src/myapp.
And I require the files under test without the relative path: require('myapp/foo').

I have tried adding:

// karma.conf.js
module.exports = function(config) {
  config.set({

   // ...

   browserify: {
        debug: true,
        paths: ['./src/js']
    }, 
   });
};

And also adding the option to package.json. But browserify doesยดnt pick up the paths. Any ideas?

Don't fail if sources are included

If sources are included in the files / preprocessors section in a karma.conf.js karma fails to start with

Chrome 38.0.2125 (Linux) ERROR
  Uncaught Error: Cannot find module '/full/path/to/file.js'
  at /tmp/e23abc7c0b33cd65128e2f9d77ad57525fd1fdbe.browserify:1

This looks like a regression (was supposed to work in karma-bro <= 0.10.

See #51 and #50.

Tests run twice when autoWatch is true

Thanks for a great plugin. I'm encountering an issue where tests are running twice while the karma server is auto-watching. This is with karma 0.12.28 and karma-browserify 1.0.1. I have the following setup:

karma.coffee

module.exports = (config) ->
  config.set
    autoWatch     : true
    basePath      : ''
    browsers      : [ 'Chrome' ]
    colors        : true
    exclude       : [ ]
    files         : [ 'ui/modules/kindler/kindler.ui.spec.coffee' ]
    logLevel      : config.LOG_INFO # or LOG_DISABLE, LOG_ERROR, LOG_WARN, LOG_INFO, LOG_DEBUG.
    port          : 9876
    reporters     : [ 'mocha' ]
    singleRun     : false

    frameworks    : [ 'browserify', 'mocha', 'chai' ]
    preprocessors : { 'ui/modules/kindler/kindler.ui.spec.coffee': [ 'browserify' ] }
    browserify    :
      debug       : true
      transform   : [ 'coffeeify' ]
      extensions  : [ '.coffee' ]

ui/modules/kindler/kindler.ui.spec.coffee

describe 'Kindler UI', ->
  it 'is true', ->
    expect(true).to.equal true

When I first run karma start karma.coffee, the tests run properly (one time) with the following output:

DEBUG [plugin]: Loading karma-* from /Users/Bellows/Development/tendfire/node_modules
DEBUG [plugin]: Loading plugin /Users/Bellows/Development/tendfire/node_modules/karma-browserify.
DEBUG [plugin]: Loading plugin /Users/Bellows/Development/tendfire/node_modules/karma-chai.
DEBUG [plugin]: Loading plugin /Users/Bellows/Development/tendfire/node_modules/karma-chrome-launcher.
DEBUG [plugin]: Loading plugin /Users/Bellows/Development/tendfire/node_modules/karma-mocha.
DEBUG [plugin]: Loading plugin /Users/Bellows/Development/tendfire/node_modules/karma-mocha-reporter.
DEBUG [framework.browserify]: created browserify bundle: /var/folders/vk/nsvhvwyj3yvb7qczgs4k65h00000gn/T/7eef085452ba2254bf49c9e849e70709bfbe389b.browserify
INFO [framework.browserify]: registering rebuild (autoWatch=true)
DEBUG [framework.browserify]: add bundle to config.files at position 0
INFO [karma]: Karma v0.12.28 server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
DEBUG [temp-dir]: Creating temp dir at /var/folders/vk/nsvhvwyj3yvb7qczgs4k65h00000gn/T/karma-39564957
DEBUG [launcher]: /Applications/Google Chrome.app/Contents/MacOS/Google Chrome --user-data-dir=/var/folders/vk/nsvhvwyj3yvb7qczgs4k65h00000gn/T/karma-39564957 --no-default-browser-check --no-first-run --disable-default-apps --disable-popup-blocking --disable-translate http://localhost:9876/?id=39564957
DEBUG [framework.browserify]: building bundle
DEBUG [framework.browserify]: adding ui/modules/kindler/kindler.ui.spec.coffee to bundle
DEBUG [framework.browserify]: bundling
INFO [framework.browserify]: 2189 bytes written (0.06 seconds)
INFO [framework.browserify]: bundle built
DEBUG [watcher]: Resolved files:
    /Users/Bellows/Development/tendfire/node_modules/chai/chai.js
    /Users/Bellows/Development/tendfire/node_modules/karma-chai/adapter.js
    /Users/Bellows/Development/tendfire/node_modules/mocha/mocha.js
    /Users/Bellows/Development/tendfire/node_modules/karma-mocha/lib/adapter.js
    /var/folders/vk/nsvhvwyj3yvb7qczgs4k65h00000gn/T/7eef085452ba2254bf49c9e849e70709bfbe389b.browserify
    /Users/Bellows/Development/tendfire/ui/modules/kindler/kindler.ui.spec.coffee
DEBUG [watcher]: Watching "/var/folders/vk/nsvhvwyj3yvb7qczgs4k65h00000gn/T/7eef085452ba2254bf49c9e849e70709bfbe389b.browserify"
DEBUG [watcher]: Watching "/Users/Bellows/Development/tendfire/ui/modules/kindler/kindler.ui.spec.coffee"
DEBUG [watcher]: Add file "/Users/Bellows/Development/tendfire/ui/modules/kindler/kindler.ui.spec.coffee" ignored. Already in the list.
DEBUG [web-server]: serving: /Users/Bellows/Development/tendfire/node_modules/karma/static/client.html
DEBUG [web-server]: serving: /Users/Bellows/Development/tendfire/node_modules/karma/static/karma.js
DEBUG [web-server]: upgrade /socket.io/1/websocket/RjZns6XtyRv3B9uKuVon
DEBUG [karma]: A browser has connected on socket RjZns6XtyRv3B9uKuVon
INFO [Chrome 39.0.2171 (Mac OS X 10.10.1)]: Connected on socket RjZns6XtyRv3B9uKuVon with id 39564957
DEBUG [launcher]: Chrome (id 39564957) captured in 1.786 secs
DEBUG [karma]: All browsers are ready, executing
DEBUG [web-server]: serving: /Users/Bellows/Development/tendfire/node_modules/karma/static/context.html
DEBUG [web-server]: serving (cached): /Users/Bellows/Development/tendfire/node_modules/chai/chai.js
DEBUG [web-server]: serving (cached): /Users/Bellows/Development/tendfire/node_modules/karma-chai/adapter.js
DEBUG [web-server]: serving (cached): /Users/Bellows/Development/tendfire/node_modules/mocha/mocha.js
DEBUG [web-server]: serving (cached): /Users/Bellows/Development/tendfire/node_modules/karma-mocha/lib/adapter.js
DEBUG [web-server]: serving (cached): /var/folders/vk/nsvhvwyj3yvb7qczgs4k65h00000gn/T/7eef085452ba2254bf49c9e849e70709bfbe389b.browserify
DEBUG [web-server]: serving (cached): /Users/Bellows/Development/tendfire/ui/modules/kindler/kindler.ui.spec.coffee

Start:
  Kindler UI
    โœ” is true

Finished in 0.006 secs / 0.001 secs

SUMMARY:
โœ” 1 tests completed

However, each successive time the tests run twice with the following output:

INFO [watcher]: Changed file "/Users/Bellows/Development/tendfire/ui/modules/kindler/kindler.ui.spec.coffee".
DEBUG [framework.browserify]: bundling
INFO [framework.browserify]: 2189 bytes written (0.01 seconds)
INFO [framework.browserify]: bundle updated
DEBUG [karma]: List of files has changed, trying to execute
DEBUG [karma]: All browsers are ready, executing
INFO [watcher]: Changed file "/var/folders/vk/nsvhvwyj3yvb7qczgs4k65h00000gn/T/7eef085452ba2254bf49c9e849e70709bfbe389b.browserify".
DEBUG [web-server]: serving (cached): /Users/Bellows/Development/tendfire/node_modules/karma/static/context.html
  Kindler UI
    โœ” is true

Finished in 0.005 secs / 0 secs

SUMMARY:
โœ” 1 tests completed
DEBUG [framework.browserify]: files changed
DEBUG [framework.browserify]: bundling
INFO [framework.browserify]: 2189 bytes written (0.01 seconds)
INFO [framework.browserify]: bundle updated
INFO [watcher]: Changed file "/var/folders/vk/nsvhvwyj3yvb7qczgs4k65h00000gn/T/7eef085452ba2254bf49c9e849e70709bfbe389b.browserify".
DEBUG [karma]: List of files has changed, trying to execute
DEBUG [karma]: All browsers are ready, executing
DEBUG [web-server]: serving (cached): /Users/Bellows/Development/tendfire/node_modules/karma/static/context.html
  Kindler UI
    โœ” is true

Finished in 0.004 secs / 0 secs

SUMMARY:
โœ” 1 tests completed

This happens reliably as soon as I add the browserify preprocessor. I have also tried it with vanilla JS and without any options passed to browserify, and the tests still run twice. I've also tried it with jasmine instead of mocha and chai with the same results. It also occurs with the standard progress runner.

Setting autoWatch = false and then using karma run karma.coffee works properly.

Is this something with my setup or a bug?

Thanks for your time!!

Karma + Karma-bro + proxyquireify don't get along

Hey,
I've posted this issue to proxyquireify (mocking library) in regards to my attempt to have the aforementioned setup to work:
thlorenz/proxyquireify#15

The bug is that proxyquireify is a plugin for Browserify which mocks required dependencies, and it doesn't work in the repo above.

The thing is that it is yet unclear where the unexpected behavior of the test suite comes from Karma, karma-bro (specifically how plugins are handled), proxyquireify... or me.

A demo repo is here: https://github.com/xcambar/karma-bro-proxyquireify

Please, can you have a look at it so I can move on in my investigations?

Tests fail on Windows

Looks like some sort of double-escaping issue. Don't you hate this dumb platform? I haven't really looked into it just yet, working on #33 first.

 1) bro preprocessing should create bundle:
     Uncaught AssertionError: expected '(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module \'"+o+"\'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({"C:\\\\Code\\\\karma-bro\\\\test\\\\fixtures\\\\a.js":[function(require,module,exports){\n\'use strict\';\r\n\r\nmodule.exports = \'A\';\n},{}],"C:\\\\Code\\\\karma-bro\\\\test\\\\fixtures\\\\b.js":[function(require,module,exports){\n\'use strict\';\r\n\r\nvar a = require(\'./a\');\r\n\r\nmodule.exports = \'B\' + a;\n},{"./a":"C:\\\\Code\\\\karma-bro\\\\test\\\\fixtures\\\\a.js"}]},{},["C:\\\\Code\\\\karma-bro\\\\test\\\\fixtures\\\\b.js"]);\n' to include '"C:\\Code\\karma-bro\\test\\fixtures\\b.js"'
      at C:\Code\karma-bro\test\spec\pluginSpec.js:267:39
      at fileProcessed (C:\Code\karma-bro\test\spec\pluginSpec.js:73:7)
      at C:\Code\karma-bro\test\spec\pluginSpec.js:79:7
      at C:\Code\karma-bro\lib\bro.js:270:9
      at Browserify.<anonymous> (C:\Code\karma-bro\lib\bro.js:244:9)
      at Browserify.g (events.js:199:16)
      at Browserify.emit (events.js:129:20)
      at C:\Code\karma-bro\lib\bro.js:225:11
      at C:\Code\karma-bro\node_modules\browserify\index.js:664:13
      at ConcatStream.<anonymous> (C:\Code\karma-bro\node_modules\browserify\node_modules\concat-stream\index.js:32:43)

  2) bro preprocessing should pass through on updates:
     Uncaught AssertionError: expected '(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module \'"+o+"\'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({"C:\\\\Code\\\\karma-bro\\\\test\\\\fixtures\\\\a.js":[function(require,module,exports){\n\'use strict\';\r\n\r\nmodule.exports = \'A\';\n},{}],"C:\\\\Code\\\\karma-bro\\\\test\\\\fixtures\\\\b.js":[function(require,module,exports){\n\'use strict\';\r\n\r\nvar a = require(\'./a\');\r\n\r\nmodule.exports = \'B\' + a;\n},{"./a":"C:\\\\Code\\\\karma-bro\\\\test\\\\fixtures\\\\a.js"}]},{},["C:\\\\Code\\\\karma-bro\\\\test\\\\fixtures\\\\b.js"]);\n' to include '"C:\\Code\\karma-bro\\test\\fixtures\\b.js"'
      at C:\Code\karma-bro\test\spec\pluginSpec.js:295:41
      at fileProcessed (C:\Code\karma-bro\test\spec\pluginSpec.js:73:7)
      at C:\Code\karma-bro\test\spec\pluginSpec.js:79:7
      at C:\Code\karma-bro\lib\bro.js:270:9
      at Browserify.<anonymous> (C:\Code\karma-bro\lib\bro.js:244:9)
      at Browserify.g (events.js:199:16)
      at Browserify.emit (events.js:129:20)
      at C:\Code\karma-bro\lib\bro.js:225:11
      at C:\Code\karma-bro\node_modules\browserify\index.js:664:13
      at ConcatStream.<anonymous> (C:\Code\karma-bro\node_modules\browserify\node_modules\concat-stream\index.js:32:43)

pipe preprocessors

Hello,

I tried karma-bro and it occurs that if I use

preprocessors: {
        'src/index.js': ['other-preprocessor', 'browserify']
    }

the file returned by browserify preprocessor is not the one processed by other-preprocessor but the original file src/index.js browserified.

Have you ever had this use case? (in my case, 'other-preprocessor' is a es6-transpiler).

Cheers,

paths parameter ignored

I'm not sure if this is handeled by a parameter elsewere but when I ant to add a paths parameter to the browserify task in karma.conf it is ignored.

browserify: {
paths: ['src/js/code']

I have overcome this by editing the bro.js code line 123 and changing:
var browserifyOptions = _.extend({}, watchify.args, _.pick(bopts, [
'extensions', 'builtins', 'basedir', 'commondir', 'debug'
]));
to
var browserifyOptions = _.extend({}, watchify.args, _.pick(bopts, [
'extensions', 'builtins', 'basedir', 'commondir', 'debug', 'paths'
]));

I was hoping that this could be included in the official repo unless there is a good reason why it should not be there.

Thanks
Peter

TypeError: 'undefined' is not an object when using browserify-shim

When using karma-browserify with the browserify-shim transform on a non-CJS module (fancySelect). I keep running into this issue:

...
PhantomJS 1.9.8 (Mac OS X) ERROR
    TypeError: 'undefined' is not an object (evaluating '$.fn')
    at /Users/Mark/Sites/karma-shim-test/src/components/fancyselect/fancySelect.js:7

Here is my package.json:

{
    "name": "karma-jquery-issue",
    "browser": {
        "fancySelect": "./src/components/fancyselect/fancySelect.js"
    },
    "browserify": {
        "transform": [
            "coffeeify"
        ]
    },
    "browserify-shim": {
        "fancySelect": {
            "depends": ["jquery:jQuery"]
        }
    },
    "devDependencies": {
        "browserify": "6.3.3",
        "browserify-shim": "3.8.0",
        "coffeeify": "^1.0.0",
        "karma": "^0.12.28",
        "karma-browserify": "^1.0.0",
        "karma-phantomjs-launcher": "^0.1.4"
    },
    "dependencies": {
        "jquery": "^2.1.1"
    }
}

Here is my karma.conf.json:

module.exports = function (karma) {
    karma.set({
        browserify: {
            debug: true,
            transform: ['browserify-shim'],
            extensions: ['.coffee']
        },

        browsers: ['PhantomJS'],

        files: [
            './src/components/fancyselect/fancySelect.js',
            'tests/**/*.coffee'
        ],

        frameworks: ['browserify'],

        preprocessors: {
            'tests/**/*.coffee': ['browserify']
        }
    });
};

I tried installing jQuery as a Bower dependency and adding a reference to the browser hash but I got the exact same error. It almost seems as if the browerify-shim config isn't being read.

karma-bro + angular

Hi,

I somehow cannot get karma to work well with angular and browserify.
On the app side I have to following configuration:
package.json

...
"browserify": {
    "transform": [
      "browserify-shim"
    ]
  },
  "browser": {
    "angular": "./bower_components/angular/angular.js"
  },
  "browserify-shim": {
    "angular": {
      "exports": "angular"
    }
...

Then in the code i can do the following:

var angular = require('angular');
angular.module....

This works fine, and allow me to use the bower distribution of angular with browserify.

Now in karma i should be able to do the same thing and in addition add also the angular-mocks library. The browserify section in the karma.config does not seem to allow declaring shims.
I could not find any successfull implementation of that, any help would be appreciated...

Symlinks not watched on OS X

@bendrucker your guys' library is saving me from some crazy issues I was having manually bundling and having karma watch the bundle so thank you! but I'm having one major issue.

I can only imagine that I'm doing something super wrong cause this seems like something anyone would catch otherwise but here's my situation:

I have reduced the failing case to a pretty straightforward setup with two files:
one util file - src/modules/util/index.js
and one spec file for that module - src/modules/util/util.spec.js

the spec file requires the util file via:

var util
beforeEach(function(){
    util = require('@grid/util');
});

@grid is a symlink from node_modules/@grid to ../src/modules/

changes to util.spec.js reflect properly, but when i change util/index.js the tests rerun but do not reflect the changes to the file. I can introduce null pointers with no effect. If i restart gulp entirely the changes are reflected at that time.

I tried not using the symlink and requiring it like:
require('./index.js')
or
require('../util/index.js')

but i get: Error: Cannot find module '/Users/scamden/projects/riq-grid/src/modules/util/index.js'
which is a valid directory.

I'm at a loss here, am i missing something?

here's my karma.conf.js if it helps:

module.exports = function (config) {
    config.set({

        // base path that will be used to resolve all patterns (eg. files, exclude)
        basePath: '',

        frameworks: ['browserify', 'jasmine'],

        files: [
            'bower_components/angular/angular.js',
            'bower_components/angular-mocks/angular-mocks.js',
            'src/modules/util/*.js'
        ],
        exclude: [],

        preprocessors: {
            'src/modules/util/*.js': ['browserify']
        },
        reporters: ['progress', /*'story',*/ 'coverage'],

        port: 9876,

        colors: true,

        logLevel: config.LOG_INFO,

        autoWatch: true,

        browsers: ['PhantomJS'],

        browserNoActivityTimeout: 3000000,

        singleRun: false,

        reportSlowerThan: 250

    });
};

Add bundle before test files

First off, many thanks for writing the first Karma Browserify plugin that actually works. After lots of frustrations with browserify and browserifast it's really refreshing to find something that actually works.

I'm using browserify with Angular projects. I've experimented with a bunch of different strategies for using browserify-shim. The only sensible way to ship CommonJS components is to use browserify-shim's global option which turns var angular = require('angular') into var angular = (window.angular). That means I'd like my files array to look like this:

files: [
  'components/angular/angular.js',
  'components/angular-mocks/angular-mocks.js',
  'components/stripe/index.js',
  'test/*.js'
]

Because the bundle gets unshifted onto the files array, the tests run before the globals are available. Was looking to see if there might be a way to figure out where in the file array the bundle was located but couldn't figure it out.

Any chance this is possible? Happy to help on a PR.

Upgrade to Browserify 5.x

Browserify 5.x introduces breaking changes. We should investigate these changes and upgrade to it at some point. Related to #10.

Todos

  • upgrade brfs once compatible
  • investigate error handling problems (currently the plug-in fails to correctly report errors on files with syntax errors

Update Travis

You just need to run travis enable -R nikku/karma-browserify to sync Travis to the new repo.

Is there a way to pass options down to tranformers?

E.g. I'm using rewireify and I'd like to ignore some files. Using browserify CLI it goes like this:

$ browserify -e app.js -o test-bundle.js -t [ rewireify --ignore filename,second-filename ] -s test-bundle

I flailed around and I tried some semi-obvious things to no avail (e.g. adding a rewireify key with options inside karma.conf.js at various places).

Thanks in advance for any advice on this!

Sometimes tests don't run at all with autoWatch=true

Hi. It's a strange issue i'm having. First time i run karma karma.conf.js it runs well, but when i change my test files it sometimes runs the tests and sometimes doesn't(although it seems that it runs them twice!). I tried setting bundleDelay as high as 3000, but it doesn't help. I'll explain what i mean. First, here's my config file:

'use strict';

module.exports = function (karma) {

  karma.set({

    basePath: '../',

    colors: true,

    frameworks: [
      'browserify',
      'jasmine',
      'jasmine-matchers'
    ],

    preprocessors: {
      './test/unit/**/*.coffee': ['browserify']
    },

    browsers: ['PhantomJS'],

    reporters: ['mocha'],

    browserify: {
      transform: ['coffeeify', 'brfs', 'browserify-shim'],
      extensions: ['.coffee'],
    },

    autoWatch: true,

    logLevel: 'LOG_DEBUG',

    files: [
      './js/vendor/jquery/jquery.js',
      './js/vendor/lodash/lodash.compat.js',
      './js/vendor/**/*.js',
      './test/unit/**/*.coffee'
    ]

  });

};

Here's my spec file:

'use strict'

describe 'vendor libraries', ->

  describe 'jQuery', ->
    it 'should be defined on window', ->
      expect(window.jQuery)
        .toBeObject()

So the first time i run karma karma.conf.js, it runs this test and it passes.

Then i edit this file. Lets say i'll do this:

'use strict'

describe 'vendor libraries', ->

  describe 'jQuery', ->
    it 'should be defined on window, I HOPE SO', ->
      expect(window.jQuery)
        .toBeObject()

i added "I HOPE SO".

So i changed this file, saved it and it runs the test twice. Here's the output:

INFO [watcher]: Changed file "/Users/le0/Projects/GulpTest/src/assets/scripts/test/unit/vendorSpec.coffee".
DEBUG [framework.browserify]: updating test/unit/vendorSpec.coffee in bundle
DEBUG [framework.browserify]: resetting bundle
DEBUG [framework.browserify]: bundling
INFO [framework.browserify]: 805 bytes written (0.00 seconds)
INFO [framework.browserify]: bundle updated
DEBUG [karma]: List of files has changed, trying to execute
DEBUG [karma]: All browsers are ready, executing
INFO [watcher]: Changed file "/var/folders/n8/wl3658qx0ll4bp3vdhl24j0m0000gn/T/70ba12dbd320662a60e66eef11f82f3f7ba65c8e.browserify".
DEBUG [web-server]: serving (cached): /Users/le0/Projects/GulpTest/node_modules/karma/static/context.html
  vendor libraries
    jQuery
      โœ” should be defined on window

Finished in 0.001 secs / 0.002 secs

SUMMARY:
โœ” 1 tests completed
DEBUG [framework.browserify]: files changed
DEBUG [framework.browserify]: resetting bundle
DEBUG [framework.browserify]: removing missing file ../../../test/unit/vendorSpec.coffee
DEBUG [framework.browserify]: bundling
INFO [framework.browserify]: 454 bytes written (0.00 seconds)
INFO [framework.browserify]: bundle updated
INFO [watcher]: Changed file "/var/folders/n8/wl3658qx0ll4bp3vdhl24j0m0000gn/T/70ba12dbd320662a60e66eef11f82f3f7ba65c8e.browserify".
DEBUG [karma]: List of files has changed, trying to execute
DEBUG [karma]: All browsers are ready, executing
DEBUG [web-server]: serving (cached): /Users/le0/Projects/GulpTest/node_modules/karma/static/context.html
PhantomJS 1.9.8 (Mac OS X) ERROR
  ReferenceError: Can't find variable: require
  at /Users/le0/Projects/GulpTest/src/assets/scripts/test/unit/vendorSpec.coffee:1

Finished in 0.276 secs / 0 secs

SUMMARY:
โœ” 0 tests completed

As you can see, it runs it two times now. First time it looks like it runs, but then it somehow thinks the file changed again and it tries to run again. Now it gives the error

'PhantomJS 1.9.8 (Mac OS X) ERROR
  ReferenceError: Can't find variable: require
  at /Users/le0/Projects/GulpTest/src/assets/scripts/test/unit/vendorSpec.coffee:1

But notice this: on the first run, the test doesn't say 'I HOPE SO'. It says what was previously there.

So the test didn't run at all!

If i save this file again it might run normally, but it might do the same thing again. It's completely random. It 100% works only the first time i launch it.

Also sometimes it gives me another error, when i first launch karma karma.conf.js

PhantomJS 1.9.8 (Mac OS X) ERROR
  TEST RUN WAS CANCELLED because this file contains some errors:
    /var/folders/n8/wl3658qx0ll4bp3vdhl24j0m0000gn/T/70ba12dbd320662a60e66eef11f82f3f7ba65c8e.browserify

I do karma karma.conf.js again and it works fine... Go figure.

Versions of all npm packages are latest as of today.

If you need anything else, i can create an example repo. I'm just trying this stuff out so i might've made a mistake and maybe it's my own fault and not an issue with your cool package.

One thing i can say is that it's not jasmine-matchers plugin's fault, because it worked like that before i added it.

Level of support from repo

I just wanted to ask if you plan on regularly supporting this plugin?
I'm keen to use Browserify but support for testing tools seems quite poor.

Phpstorm caches test files

Phpstorm (and Webstorm) have a plugin that runs karma tests. For some reason there is some incompatibilty that prevents the tests from being properly invalidated.

I tested using the example and changing failingSpec.js from the failure to "expect(true).toBe(true);"

I get the following logs.

Phpstorm intergrated runner:

/usr/bin/node /home/ulrik/.WebIde80/config/plugins/js-karma/js_reporter/karma-intellij/lib/intellijServer.js --karmaPackageDir=/home/ulrik/Projects/karma-bro/example/node_modules/karma --configFile=/home/ulrik/Projects/karma-bro/example/karma.conf.js
DEBUG [plugin]: Loading karma-* from /home/ulrik/Projects/karma-bro/example/node_modules
DEBUG [plugin]: Loading plugin /home/ulrik/Projects/karma-bro/example/node_modules/karma-bro.
DEBUG [plugin]: Loading plugin /home/ulrik/Projects/karma-bro/example/node_modules/karma-chrome-launcher.
DEBUG [plugin]: Loading plugin /home/ulrik/Projects/karma-bro/example/node_modules/karma-jasmine.
DEBUG [plugin]: Loading plugin /home/ulrik/Projects/karma-bro/example/node_modules/karma-phantomjs-launcher.
DEBUG [plugin]: Loading plugin /home/ulrik/.WebIde80/config/plugins/js-karma/js_reporter/karma-intellij/lib/intellijPlugin.js.
DEBUG [framework.browserify]: bundle file used: /tmp/80b6bd75d1c5ac7a5dbeaab6d79c412cce083100.browserify
DEBUG [framework.browserify]: insert browserified bundle in config.files at position 3
WARN [karma]: Port 9876 in use
INFO [karma]: Karma v0.12.24 server started at http://localhost:9877/
INFO [launcher]: Starting browser PhantomJS
DEBUG [temp-dir]: Creating temp dir at /tmp/karma-7729754
DEBUG [launcher]: /home/ulrik/Projects/karma-bro/example/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/bin/phantomjs /tmp/karma-7729754/capture.js
DEBUG [framework.browserify]: creating initial bundle
DEBUG [framework.browserify]: added file to bundle: test/bSpec.js
DEBUG [framework.browserify]: added file to bundle: test/externalSpec.js
DEBUG [framework.browserify]: added file to bundle: test/failingSpec.js
DEBUG [web-server]: serving: /home/ulrik/Projects/karma-bro/example/node_modules/karma/static/client.html
DEBUG [web-server]: serving: /home/ulrik/Projects/karma-bro/example/node_modules/karma/static/karma.js
DEBUG [web-server]: upgrade /socket.io/1/websocket/nYGeYOTVbiZ_e6u_3hbG
DEBUG [karma]: A browser has connected on socket nYGeYOTVbiZ_e6u_3hbG
INFO [PhantomJS 1.9.7 (Linux)]: Connected on socket nYGeYOTVbiZ_e6u_3hbG with id 7729754
DEBUG [launcher]: PhantomJS (id 7729754) captured in 0.654 secs
DEBUG [karma]: Execution (fired by runner)
DEBUG [karma]: Setting client.args to  undefined
DEBUG [karma]: All browsers are ready, executing
DEBUG [framework.browserify]: building bundle
INFO [framework.browserify]: bundle built (92ms, 5kB)
DEBUG [framework.browserify]: built initial bundle
DEBUG [framework.browserify]: created stub for file: test/bSpec.js
DEBUG [framework.browserify]: created stub for file: test/externalSpec.js
DEBUG [framework.browserify]: created stub for file: test/failingSpec.js
DEBUG [watcher]: Resolved files:
    /home/ulrik/Projects/karma-bro/example/node_modules/karma-jasmine/lib/jasmine.js
    /home/ulrik/Projects/karma-bro/example/node_modules/karma-jasmine/lib/adapter.js
    /home/ulrik/Projects/karma-bro/example/vendor/external.js
    /tmp/80b6bd75d1c5ac7a5dbeaab6d79c412cce083100.browserify
    /home/ulrik/Projects/karma-bro/example/test/bSpec.js
    /home/ulrik/Projects/karma-bro/example/test/externalSpec.js
    /home/ulrik/Projects/karma-bro/example/test/failingSpec.js
DEBUG [web-server]: serving: /home/ulrik/Projects/karma-bro/example/node_modules/karma/static/context.html
DEBUG [web-server]: serving (cached): /home/ulrik/Projects/karma-bro/example/node_modules/karma-jasmine/lib/jasmine.js
DEBUG [web-server]: serving (cached): /home/ulrik/Projects/karma-bro/example/test/failingSpec.js
DEBUG [web-server]: serving (cached): /home/ulrik/Projects/karma-bro/example/node_modules/karma-jasmine/lib/adapter.js
DEBUG [web-server]: serving (cached): /home/ulrik/Projects/karma-bro/example/vendor/external.js
DEBUG [web-server]: serving (cached): /tmp/80b6bd75d1c5ac7a5dbeaab6d79c412cce083100.browserify
DEBUG [web-server]: serving (cached): /home/ulrik/Projects/karma-bro/example/test/bSpec.js
DEBUG [web-server]: serving (cached): /home/ulrik/Projects/karma-bro/example/test/externalSpec.js
INFO [watcher]: Changed file "/home/ulrik/Projects/karma-bro/example/test/failingSpec.js".
DEBUG [framework.browserify]: added file to bundle: test/failingSpec.js
DEBUG [karma]: Execution (fired by runner)
DEBUG [karma]: Setting client.args to  undefined
DEBUG [karma]: All browsers are ready, executing
DEBUG [web-server]: serving (cached): /home/ulrik/Projects/karma-bro/example/node_modules/karma/static/context.html
DEBUG [web-server]: serving (cached): /home/ulrik/Projects/karma-bro/example/test/failingSpec.js
DEBUG [framework.browserify]: building bundle
INFO [framework.browserify]: bundle built (23ms, 5kB)
DEBUG [framework.browserify]: created stub for file: test/failingSpec.js

karma start

DEBUG [plugin]: Loading karma-* from /home/ulrik/Projects/karma-bro/example/node_modules
DEBUG [plugin]: Loading plugin /home/ulrik/Projects/karma-bro/example/node_modules/karma-bro.
DEBUG [plugin]: Loading plugin /home/ulrik/Projects/karma-bro/example/node_modules/karma-chrome-launcher.
DEBUG [plugin]: Loading plugin /home/ulrik/Projects/karma-bro/example/node_modules/karma-jasmine.
DEBUG [plugin]: Loading plugin /home/ulrik/Projects/karma-bro/example/node_modules/karma-phantomjs-launcher.
DEBUG [framework.browserify]: bundle file used: /tmp/80b6bd75d1c5ac7a5dbeaab6d79c412cce083100.browserify
DEBUG [framework.browserify]: insert browserified bundle in config.files at position 3
WARN [karma]: Port 9876 in use
WARN [karma]: Port 9877 in use
INFO [karma]: Karma v0.12.24 server started at http://localhost:9878/
INFO [launcher]: Starting browser PhantomJS
DEBUG [temp-dir]: Creating temp dir at /tmp/karma-67329401
DEBUG [launcher]: /home/ulrik/Projects/karma-bro/example/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/bin/phantomjs /tmp/karma-67329401/capture.js
DEBUG [framework.browserify]: register bundle update (autoWatch=true)
DEBUG [framework.browserify]: creating initial bundle
DEBUG [framework.browserify]: added file to bundle: test/bSpec.js
DEBUG [framework.browserify]: added file to bundle: test/externalSpec.js
DEBUG [framework.browserify]: added file to bundle: test/failingSpec.js
DEBUG [web-server]: serving: /home/ulrik/Projects/karma-bro/example/node_modules/karma/static/client.html
DEBUG [web-server]: serving: /home/ulrik/Projects/karma-bro/example/node_modules/karma/static/karma.js
DEBUG [web-server]: upgrade /socket.io/1/websocket/GF_zK7xYYAdv8_i-3j_l
DEBUG [karma]: A browser has connected on socket GF_zK7xYYAdv8_i-3j_l
INFO [PhantomJS 1.9.7 (Linux)]: Connected on socket GF_zK7xYYAdv8_i-3j_l with id 67329401
DEBUG [launcher]: PhantomJS (id 67329401) captured in 0.608 secs
DEBUG [karma]: All browsers are ready, executing
DEBUG [framework.browserify]: building bundle
INFO [framework.browserify]: bundle built (92ms, 5kB)
DEBUG [framework.browserify]: built initial bundle
DEBUG [framework.browserify]: created stub for file: test/bSpec.js
DEBUG [framework.browserify]: created stub for file: test/externalSpec.js
DEBUG [framework.browserify]: created stub for file: test/failingSpec.js
DEBUG [watcher]: Resolved files:
        /home/ulrik/Projects/karma-bro/example/node_modules/karma-jasmine/lib/jasmine.js
        /home/ulrik/Projects/karma-bro/example/node_modules/karma-jasmine/lib/adapter.js
        /home/ulrik/Projects/karma-bro/example/vendor/external.js
        /tmp/80b6bd75d1c5ac7a5dbeaab6d79c412cce083100.browserify
        /home/ulrik/Projects/karma-bro/example/test/bSpec.js
        /home/ulrik/Projects/karma-bro/example/test/externalSpec.js
        /home/ulrik/Projects/karma-bro/example/test/failingSpec.js
DEBUG [watcher]: Watching "/home/ulrik/Projects/karma-bro/example/vendor/external.js"
DEBUG [watcher]: Watching "/tmp/80b6bd75d1c5ac7a5dbeaab6d79c412cce083100.browserify"
DEBUG [watcher]: Watching "/home/ulrik/Projects/karma-bro/example/test"
DEBUG [watcher]: Add file "/tmp/80b6bd75d1c5ac7a5dbeaab6d79c412cce083100.browserify" ignored. Already in the list.
DEBUG [web-server]: serving: /home/ulrik/Projects/karma-bro/example/node_modules/karma/static/context.html
DEBUG [web-server]: serving (cached): /home/ulrik/Projects/karma-bro/example/node_modules/karma-jasmine/lib/jasmine.js
DEBUG [web-server]: serving (cached): /home/ulrik/Projects/karma-bro/example/test/failingSpec.js
DEBUG [web-server]: serving (cached): /home/ulrik/Projects/karma-bro/example/node_modules/karma-jasmine/lib/adapter.js
DEBUG [web-server]: serving (cached): /home/ulrik/Projects/karma-bro/example/vendor/external.js
DEBUG [web-server]: serving (cached): /tmp/80b6bd75d1c5ac7a5dbeaab6d79c412cce083100.browserify
DEBUG [web-server]: serving (cached): /home/ulrik/Projects/karma-bro/example/test/bSpec.js
DEBUG [web-server]: serving (cached): /home/ulrik/Projects/karma-bro/example/test/externalSpec.js
DEBUG [watcher]: Add file "/home/ulrik/Projects/karma-bro/example/test/bSpec.js" ignored. Already in the list.
DEBUG [watcher]: Add file "/home/ulrik/Projects/karma-bro/example/test/externalSpec.js" ignored. Already in the list.
DEBUG [watcher]: Add file "/home/ulrik/Projects/karma-bro/example/test/failingSpec.js" ignored. Already in the list.
..
PhantomJS 1.9.7 (Linux) failing spec should result in nicely formated stack trace FAILED
        Error: intentional
            at /tmp/80b6bd75d1c5ac7a5dbeaab6d79c412cce083100.browserify:17:0 <- /home/ulrik/Projects/karma-bro/example/lib/fail.js:2:0
            at /tmp/80b6bd75d1c5ac7a5dbeaab6d79c412cce083100.browserify:62:0 <- /home/ulrik/Projects/karma-bro/example/test/failingSpec.js:8:0
PhantomJS 1.9.7 (Linux): Executed 3 of 3 (1 FAILED) (0.046 secs / 0.002 secs)
INFO [watcher]: Changed file "/home/ulrik/Projects/karma-bro/example/test/failingSpec.js".
DEBUG [framework.browserify]: added file to bundle: test/failingSpec.js
DEBUG [framework.browserify]: bundle file changed [ '/home/ulrik/Projects/karma-bro/example/test/failingSpec.js' ]
DEBUG [framework.browserify]: building bundle
INFO [framework.browserify]: bundle built (43ms, 5kB)
DEBUG [framework.browserify]: created stub for file: test/failingSpec.js
DEBUG [karma]: List of files has changed, trying to execute
DEBUG [karma]: All browsers are ready, executing
DEBUG [framework.browserify]: bundle file updated
INFO [watcher]: Changed file "/tmp/80b6bd75d1c5ac7a5dbeaab6d79c412cce083100.browserify".
DEBUG [web-server]: serving (cached): /home/ulrik/Projects/karma-bro/example/node_modules/karma/static/context.html
DEBUG [web-server]: serving (cached): /tmp/80b6bd75d1c5ac7a5dbeaab6d79c412cce083100.browserify
DEBUG [web-server]: serving (cached): /home/ulrik/Projects/karma-bro/example/test/failingSpec.js
...
PhantomJS 1.9.7 (Linux): Executed 3 of 3 SUCCESS (0.037 secs / 0.003 secs)

Cannot load "browserify" warning and then "require is not defined" error.

It seems that karma-bro has stopped working with current versions (Node v0.10.29 Mac OS X):

"devDependencies": {
    "karma": "^0.12.19",
    "karma-bro": "^0.6.0",
    "karma-chrome-launcher": "^0.1.4",
    "karma-jasmine": "^0.1.5",
    "watchify": "^1.0.1"
  }

Reproduced with karma-bro example in Mac OS X and Windows 7.

module not found when running tests on windows

This is continuation of #41
The example project is https://github.com/estekhin/sandbox-karma-browserify, the issue is reproduced by simply running karma start karma.conf.js on a windows machine.

I have tried to apply replace(/\\/g, '/') to identifiers/filepaths exposed by karma-browserify (in karma-browserify/bro.js) and to identifiers/filepaths produced/resolved by browserify (in browserify/index.js). In the end the test was able to run successfully.

I would say that the problem lies in a way path.relative() works - it returns ''-separated path on windows, which results in a mix of '/'-separated and ''-separated strings that denote different filepaths and identifiers.
In particular, createBundle() in bro.js iterates the file array and calls w.require(f, expose : path.relative( config.basePath, f )}) where both config.basePath and f are '/'-separated file paths but the result of resolve is ''-separated.

I am not yet sure why "production" code works when transformed via browserify - it uses essentially the same mechanism and is being built on the same windows machine, but the resulting bundle works ok and all dependencies are being resolved ok.

Order of files added to bundle is non-deterministic

Browserify respects the order of files that are included, and sometimes that ordering can be significant. I have a situation in one of my codebases in which tests sometimes fail because b.add() is called on the input files in a different order.

I'm pretty sure this is because Karma runs testFilePreprocessor in a non-deterministic order on the input files. I think that Karma normally includes files in the order specified in files in its config, but that doesn't mean much here since the individual files are replaced with stubs. (Correctly ordered stubs!) Can, and should, karma-bro respect that ordering for files it adds to its bundle?

Module not found using Windows 7

Before I switched to windows from linux my karma tests with karma-bro worked perfectly. On Windows 7 I get the following Error:

Uncaught Error: Cannot find module 'C:\Programmieren\client\app\modules\auth\auth.js'
at http://localhost:9877/absoluteC:/Users/Roger/AppData/Local/Temp/19a43f07f5e40abd1e4cce262ad245220e2acc25.browserify?da39a3ee5e6b4b0d3255bfef95601890afd80709:1

After opening the link in a browser I find the module but slashes are used:

..
({"C:/Programmieren/client/app/modules/auth/auth.js":[function(require,module,exports){
...

I assume that's the reason why the module is not found?

I am using following versions:
karma-bro: 0.8.0
karam: 0.12.24

Failure to find module using example app

I'm using the current version (9545169) of this repo to test using Karma with Browserify.

When I run the example app with "npm test" I get a failure to find a module. I originally received the same error in my personal project and thought I'd try the example app to make sure my environment was sane.

Here is the output


> [email protected] test /Users/joe/dev/play/karma-browserify/example
> node_modules/karma/bin/karma start

DEBUG [plugin]: Loading karma-* from /Users/joe/dev/play/karma-browserify/example/node_modules
DEBUG [plugin]: Loading plugin /Users/joe/dev/play/karma-browserify/example/node_modules/karma-browserify.
DEBUG [plugin]: Loading plugin /Users/joe/dev/play/karma-browserify/example/node_modules/karma-chrome-launcher.
DEBUG [plugin]: Loading plugin /Users/joe/dev/play/karma-browserify/example/node_modules/karma-jasmine.
DEBUG [plugin]: Loading plugin /Users/joe/dev/play/karma-browserify/example/node_modules/karma-phantomjs-launcher.
DEBUG [framework.browserify]: created browserify bundle: /var/folders/99/490t3s6x7r573sb3d1grb1_c0000gn/T/652a5c663eb0ac2b3e30ad5c86d7ccbaefc6819f.browserify
DEBUG [framework.browserify]: add bundle to config.files at position 3
WARN [karma]: Port 9876 in use
INFO [karma]: Karma v0.12.25 server started at http://localhost:9877/
INFO [launcher]:  Starting browser PhantomJS
DEBUG [temp-dir]: Creating temp dir at /var/folders/99/490t3s6x7r573sb3d1grb1_c0000gn/T/karma-21387361
DEBUG [launcher]: /Users/joe/dev/play/karma-browserify/example/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/bin/phantomjs /var/folders/99/490t3s6x7r573sb3d1grb1_c0000gn/T/karma-21387361/capture.js
DEBUG [framework.browserify]: building bundle
DEBUG [framework.browserify]: adding lib/a.js to bundle
DEBUG [framework.browserify]: adding test/bSpec.js to bundle
DEBUG [framework.browserify]: adding test/externalSpec.js to bundle
DEBUG [framework.browserify]: adding test/failingSpec.js to bundle
DEBUG [framework.browserify]: bundling
INFO [framework.browserify]: 5424 bytes written (0.34 seconds)
INFO [framework.browserify]: bundle built
DEBUG [watcher]: Resolved files:
    /Users/joe/dev/play/karma-browserify/example/node_modules/karma-jasmine/lib/jasmine.js
    /Users/joe/dev/play/karma-browserify/example/node_modules/karma-jasmine/lib/adapter.js
    /Users/joe/dev/play/karma-browserify/example/vendor/external.js
    /var/folders/99/490t3s6x7r573sb3d1grb1_c0000gn/T/652a5c663eb0ac2b3e30ad5c86d7ccbaefc6819f.browserify
    /Users/joe/dev/play/karma-browserify/example/lib/a.js
    /Users/joe/dev/play/karma-browserify/example/test/bSpec.js
    /Users/joe/dev/play/karma-browserify/example/test/externalSpec.js
    /Users/joe/dev/play/karma-browserify/example/test/failingSpec.js
DEBUG [web-server]: serving: /Users/joe/dev/play/karma-browserify/example/node_modules/karma/static/client.html
DEBUG [web-server]: serving: /Users/joe/dev/play/karma-browserify/example/node_modules/karma/static/karma.js
DEBUG [web-server]: upgrade /socket.io/1/websocket/pNUrWMbdmDhKqkdp570o
DEBUG [karma]: A browser has connected on socket pNUrWMbdmDhKqkdp570o
INFO [PhantomJS 1.9.8 (Mac OS X)]: Connected on socket pNUrWMbdmDhKqkdp570o with id 21387361
DEBUG [launcher]: PhantomJS (id 21387361) captured in 2.112 secs
DEBUG [web-server]: serving: /Users/joe/dev/play/karma-browserify/example/node_modules/karma/static/context.html
DEBUG [web-server]: serving (cached): /Users/joe/dev/play/karma-browserify/example/node_modules/karma-jasmine/lib/jasmine.js
DEBUG [web-server]: serving (cached): /Users/joe/dev/play/karma-browserify/example/node_modules/karma-jasmine/lib/adapter.js
DEBUG [web-server]: serving (cached): /Users/joe/dev/play/karma-browserify/example/test/failingSpec.js
DEBUG [web-server]: serving (cached): /Users/joe/dev/play/karma-browserify/example/test/externalSpec.js
DEBUG [web-server]: serving (cached): /Users/joe/dev/play/karma-browserify/example/vendor/external.js
DEBUG [web-server]: serving (cached): /var/folders/99/490t3s6x7r573sb3d1grb1_c0000gn/T/652a5c663eb0ac2b3e30ad5c86d7ccbaefc6819f.browserify
DEBUG [web-server]: serving (cached): /Users/joe/dev/play/karma-browserify/example/lib/a.js
DEBUG [web-server]: serving (cached): /Users/joe/dev/play/karma-browserify/example/test/bSpec.js
PhantomJS 1.9.8 (Mac OS X) ERROR
  Error: Cannot find module '/Users/joe/dev/play/karma-browserify/example/lib/a.js'
  at /var/folders/99/490t3s6x7r573sb3d1grb1_c0000gn/T/652a5c663eb0ac2b3e30ad5c86d7ccbaefc6819f.browserify:1:0 <- node_modules/karma-browserify/node_modules/browserify/node_modules/browser-pack/_prelude.js:1:0
PhantomJS 1.9.8 (Mac OS X): Executed 0 of 0๏ฟฝ ERROR๏ฟฝ (0.029 secs / 0 secs)
DEBUG [karma]: Run complete, exiting.
DEBUG [launcher]: Disconnecting all browsers
DEBUG [framework.browserify]: ๏ฟฝ[39mcleaning up
DEBUG [launcher]: Process PhantomJS exited with code 0
DEBUG [temp-dir]: Cleaning temp dir /var/folders/99/490t3s6x7r573sb3d1grb1_c0000gn/T/karma-21387361

Inside the /Users/joe/dev/play/karma-browserify/example/lib/a.js we just have

module.exports = 'A'

If I remove the reference to a.js in the files section of the Karma conf then it works fine.

karma-bro + coverage?

Just wondering if anyone has figured out a way to do code coverage with karma-bro.

Thank you!

Thank you for this.

It took me some time to find this one, that actually works.

debug: true not working

I'm attempting to debug some unit tests that are being compiled/resourced using karma-bro

here's the config:

options:
  files : [
    'test/**/*Spec.coffee'
  ]
  preprocessors:
    'test/**/*Spec.coffee': ['browserify', 'sourcemap']
  frameworks: ['browserify', 'jasmine']
  basePath: ''
  browsers: ['PhantomJS']
  port: 9876
  colors: true
  autoWatch: false
  captureTimeout: 60000
  browserNoActivityTimeout: 60000
  singleRun: false
  logLevel: 'DEBUG'
  browserify:
    extensions: ['.coffee']
    transform: ['coffeeify', 'brfs', 'browserify-istanbul']
    debug: true
  coverageReporter:
    reporters: [
      {type: 'text-summary'}
    ]
once:
  singleRun: true
  reporters: ['dots', 'progress', 'coverage']
dev:
  # Works with grunt-contrib-watch, which should
  # trigger karma:dev:run on 'watch', and the karma
  # task should be started with 'karma:dev:start'
  background: true 
  reporters: ['dots', 'coverage']
  autoWatch: true

note the browserify: debug: true setting (which the docs lead me to believe should result in the generation of sourcemaps for my code)

the sourcemaps are getting generated, but appear to be minified..... wtf?

what's wrong?

Uncaught Error: Cannot find module

Hello,

I am trying to set up karma + browserify for my boilerplate project, but i get strange error.

I managed to set up browserify with gulp without any problem, it works and compiles everything like it should, but with this i get the problem.

It's a big report, but I want to show how confusing it is.

โ˜  /var/www/boilerplate/assets/js/tests [gulp-browserify] โšก  karma start karmaconf.js 
DEBUG [plugin]: Loading karma-* from /var/www/boilerplate/assets/js/tests/node_modules
DEBUG [plugin]: Loading plugin /var/www/boilerplate/assets/js/tests/node_modules/karma-browserify.
DEBUG [plugin]: Loading plugin /var/www/boilerplate/assets/js/tests/node_modules/karma-chrome-launcher.
DEBUG [plugin]: Loading plugin /var/www/boilerplate/assets/js/tests/node_modules/karma-growl-notifications-reporter.
DEBUG [plugin]: Loading plugin /var/www/boilerplate/assets/js/tests/node_modules/karma-jasmine.
DEBUG [plugin]: Loading plugin /var/www/boilerplate/assets/js/tests/node_modules/karma-jasmine-html-reporter.
DEBUG [plugin]: Loading plugin /var/www/boilerplate/assets/js/tests/node_modules/karma-sinon.
DEBUG [plugin]: Loading plugin /var/www/boilerplate/assets/js/tests/node_modules/karma-spec-reporter.
DEBUG [framework.browserify]: created browserify bundle: /tmp/e23abc7c0b33cd65128e2f9d77ad57525fd1fdbe.browserify
INFO [framework.browserify]: registering rebuild (autoWatch=true)
DEBUG [framework.browserify]: add bundle to config.files at position 3
INFO [karma]: Karma v0.12.24 server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
DEBUG [temp-dir]: Creating temp dir at /tmp/karma-91928800
DEBUG [launcher]: google-chrome --user-data-dir=/tmp/karma-91928800 --no-default-browser-check --no-first-run --disable-default-apps --disable-popup-blocking --disable-translate http://localhost:9876/?id=91928800
WARN [watcher]: Pattern "/var/www/boilerplate/assets/js/collections/**/*.js" does not match any file.
WARN [watcher]: Pattern "/var/www/boilerplate/assets/js/libs/**/*.js" does not match any file.
WARN [watcher]: Pattern "/var/www/boilerplate/assets/js/tests/collections/**/*.js" does not match any file.
WARN [watcher]: Pattern "/var/www/boilerplate/assets/js/tests/models/**/*.js" does not match any file.
DEBUG [framework.browserify]: building bundle
DEBUG [framework.browserify]: adding ../views/example-view.js to bundle
DEBUG [framework.browserify]: adding ../views/global.js to bundle
DEBUG [framework.browserify]: adding ../pages/home.js to bundle
DEBUG [framework.browserify]: adding ../models/example-model.js to bundle
DEBUG [framework.browserify]: adding libs/jasmine-jquery.js to bundle
DEBUG [framework.browserify]: adding pages/home.js to bundle
DEBUG [framework.browserify]: adding views/exampleViewSpec.js to bundle
DEBUG [framework.browserify]: bundling
DEBUG [web-server]: serving: /var/www/boilerplate/assets/js/tests/node_modules/karma/static/client.html
INFO [framework.browserify]: 420134 bytes written (1.07 seconds)
INFO [framework.browserify]: bundle built
DEBUG [watcher]: Resolved files:
    /var/www/boilerplate/assets/js/tests/node_modules/karma-jasmine/lib/jasmine.js
    /var/www/boilerplate/assets/js/tests/node_modules/karma-jasmine/lib/boot.js
    /var/www/boilerplate/assets/js/tests/node_modules/karma-jasmine/lib/adapter.js
    /tmp/e23abc7c0b33cd65128e2f9d77ad57525fd1fdbe.browserify
    /var/www/boilerplate/assets/js/views/example-view.js
    /var/www/boilerplate/assets/js/views/global.js
    /var/www/boilerplate/assets/js/pages/home.js
    /var/www/boilerplate/assets/js/models/example-model.js
    /var/www/boilerplate/assets/js/tests/libs/jasmine-jquery.js
    /var/www/boilerplate/assets/js/tests/pages/home.js
    /var/www/boilerplate/assets/js/tests/views/exampleViewSpec.js
DEBUG [watcher]: Watching "/tmp/e23abc7c0b33cd65128e2f9d77ad57525fd1fdbe.browserify"
DEBUG [watcher]: Watching "/var/www/boilerplate/assets/js/views"
DEBUG [watcher]: Watching "/var/www/boilerplate/assets/js/pages"
DEBUG [watcher]: Watching "/var/www/boilerplate/assets/js/collections"
DEBUG [watcher]: Watching "/var/www/boilerplate/assets/js/models"
DEBUG [watcher]: Watching "/var/www/boilerplate/assets/js/libs"
DEBUG [watcher]: Watching "/var/www/boilerplate/assets/js/tests/collections"
DEBUG [watcher]: Watching "/var/www/boilerplate/assets/js/tests/libs"
DEBUG [watcher]: Watching "/var/www/boilerplate/assets/js/tests/models"
DEBUG [watcher]: Watching "/var/www/boilerplate/assets/js/tests/pages"
DEBUG [watcher]: Watching "/var/www/boilerplate/assets/js/tests/views"
DEBUG [web-server]: serving: /var/www/boilerplate/assets/js/tests/node_modules/karma/static/karma.js
DEBUG [watcher]: Add file "/var/www/boilerplate/assets/js/views/example-view.js" ignored. Already in the list.
DEBUG [watcher]: Add file "/var/www/boilerplate/assets/js/views/global.js" ignored. Already in the list.
DEBUG [watcher]: Add file "/var/www/boilerplate/assets/js/pages/home.js" ignored. Already in the list.
DEBUG [watcher]: Add file "/var/www/boilerplate/assets/js/models/example-model.js" ignored. Already in the list.
DEBUG [watcher]: Add file "/var/www/boilerplate/assets/js/tests/libs/jasmine-jquery.js" ignored. Already in the list.
DEBUG [watcher]: Add file "/var/www/boilerplate/assets/js/tests/pages/home.js" ignored. Already in the list.
DEBUG [watcher]: Add file "/var/www/boilerplate/assets/js/tests/views/exampleViewSpec.js" ignored. Already in the list.
DEBUG [web-server]: upgrade /socket.io/1/websocket/unLhpoJxvOon0BHK53D8
DEBUG [karma]: A browser has connected on socket unLhpoJxvOon0BHK53D8
INFO [Chrome 38.0.2125 (Linux)]: Connected on socket unLhpoJxvOon0BHK53D8 with id 91928800
DEBUG [launcher]: Chrome (id 91928800) captured in 2.198 secs
DEBUG [karma]: All browsers are ready, executing
DEBUG [web-server]: serving: /var/www/boilerplate/assets/js/tests/node_modules/karma/static/context.html
DEBUG [web-server]: serving (cached): /var/www/boilerplate/assets/js/tests/node_modules/karma-jasmine/lib/jasmine.js
DEBUG [web-server]: serving (cached): /var/www/boilerplate/assets/js/tests/node_modules/karma-jasmine/lib/boot.js
DEBUG [web-server]: serving (cached): /var/www/boilerplate/assets/js/tests/node_modules/karma-jasmine/lib/adapter.js
DEBUG [web-server]: serving (cached): /tmp/e23abc7c0b33cd65128e2f9d77ad57525fd1fdbe.browserify
DEBUG [web-server]: serving (cached): /var/www/boilerplate/assets/js/views/example-view.js
DEBUG [web-server]: serving (cached): /var/www/boilerplate/assets/js/views/global.js
DEBUG [web-server]: serving (cached): /var/www/boilerplate/assets/js/pages/home.js
DEBUG [web-server]: serving (cached): /var/www/boilerplate/assets/js/models/example-model.js
DEBUG [web-server]: serving (cached): /var/www/boilerplate/assets/js/tests/libs/jasmine-jquery.js
DEBUG [web-server]: serving (cached): /var/www/boilerplate/assets/js/tests/pages/home.js
DEBUG [web-server]: serving (cached): /var/www/boilerplate/assets/js/tests/views/exampleViewSpec.js
Chrome 38.0.2125 (Linux) ERROR
  Uncaught Error: Cannot find module '/var/www/boilerplate/assets/js/views/global.js'
  at /tmp/e23abc7c0b33cd65128e2f9d77ad57525fd1fdbe.browserify:1

Chrome 38.0.2125 (Linux) ERROR
  Uncaught Error: Cannot find module '/var/www/boilerplate/assets/js/views/global.js'
  at /tmp/e23abc7c0b33cd65128e2f9d77ad57525fd1fdbe.browserify:1

Chrome 38.0.2125 (Linux) ERROR
  Uncaught Error: Cannot find module '/var/www/boilerplate/assets/js/views/global.js'
  at /tmp/e23abc7c0b33cd65128e2f9d77ad57525fd1fdbe.browserify:1

Above the errors, it shows that it found those files and that it load them, and after that it throws an error. I don't know why is this happening ?

This is content of /var/www/boilerplate/assets/js/views/global.js:

module.exports = function() {
    "use strict";
    window.jQuery = require('jquery');
    window.$ = window.jQuery;
    window.Backbone = require('backbone');
    window._ = require('underscore');
    window.Backbone.$ = window.$;
};

If you need any other info or file content, let me know and i'll provide it. Thanks.

Intermittent error: 'Uncaught ReferenceError: require is not defined'

Hi, I've got a really annoying intermittent error that I think is coming from karma-browserify. Basically, sometimes when I run Karma, everything passes, but occasionally, it seems like Browserify takes too long to run, and require is not defined by the time my tests run. Here's a sample of my console output:

15:14 wd/corkhat-squares-ui feature/listeners: grunt clean test
Running "env:default" (env) task

Running "clean:0" (clean) task
>> 1 path cleaned.

Running "clean:1" (clean) task
>> 0 paths cleaned.

Running "newer:browserify:app" (newer) task

Running "browserify:app" (browserify) task

Running "newer-postrun:browserify:app:1:/Users/erin/Projects/corkhat-squares-ui/node_modules/grunt-newer/.cache" (newer-postrun) task

Running "html2js:app" (html2js) task
Successfully converted 9 html templates to js.

Running "karma:once" (karma) task
INFO [karma]: Karma v0.12.28 server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
INFO [framework.browserify]: 711 bytes written (0.77 seconds)
INFO [framework.browserify]: bundle built
INFO [Chrome 39.0.2171 (Mac OS X 10.9.5)]: Connected on socket z_T2LshP_C0Yc5oKhepe with id 3489622
Chrome 39.0.2171 (Mac OS X 10.9.5) ERROR
  Uncaught ReferenceError: require is not defined
  at /Users/erin/Projects/corkhat-squares-ui/test/spec/coordinates/Coordinates.spec.coffee:1


INFO [framework.browserify]: 421413 bytes written (1.15 seconds)
INFO [framework.browserify]: bundle updated
Warning: Task "karma:once" failed. Use --force to continue.

Aborted due to warnings.
15:14 wd/corkhat-squares-ui feature/listeners: grunt clean test
Running "env:default" (env) task

Running "clean:0" (clean) task
>> 1 path cleaned.

Running "clean:1" (clean) task
>> 0 paths cleaned.

Running "newer:browserify:app" (newer) task

Running "browserify:app" (browserify) task

Running "newer-postrun:browserify:app:1:/Users/erin/Projects/corkhat-squares-ui/node_modules/grunt-newer/.cache" (newer-postrun) task

Running "html2js:app" (html2js) task
Successfully converted 9 html templates to js.

Running "karma:once" (karma) task
INFO [karma]: Karma v0.12.28 server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
INFO [Chrome 39.0.2171 (Mac OS X 10.9.5)]: Connected on socket urXFL-W5y90cylz8hg3k with id 17669023
INFO [framework.browserify]: 421725 bytes written (1.29 seconds)
INFO [framework.browserify]: bundle built
Chrome 39.0.2171 (Mac OS X 10.9.5): Executed 134 of 134 SUCCESS (0.163 secs / 0.076 secs)

Done, without errors.

Those are two subsequent test runs, with no code changes whatsoever. Any idea what could be causing this? Here's my Karma config:

module.exports = (config) ->
  config.set
    basePath: '..'

    files: [
      'bower_components/angular/angular.js'
      'bower_components/angular-mocks/angular-mocks.js'
      'bower_components/angular-moment/angular-moment.js'
      'bower_components/angular-route/angular-route.js'
      'bower_components/angular-touch/angular-touch.js'
      'bower_components/jssha/src/sha256.js'
      'lib/app.js'
      'test/spec/**/*.coffee'
    ]

    preprocessors:
      '**/*.coffee': ['browserify']
      'lib/app.js': ['coverage']

    browserify:
      extensions: ['.coffee']
      transform: ['coffeeify']

    autoWatch: true

    reporters: ['progress', 'coverage']

    frameworks: ['browserify', 'jasmine']

    browsers: ['Chrome']

    plugins: [
      'karma-browserify'
      'karma-chrome-launcher'
      'karma-coverage'
      'karma-jasmine'
      'karma-junit-reporter'
      'karma-phantomjs-launcher'
    ]

    junitReporter:
      outputFile: 'test_out/unit.xml'
      suite: 'unit'

and my Gruntfile:

module.exports = (grunt) ->
  grunt.initConfig
    env:
      default:
        push:
          PATH:
            value: './node_modules/.bin'
            delimiter: ':'

    browserify:
      app:
        files: 'lib/app.js': ['src/coffee/**/*.coffee']
        options:
          transform: ['coffeeify']
          browserifyOptions:
            extensions: ['.coffee']

    html2js:
      options:
        jade:
          doctype: 'html'
      app:
        options:
          rename: (name) -> name.replace /\.[^\.]+$/, ''
        src: ['src/templates/*/**/*.html', 'src/templates/*/**/*.jade']
        dest: 'lib/templates.js'

    uglify:
      app:
        options:
          sourceMap: true
        files:
          'app/app.js': [
            'bower_components/angular/angular.js'
            'bower_components/angular-moment/angular-moment.js'
            'bower_components/angular-route/angular-route.js'
            'bower_components/angular-touch/angular-touch.js'
            'bower_components/jssha/src/sha256.js'
            'lib/app.js'
            'lib/templates.js'
          ]

    less:
      app:
        files:
          'lib/imports.css': 'src/less/imports.less'
          'lib/bootstrap.css': 'src/less/bootstrap.less'
          'lib/app.css': 'src/less/app.less'

    autoprefixer:
      app:
        files:
          'lib/app-prefixed.css': 'lib/app.css'

    cssmin:
      app:
        files:
          'app/app.css': [
            'lib/imports.css'
            'lib/bootstrap.css'
            'lib/app-prefixed.css'
          ]

    jade:
      app:
        files:
          'app/index.html': 'src/jade/index.jade'

    copy:
      app:
        cwd: 'src/static'
        src: ['**/*']
        dest: 'app'
        expand: true
        filter: 'isFile'

    clean: ['lib', 'app']

    shell:
      'update-webdriver':
        command: 'webdriver-manager update'

    'http-server':
      dev:
        host: "0.0.0.0"
        port: 8000
        cache: -1

    karma:
      options:
        configFile: 'test/karma.conf.coffee'
      unit: {}
      once:
        singleRun: true
      ci:
        singleRun: true
        browsers: ['PhantomJS']

    protractor:
      options:
        configFile: 'test/protractor.conf.coffee'
      all: {}

  grunt.loadNpmTasks 'grunt-autoprefixer'
  grunt.loadNpmTasks 'grunt-browserify'
  grunt.loadNpmTasks 'grunt-contrib-clean'
  grunt.loadNpmTasks 'grunt-contrib-copy'
  grunt.loadNpmTasks 'grunt-contrib-cssmin'
  grunt.loadNpmTasks 'grunt-contrib-jade'
  grunt.loadNpmTasks 'grunt-contrib-less'
  grunt.loadNpmTasks 'grunt-contrib-uglify'
  grunt.loadNpmTasks 'grunt-env'
  grunt.loadNpmTasks 'grunt-html2js'
  grunt.loadNpmTasks 'grunt-http-server'
  grunt.loadNpmTasks 'grunt-karma'
  grunt.loadNpmTasks 'grunt-newer'
  grunt.loadNpmTasks 'grunt-protractor-runner'
  grunt.loadNpmTasks 'grunt-shell'

  grunt.registerTask 'build:js', ['newer:browserify:app', 'html2js:app']
  grunt.registerTask 'build', [
    'build:js'
    'uglify:app'
    'less:app'
    'autoprefixer:app'
    'cssmin:app'
    'newer:copy:app'
    'newer:jade:app'
  ]

  grunt.registerTask 'start', ['build', 'http-server']

  grunt.registerTask 'test', ['build:js', 'karma:once']
  grunt.registerTask 'test-watch', ['build:js', 'karma:unit']
  grunt.registerTask 'e2e', ['build', 'shell:update-webdriver', 'protractor']
  grunt.registerTask 't', 'test'

  grunt.registerTask 'update-webdriver', 'shell:update-webdriver'

  grunt.registerTask 'default', 'test'

  grunt.task.run 'env:default'

Apologies for the info dump!

Allow globals to be defined before pre processing

I'm currently migrating an existing codebase to use Browserify. The current code uses the revealing module pattern.

I've refactored a section of the code to use Browserify and karma-bro but I'm having trouble with a global dependency (jQuery) as one of the transient dependencies has been written to both support Browserify and our revealing modules whilst we refactor the rest.

Is there a way of including files on the page before running the pre processor?
At the moment jquery is the first thing included in the files list in karma.conf.js.

Error: Cannot find module 'reactify' from '/tmp'

Hi, I was just trying to convert from browserisfast to browserify, but there are issues.

My config file looks like this:

module.exports = function(karma) {
    var config = {
        basePath: '..',
        files: [
            'karma/test/helpers/*.js',
            {
                pattern: 'src/assets/**/*',
                watched: false,
                included: false,
                served: true
            },
        ],
        commonjsPreprocessor: {
        },
        exclude: [ ],
        frameworks: ['browserify', 'jasmine'],
        plugins: [
            'karma-jasmine',
            'karma-firefox-launcher',
            'karma-chrome-launcher',
            'karma-phantomjs-launcher',
            'karma-slimerjs-launcher',
            'karma-mocha-reporter',
            'karma-spec-reporter',
            'karma-browserify',
            'karma-junit-reporter',
        ],

        browserify: {
            debug: true,
            files: [
                'src/app/*.spec.js',
            ],
            extensions: ['.js', '.jsx', '.coffee'],
            transform: ['reactify', 'coffeeify']
        },
        preprocessors: {

            'src/app/**/*.js': ['browserify'],
            'src/app/**/*.coffee': ['browserify'],
            'src/app/**/*.jsx': ['browserify'],
            "/**/*.browserify": "browserify"
        },
        logLevel: karma.LOG_DEBUG,
        reporters: 'progress',
        port: 9018,
        runnerPort: 9100,
        urlRoot: '/',

        autoWatch: true,
        singleRun: false,
        browserNoActivityTimeout: 20000,

        browsers: [
            'Chrome',

        ],
        proxies: {
            '/assets/': 'src/assets/'
        }
    };

    karma.set(config);
};

The error I get is:

$ karma start karma/karma-unit.js 
INFO [framework.browserify]: registering rebuild (autoWatch=true)
INFO [karma]: Karma v0.12.24 server started at http://localhost:9018/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.7 (Linux)]: Connected on socket vuGdKFbwX7mS_TBqeybh with id 84936799
ERROR [framework.browserify]: bundle error
ERROR [framework.browserify]: Error: Cannot find module 'reactify' from '/tmp'
ERROR [framework.browserify]: bundle error
ERROR [framework.browserify]: Error: Cannot find module 'coffeeify' from '/tmp'
PhantomJS 1.9.7 (Linux) ERROR
  ReferenceError: Can't find variable: require
  at /tmp/2bd1920c0a2ff1940519f681493632b5eafcd0de.browserify:1

I'm a bit stumped on what could be the issue here. Any tips?

Incorrect stack trace on Windows

Hi,
Whenever there is an exception in a test or source code, karma reports the error as coming from the .browserify file, which makes it difficult to locate it. Note that i'm running browserify with the debug mode set to true and karma with PhantomJS.
Is there anyway to get the original error location ?

Getting "cannot find module" error whenever a file is changed

Hi Nikku,

When I start karma, karma-bro works fine, but as soon as I change any file, it try to browserify the file changed and then I get an error, so I need to restart karma, it seems always happens on the first require found in the file changed:

Chrome 35.0.1916 (Windows 8.1) ERROR
  Uncaught Error: Cannot find module './support/helper'
  at C:/Users/faca/AppData/Local/Temp/af189affc1bf7cdcaa535161a0b064a51acf44e3.browserify?41cff830b002b6fbe0826dc02181d33b89a4b9de:1

I just create a small project, so you can test it out and give me back your thoughts, maybe I'm doing something wrong in the configuration.

https://github.com/fcaballero/karma-bro-test

browserify 6

Another day, another browserify release ๐Ÿ˜„

Should be a much smaller API change if it affects our use at all. Will check this out tonight and make the version bump if it is indeed a one line fix.

Exposing bundles

I've been struggling the whole day over getting karma to work with browserify. I'm using broccoli-browserify to create a single js file that exposes a frontend package, like so:

var frontend = browserify('frontend/lib/src', {
    require: [
        ['./api.js', { expose: 'frontend' }]
    ],
    outputFile: '/api.js'
});

This is working quite well on the development server. I can require('frontend') just fine and everything works as expected. The karma configuration, however, has me stumped. I've tried the golden path, based on the readme:

config.set({
  frameworks: ['browserify', 'jasmine'],
  files: [
    'frontend/lib/src/api.js',
    // more files that require('frontend')
  ],
  preprocessors: {
    'frontend/lib/src/api.js': ['browserify']
  },
  browserify: {
    prebundle: function(bundle) {
      bundle.external('frontend');
    }
  }
  // ...
});

I've also tried returning the bundle, in case that had any bearing:

browserify: {
  prebundle: function(bundle) {
    return bundle.external('frontend');
  }
}

And I've tried to mimic what I was doing with broccoli in this way:

browserify: {
  prebundle: function(bundle) {
    return bundle.require('./frontend/lib/src/api.js', { expose: 'frontend' });
  }
}

Of course, I wouldn't be here if any of these worked. The error is always the same:

Error: Cannot find module 'frontend'

I'm hoping someone can show me the error in my ways and that there is, actually, a solution to this problem.

I'd be happy to submit a PR with a readme or doc update to address this very scenario, once it's solved.

Announcement: karma-bro* are becoming one!

Wanted to share some exciting news with everyone!

We've coordinated with @xdissent and @alexgorbatchev of karma-browserify and @cjohansen of karma-browserifast. I've also just reached out to @afbobak of karma-browserify-preprocessor which I believe should cover all the karma-bro* packages. Here's what will be happening:

  • All existing versions of all projects will be deprecated on npm. No existing dependencies should break.
  • Everyone but karma-bro will be replacing their README with a deprecation notice containing a link to karma-bro and disabling GitHub issues.
  • karma-bro will be renamed to karma-browserify on GitHub.
  • karma-browserify (formerly karma-bro) will be published to npm as [email protected]

Wanted to thank everyone for being super cooperative here and working towards the best outcome for users. I'll continue to reference this issue from commits and PRs as well as notify everyone when the npm publishes happen and you can update your dependencies.

Checklist

  • ensure we can publish to karma-browserify@npm
  • rename karma-bro@GitHub -> karma-browserify@GitHub
  • deprecate karma-bro@npm
  • release this library as v1.0.0 to karma-browserify@npm

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.