1.0.2 • Published 8 years ago

min-karma-webpack v1.0.2

Weekly downloads
13
License
MIT
Repository
github
Last release
8 years ago

min-karma-webpack

Combines Minimal Webpack and Minimal Karma to a single Package.

js-standard-style

Karma

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

Webpack is a popular JavaScript/NodeJS Module Bundler.

Why?

  • 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

Features

  • 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:

Clone

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.

Enjoy!

1.0.2

8 years ago

1.0.1

8 years ago

0.3.1

8 years ago

0.2.5

8 years ago

0.2.4

8 years ago

0.2.3

8 years ago

0.2.2

8 years ago

0.2.1

8 years ago

0.1.4

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago