Ponelat
Ponelat

Reputation: 116

How to ignore modules from the karma config file with browserify

I'm trying to test React.js with testdom, which requires jsdom. I'm using karma with browserify. jsdom cannot be browserified, so I'd like to ignore it.

The problem I have is trying to do this from within the karma.config.js file.

browserify: {
    debug: true,
    transform: [
      "babelify"
    ],
    ignore: [] or {} or...???
  },

Upvotes: 1

Views: 1132

Answers (2)

Ponelat
Ponelat

Reputation: 116

Thanks @marcel for the answer. I'm not sure why it failed to work in my case (using exclude and ignore) But I managed to get what I needed from this...

browserify: { debug: true, transform: [ "babelify" ], configure: function(bundle) { bundle.on('prebundle', function() { bundle.ignore('jsdom'); }); } }

Which you might have guessed, registers a callback for 'prebundle', where you can configure the bundle. From the karma-browserify docs: https://github.com/Nikku/karma-browserify#additional-bundle-configuration

Not the cleanest, but it worked. I've since dropped my need for testdom/jsdom.

Upvotes: 3

marcel
marcel

Reputation: 3149

Try this:

browserify: {
    debug: true,
    transform: [
        "babelify"
    ],
    exclude: [
        "jsdom"
    ]
},

exclude will omit the files from the output bundle. You could also try ignore: that would replace the files with empty stubs.

Upvotes: 0

Related Questions