min-karma-webpack
Combines Minimal Webpack and Minimal Karma to a single Package.
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
- You have a project and want to add unit/integration/whatever tests — install the package.
- You want to quickly evaluate Karma runner and play with in a clean folder — clone or download the repository.
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.
demo
folder
Basic testing demo — inside // add-module.js // export function as modulemodule { return a + b} // import our module for testingvar add =
Tip. Keep your tests next to their testees for better cohesion. Avoid putting them into separate folders (like tests
) away from your code.
Enjoy!