Minimal Karma-Webpack setup

the proposed configuration is too old by now
Last updated 4 years ago by dmitriz .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install min-karma-webpack 
SYNC missed versions from official npm registry.


Combines Minimal Webpack and Minimal Karma to a single Package.



Karma is a JavaScript Test Runner, one of the most popular and friendliest for beginners. The most notable advantage of Karma is testing in real browsers. See my StackOverflow answer for more information about Karma usage.


Webpack is a popular JavaScript/NodeJS Module Bundler.


  • Most setups are bloated with unnecessary options.
  • Start clean and minimal and extend as you go.
  • Add single package to your project instead of many, to get your tests up and running.

But I already run NodeJS! Why do I need Webpack to load my modules just to test them?

Karma runs your tests as separate JavaScript files in real browsers that don't natively support modules. So you need a bundler like Webpack (or Browserify) to pre-process your modules beforehand. This is achieved by the excellent preprocessor support from Karma

But what if I only need my modules to run with NodeJS?

You may want to re-use some of your modules later in web applications. By running your tests in real browsers now you make them future-proof.

Use cases


  • No webpack config file needed for testing! (You still get one as bonus. ;-)
  • Minimal functional Karma config file.
  • Minimal testing example.

If you are new to Node

Download and Install Node.js, see How do I get started with Node.js for more information.

To use as separate Repository:


git clone https://github.com/dmitriz/min-karma-webpack

or simply Download this Repository, unzip it and cd min-karma-webpack-master.

Install dependencies

npm install

To use as Package (add to your project):

In your main project directory (should contain package.json):

npm install min-karma-webpack --save

Getting started

Run your tests:

karma start

Now try to edit files inside demo folder and see how karma is watching and updating your test results.

Basic testing demo — inside demo folder

// add-module.js

// export function as module
module.exports = function add (a, b) {
  return a + b

// import our module for testing
var add = require('./add-module.js')

describe('Addition', function () {
  it('should add numbers', function () {
    expect(add(2, 4)).toBe(6)
    expect(add(2, 4)).not.toBe(2)

Tip. Keep your tests next to their testees for better cohesion. Avoid putting them into separate folders (like tests) away from your code.


Current Tags

  • 1.0.2                                ...           latest (4 years ago)

12 Versions

  • 1.0.2 [deprecated]           ...           4 years ago
  • 1.0.1 [deprecated]           ...           4 years ago
  • 0.3.1 [deprecated]           ...           4 years ago
  • 0.2.5 [deprecated]           ...           4 years ago
  • 0.2.4 [deprecated]           ...           4 years ago
  • 0.2.3 [deprecated]           ...           4 years ago
  • 0.2.2 [deprecated]           ...           4 years ago
  • 0.2.1 [deprecated]           ...           4 years ago
  • 0.1.4 [deprecated]           ...           4 years ago
  • 0.1.3 [deprecated]           ...           4 years ago
  • 0.1.2 [deprecated]           ...           4 years ago
  • 0.1.1 [deprecated]           ...           4 years ago
Maintainers (1)
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (4)
Dev Dependencies (0)
Dependents (0)

Copyright 2014 - 2017 © taobao.org |