Skip to content

Commit

Permalink
chore(docs) Update README and change to match template from html5-loader
Browse files Browse the repository at this point in the history
  • Loading branch information
MikaAK committed Jul 26, 2016
1 parent d67732d commit 1b3a4e0
Showing 1 changed file with 156 additions and 72 deletions.
228 changes: 156 additions & 72 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,77 +1,101 @@
# karma-webpack

## Installation

``` sh
npm install --save-dev karma-webpack
[npm]: https://img.shields.io/npm/v/karma-webpack.svg
[npm-url]: https://npmjs.com/package/karma-webpack

[deps]: https://david-dm.org/webpack/karma-webpack.svg
[deps-url]: https://david-dm.org/webpack/karma-webpack

[chat]: https://img.shields.io/badge/gitter-webpack%2Fwebpack-brightgreen.svg
[chat-url]: https://gitter.im/webpack/webpack

[test]: http://img.shields.io/travis/webpack/karma-webpack.svg
[test-url]: https://travis-ci.org/webpack/karma-webpack

[cover]: https://codecov.io/gh/webpack/karma-webpack/branch/master/graph/badge.svg
[cover-url]: https://codecov.io/gh/webpack/karma-webpack

[![npm][npm]][npm-url]
[![deps][deps]][deps-url]
[![test][test]][test-url]
[![coverage][cover]][cover-url]
[![chat][chat]][chat-url]

<div align="center">
<a href='https://github.com/karma-runner/karma'>
<img width="200" height="200" vspace="20" hspace="25"
src="https://worldvectorlogo.com/logos/karma.svg">
</a>
<a href="https://github.com/webpack/webpack">
<img width="200" height="200" vspace="40" hspace="25"
src="https://worldvectorlogo.com/logos/webpack.svg">
</a>
<h1>Karma Webpack</h1>
<p>Use webpack to preprocess files in karma<p>
</div>

<h2 align="center">Install</h2>

```bash
npm i -D karma-webpack
```

## Usage
<h2 align="center">Usage</h2>

``` javascript
// Karma configuration

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

files: [
// all files ending in "_test"
'test/*_test.js',
'test/**/*_test.js'
// each file acts as entry point for the webpack configuration
],

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

webpack: {
// karma watches the test entry points
// (you don't need to specify the entry option)
// webpack watches dependencies

// webpack configuration
},

// optional middleware that blocks tests from running until code
// recompiles
beforeMiddleware: [
'webpackBlocker'
],

webpackMiddleware: {
// webpack-dev-middleware configuration
// i. e.
stats: 'errors-only'
},

plugins: [
require("karma-webpack")
]
});
config.set({
// ... normal karma configuration
files: [
// all files ending in "_test"
'test/*_test.js',
'test/**/*_test.js'
// each file acts as entry point for the webpack configuration
],

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

webpack: {
// karma watches the test entry points
// (you don't need to specify the entry option)
// webpack watches dependencies

// webpack configuration
},

webpackMiddleware: {
// webpack-dev-middleware configuration
// i. e.
stats: 'errors-only'
},

plugins: [
require("karma-webpack")
]
});
};
```

## Alternative usage
<h3 align="center">Alternative Usage</h3>

This configuration is more performant, but you cannot run single test anymore (only the complete suite).

The above configuration generates a webpack bundle for each test. For many testcases this can result in many big files. The alterative configuration creates a single bundle with all testcases.

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

preprocessors: {
// add webpack as preprocessor
'test/test_index.js': ['webpack']
},
files: [
// only specify one entry point
// and require all tests in there
'test/test_index.js'
],

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

``` javascript
Expand All @@ -85,7 +109,7 @@ 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
<h2 align="center">Source Maps</h2>

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

Expand All @@ -97,7 +121,7 @@ And then add it to your preprocessors

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

Expand All @@ -106,23 +130,23 @@ And tell webpack to generate sourcemaps
``` javascript
webpack: {
// ...
devtool: 'inline-source-map'
devtool: 'inline-source-map'
}
```

## Options
<h2 align="center">Options</h2>

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

### webpack
### `webpack`

Webpack configuration.

### webpackMiddleware
### `webpackMiddleware`

Configuration for webpack-dev-middleware.

### beforeMiddleware
### `beforeMiddleware`

`beforeMiddleware` is a webpack option that allows injecting middleware before
karama's own middleware are run. This loader provides a `webpackBlocker`
Expand All @@ -137,10 +161,70 @@ Without the `webpackBlocker` middleware karma will serve files from before
the code change. With the `webpackBlocker` middleware the loader will not serve
the files until the code has finished recompiling.

Note that the `beforeMiddleware` option is only supported in karma with version >1.0.

## License

Copyright 2014-2015 Tobias Koppers
***Note that the `beforeMiddleware` option is only supported in karma with version >1.0.***

<h2 align="center">Maintainers</h2>

<table>
<tbody>
<tr>
<td align="center">
<img width="150" height="150"
src="https://avatars.githubusercontent.com/u/4650931?v=3&s=150">
</br>
<a href="https://github.com/MikaAK">Mika Kalathil</a>
</td>
<td align="center">
<img width="150" height="150"
src="https://avatars.githubusercontent.com/u/8420490?v=3&s=150">
<a href="https://github.com/d3viant0ne">Joshua Wiens</a>
</td>
<td align="center">
<img width="150" height="150" src="https://avatars.githubusercontent.com/u/1919664?v=3&s=150">
<a href="https://github.com/goldhand">Will Farley</a>
</td>
<td align="center">
<img width="150" height="150"
src="https://avatars.githubusercontent.com/u/1307954?v=3&s=150">
<a href="https://github.com/DanielaValero">Daniela Valero</a>
</td>
</tr>
<tr>
<td align="center">
<img width="150" height="150"
src="https://avatars.githubusercontent.com/u/122108?v=3&s=150">
<a href="https://github.com/jon301">Jonathan Trang</a>
</td>
<td align="center">
<img width="150" height="150"
src="https://avatars.githubusercontent.com/u/3285723?v=3&s=150">
<a href="https://github.com/carlos-">Carlos Morales</a>
</td>
</tr>
<tbody>
</table>

<h2 align="center">LICENSE</h2>

> The MIT License (MIT)
> Copyright (c) 2014 - 2016 Tobias Koppers
> Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

> The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

[MIT](http://www.opensource.org/licenses/mit-license.php)

0 comments on commit 1b3a4e0

Please sign in to comment.