Skip to content

Commit

Permalink
Improve documentation - recommend more useful default configuration
Browse files Browse the repository at this point in the history
- add installation instructions
- mention sourcemaps
- separate optional options from the recommended configuration
- update the example tests to use the new defaults in example dir
  • Loading branch information
KidkArolis committed Sep 11, 2014
1 parent 1797ae6 commit 35a402a
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 25 deletions.
78 changes: 62 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,86 @@
# karma-webpack

## Installation

``` sh
npm install --save-dev karma-webpack
```

## Usage

``` javascript
// Karma configuration

module.exports = function(config) {
config.set({
// ... normal karma configuration

files: [
// only specify one entry point
// and require all tests in there
'test/test_index.js'
],

// add webpack as preprocessor
preprocessors: {
'test/*Test.js': ['webpack']
'test/test_index.js': ['webpack']
},

webpack: {
cache: true,
// webpack configuration
// karma watches test/test_index.js
// webpack watches dependencies of test/test_index.js
watch: true
},

webpackServer: {
// webpack-dev-server configuration
// webpack-dev-middleware configuration
},

// the port used by the webpack-dev-server
// defaults to "config.port" + 1
webpackPort: 1234,

plugins: [
require("karma-webpack")
]
noInfo: true
}

});
};
```

Every test file is compiled with webpack and the resulting bundle is served.
``` javascript
// test/test_index.js

// require all modules ending in _test from the
// current directory and all subdirectories
var testsContext = require.context(".", true, /_test$/);
testsContext.keys().forEach(testsContext);
```

Every test file is required using the [require.context](http://webpack.github.io/docs/context.html#require-context) and compiled with webpack into one test bundle.

## Source Maps

You can use the `karma-sourcemap-loader` to get the source maps generated for your test bundle.

```
npm install --save-dev karma-sourcemap-loader
```

And then add it to your preprocessors

``` javascript
preprocessors: {
'test/test_index.js': ['webpack', 'sourcemap']
}
```

## Options

This is the full list of options you can specify in your Karma config.

### webpack

Webpack configuration.

### webpackServer

Configuration for webpack-dev-server and webpack-dev-middleware.

### webpackPort

Port used by the webpack-dev-server. Defaults to "karmaConfig.port" + 1.

## License

Expand Down
14 changes: 5 additions & 9 deletions example/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,18 @@ module.exports = function(config) {

// list of files / patterns to load in the browser
files: [
'test/*Test.*'
],


// list of files to exclude
exclude: [

'test/index.js'
],


// list of preprocessors
preprocessors: {
'test/*Test.*': ['webpack']
'test/index.js': ['webpack']
},


webpack: {
cache: true,
watch: true,
module: {
loaders: [
{ test: /\.coffee$/, loader: "coffee-loader" }
Expand Down Expand Up @@ -88,6 +82,8 @@ module.exports = function(config) {
singleRun: false,


// List plugins explicitly, since autoloading karma-webpack
// won't work here
plugins: [
require("karma-mocha"),
require("karma-chrome-launcher"),
Expand Down
2 changes: 2 additions & 0 deletions example/test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
var testsContext = require.context(".", true, /Test$/);
testsContext.keys().forEach(testsContext);

0 comments on commit 35a402a

Please sign in to comment.