Talk given at MelbJS - August 2013
KarmaJS Test RunnerSebastiano Armeli@sebarmeli14/8/2013 - MelbJS
View Slide
KarmaJS Test RunnerSebastiano Armeli@sebarmeli
Test FrameworkHow you write your tests
Test EnvironmentWhere you execute your tests
Test RunnerHow you run your test
What do we need from a Test Runner?
it (‘should be fast’)
it (‘should use real browsers’)
it (‘should be reliable’)
Karma
Clientsocket.ioClientClientsocket.iosocket.iowatcherreportermanagerweb serverpreprocessorServer
Clientsocket.ioClientClientsocket.iosocket.iowatcherreportermanagerweb serverhttphttphttppreprocessorServer
Domain Specific Language (DSL) for defining testsnpm install -g karma // Ready to use
Domain Specific Language (DSL) for defining testsnpm install -g karmakarma init // Create config file
Domain Specific Language (DSL) for defining testsnpm install -g karmakarma initkarma start // Karma starts listening
Domain Specific Language (DSL) for defining testsnpm install -g karmakarma initkarma startkarma run // Karma runs the tests
module.exports = function(config) {config.set({basePath: './../..',frameworks: ['jasmine', ‘requirejs’],files: [‘spec/javascripts/test-main.js’,{pattern: 'spec/javascripts/fixtures/**/*.html', watched: false},{pattern: 'app/assets/javascripts/**/*.js'},{pattern: 'spec/javascripts/**/*.js'}],port: 9876, //defaultbrowsers: ['Chrome’, ‘ChromeCanary’],singleRun: false,autoWatch: true});}
PluginsBrowser LaunchersTest FrameworkReportersPreprocessors
karma-!refox-launcherkarma-safari-launcherkarma-opera-launcherkarma-ie-launcher
karma-jasminekarma-mochakarma-qunitkarma-requirejs
karma-junit-reporterkarma-coveragereporters: [‘junit’],junitReporter : {outputFile: 'test-reports.xml',suite: 'My Suite'}reporters: [‘coverage’],coverageReporter: {type : 'html',dir : 'coverage/'}
karma-coveragepreprocessors: {'./app/assets/javascripts/**/*.js': 'coverage'}preprocessors: {'**/*.handlebars': 'ember'}karma-ember-preprocessor
Running just onespec?
Running just onespec?iit(“should do something”, function(){});ddescribe(“component”, function(){});
Debughttp://localhost:9876/debug.html
Grunt-Karmakarma: {ci: {configFile: 'karma.conf.js',singleRun: true,browsers: ['PhantomJS']}}
Running on CI?
Running on CI?karma start --singleRun=true --browsersPhantomJS --reporters junit
Karma!