Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve documentation - recommend more useful default configuration #25

Merged
merged 1 commit into from
Oct 15, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 71 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,95 @@
# 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']
}
```

And tell webpack to generate sourcemaps

``` javascript
webpack: {
// ...
devtool: 'inline-source-map'
}
```

## 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);