The main goal for Karma is to bring a productive testing environment to developers. The environment being one where they don`t have to set up loads of configurations, but rather a place where developers can just write the code and get instant feedback from their tests. Because getting quick feedback is what makes you productive and creative.
npm install -g karma-cli
npm install karma # Install Karma
karma init # Create configuration file
npm install karma-mocha # Testing framework
npm install karma-expect # Assertion lib
npm install karma-phantomjs-launcher # Browser
karma start
INFO [karma]: Karma v0.12.0 server started at http://localhost:9876/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.7 (Linux)]: Connected on socket M64_IXz with id 98199717
PhantomJS 1.9.7 (Linux): Executed 1 of 1 SUCCESS (0.011 secs / 0.003 secs)
module.exports = function(config) {
config.set({
frameworks: ['mocha', 'expect'],
files: ['test/**/*.js'],
autoWatch: false,
singleRun: true,
browsers: ['PhantomJS']
});
}
karma start --single-run=false --auto-watch=true
...
PhantomJS 1.9.7 (Linux): Executed 1 of 1 SUCCESS (0.038 secs / 0.005 secs)
INFO [watcher]: Changed file "/tmp/karma/test/foo_spec.js".
PhantomJS 1.9.7 (Linux): Executed 2 of 2 SUCCESS (0.037 secs / 0.006 secs)
...
➜ Изменил файл ➜ Тесты ➜ Изменил файл ➜ Тесты ... ➜
module.exports = function(config) {
config.set({
files: ['src/**/*.js', 'test/*.coffee', 'lib/*.dart'],
preprocessors: {
'**/*.js': ['borschik'],
'**/*.coffee': ['coffee'],
'**/*.dart': ['dart']
}
});
}
Просто зайдите на host где запущен karma-server
Karma v0.12.0 server started at http://localhost:9876/
...
PhantomJS 1.9.7 (Linux): Executed 2 of 2 SUCCESS (0.03 secs / 0.009 secs)
Chromium 31.0.1650 (Ubuntu): Executed 2 of 2 SUCCESS (0.27 secs / 0.009 secs)
TOTAL: 4 SUCCESS
http://localhost:9876/debug.html
Максим Рыжиков, Yandex