Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Structuring webpack config for use with karma testing

I would like to create a test suite which will be run with karma against my app which is using webpack to build itself. I have two entrypoints, app and vendors. These are set up through my webpack.config.js file here. The resulting bundle.js should contain both of these entrypoints in its generated file. My karma (mocha) tests residing in test/spec/*_spec.js are currently pointing to specific components, via require statements like:

var app = require('../src/scripts/App')

They also utilize react/jsx which seems to be causing problems during the test run where I get jsx errors:

Module parse failed: /Users/dmarr/src/status/test/spec/app_spec.js Line 10: Unexpected token < You may need an appropriate loader to handle this file type.

I'd like to keep test runs quick as possible as well as fast build times for testing with webpack-dev-server during development by minimizing babel transforms to only where needed.

What do I need to do in karma.conf.js to get my builds working? Here is the karma.conf.js file I'm playing around with.

Note, that I do have this working without breaking out the vendor bundle here: https://github.com/bitwise/status

Thanks for any help, Dave

like image 289
dmarr Avatar asked May 31 '15 03:05

dmarr


1 Answers

In a similar setup, disabling CommonsChunkPlugin (for testing only) worked for me. Give it a shot!

like image 143
mateatslc Avatar answered Nov 08 '22 20:11

mateatslc