What is karma?
Karma is a test runner for JavaScript that runs on Node.js. It is designed to work with any testing framework and has plugins for many popular frameworks. Karma runs tests in real browsers, can watch file changes, and re-run tests during development. It is often used for unit testing and can be integrated with continuous integration tools.
What are karma's main functionalities?
Running tests in real browsers
This code configures Karma to run tests in both Chrome and Firefox browsers using the Jasmine testing framework. The 'files' property specifies the location of the test files.
module.exports = function(config) {
config.set({
browsers: ['Chrome', 'Firefox'],
frameworks: ['jasmine'],
files: ['test/**/*.js']
});
};
Watching files and re-running tests
This configuration enables Karma's file watching feature. When set to true, Karma will watch for any file changes and automatically re-run the tests, which is useful during development.
module.exports = function(config) {
config.set({
autoWatch: true,
singleRun: false
});
};
Integration with continuous integration tools
This configuration is set up for continuous integration environments. It runs the tests a single time and uses reporters to output test results, such as the JUnit reporter which outputs results in an XML format that can be consumed by CI tools.
module.exports = function(config) {
config.set({
singleRun: true,
reporters: ['progress', 'junit'],
junitReporter: {
outputFile: 'test-results.xml'
}
});
};
Other packages similar to karma
mocha
Mocha is a feature-rich JavaScript test framework running on Node.js, making asynchronous testing simple. It is often compared to Karma, but unlike Karma, Mocha does not run tests in real browsers and does not have a built-in watcher.
jest
Jest is a delightful JavaScript Testing Framework with a focus on simplicity. It works out of the box for any React project. Jest runs tests in a Node environment instead of real browsers, provides a powerful mocking library, and has a built-in test runner and assertion library.
jasmine
Jasmine is a behavior-driven development framework for testing JavaScript code. It does not require a DOM, and it has a clean, obvious syntax so that you can easily write tests. Jasmine is often used as a testing framework within Karma, but it can also be used standalone.
Karma
A simple tool that allows you to execute JavaScript code in multiple
real browsers.
The main purpose of Karma is to make your test-driven development easy,
fast, and fun.
Help and Support
For questions and support please use the mailing list or Gitter.
The issue tracker is for bug reports and feature discussions only.
When should I use Karma?
- You want to test code in real browsers.
- You want to test code in multiple browsers (desktop, mobile,
tablets, etc.).
- You want to execute your tests locally during development.
- You want to execute your tests on a continuous integration server.
- You want to execute your tests on every save.
- You love your terminal.
- You don't want your (testing) life to suck.
- You want to use Istanbul to automagically generate coverage
reports.
- You want to use RequireJS for your source files.
But I still want to use _insert testing library_
Karma is not a testing framework, nor an assertion library.
Karma just launches an HTTP server, and generates the test runner HTML file you probably already know from your favourite testing framework.
So for testing purposes you can use pretty much anything you like. There are already plugins for most of the common testing frameworks:
If you can't find an adapter for your favourite framework, don't worry and write your own.
It's not that hard and we are here to help.
Which Browsers can I use?
All the major browsers are supported, if you want to know more see the
browsers page.
Troubleshooting
See FAQ.
I want to use it. Where do I sign?
You don't need to sign anything but here are some resources to help
you to get started...
Obligatory Screencast.
Every serious project has a screencast, so here is ours. Just click
here and let the show begin.
Installation.
See installation.
Using it.
See configuration.
This is so great. I want to help.
Please, see
contributing.
Why did you create this?
Throughout the development of AngularJS, we've been using JSTD for
testing. I really think that JSTD is a great idea. Unfortunately, we
had many problems with JSTD, so we decided to write our own test
runner based on the same idea. We wanted a simple tool just for
executing JavaScript tests that is both stable and fast. That's why we
use the awesome Socket.io library and Node.js.
My boss wants a license. So where is it?
MIT License