Installation
This boilerplate package will let you use karma
in your projects.
Use npm install webpack-karma-jasmine
instead of installing all dependencies and loaders separately.
If you want to test your
.html
files with DOM see karma-html package.
This package is the suggestion of karma configuration. It uses:
karma-webpack
andbabel-loader
to compile ES2015 javascript features and bundle specs and tests.js
files togetherkarma-jasmine
(to use another framework, install it manually)karma-mocha-reporter
bash reporterkarma-jasmine-html-reporter
browser reporter
Sample
git clone https://github.com/devrafalko/webpack-karma-jasmine.git
cd webpack-karma-jasmine/sample
npm install
npm test
Configuration
This is the full description of the sample above.
1. Install all dependencies
npm install webpack webpack-cli webpack-karma-jasmine
karma.conf.js
file
2. create The suggestion of karma.conf.js
configuration
module { config;};
3. adjust the folders structure to your needs
- Adjust
basePath
andexcludes
property,files
pattern
properties, andpreprocessors
properties to your need. - The configuration assumes that the following folder structure is arranged in the following way:
┌ karma.conf.js
├ package.json
├ webpack.config.js
├ src
│ ├ index.js
│ └ another_module.js
└ tests
├ spec_a.js
└ spec_b.js
4. Add some specs to your test files
tests/spec_a.js
; ;
src/index.js
10;
5. Run tests:
- add
"scripts": { "test": "karma start" }
to yourpackage.json
and run tests withnpm test
- or run
karma start
in the terminal (but first installkarma-cli
globally)
> npm install karma-cli -g
Links
- karma configuration file docs
- karma files docs
- webpack-babel-installer
- babel presets docs
- babel-loader
- karma-webpack (webpack docs)
- karma-webpack (github docs)
- jasmine docs
- karma-jasmine docs
Launchers
- karma-phantomjs-launcher
- karma-chrome-launcher
- karma-firefox-launcher
- karma-edge-launcher
- karma-ie-launcher
- karma-opera-launcher
- karma-safari-launcher
Reporters
See also
- karma-html (test your
.html
files in the browser) - jasmine-dom-custom-matchers
- webpack-jquery-ui
- webpack-icons-installer
- styles-loader