Karma - JS Test Runner

9,678 views

Published on

Talk given at MelbJS - August 2013

Published in: Technology, Education
0 Comments
12 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
9,678
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
120
Comments
0
Likes
12
Embeds 0
No embeds

No notes for slide

Karma - JS Test Runner

  1. 1. Karma JS Test Runner Sebastiano Armeli @sebarmeli14/8/2013 - MelbJS
  2. 2. Karma JS Test Runner Sebastiano Armeli @sebarmeli
  3. 3. Karma JS Test Runner Sebastiano Armeli @sebarmeli
  4. 4. Test Framework How you write your tests
  5. 5. Test Environment Where you execute your tests
  6. 6. Test Runner How you run your test
  7. 7. What do we need from a Test Runner?
  8. 8. it (‘should be fast’)
  9. 9. it (‘should use real browsers’)
  10. 10. it (‘should be reliable’)
  11. 11. it (‘should be reliable’)
  12. 12. Karma
  13. 13. Client socket.io Client Client socket.io socket.io watcher reporter manager web server preprocessor Server
  14. 14. Client socket.io Client Client socket.io socket.io watcher reporter manager web server http http http preprocessor Server
  15. 15. Domain Specific Language (DSL) for defining tests npm install -g karma // Ready to use
  16. 16. Domain Specific Language (DSL) for defining tests npm install -g karma karma init // Create config file
  17. 17. Domain Specific Language (DSL) for defining tests npm install -g karma karma init karma start // Karma starts listening
  18. 18. Domain Specific Language (DSL) for defining tests npm install -g karma karma init karma start karma run // Karma runs the tests
  19. 19. 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, //default browsers: ['Chrome’, ‘ChromeCanary’], singleRun: false, autoWatch: true }); }
  20. 20. Plugins Browser Launchers Test Framework Reporters Preprocessors
  21. 21. karma-!refox-launcher karma-safari-launcher karma-opera-launcher karma-ie-launcher
  22. 22. Plugins Browser Launchers Test Framework Reporters Preprocessors
  23. 23. karma-jasmine karma-mocha karma-qunit karma-requirejs
  24. 24. Plugins Browser Launchers Test Framework Reporters Preprocessors
  25. 25. karma-junit-reporter karma-coverage reporters: [‘junit’], junitReporter : { outputFile: 'test-reports.xml', suite: 'My Suite' } reporters: [‘coverage’], coverageReporter: { type : 'html', dir : 'coverage/' }
  26. 26. Plugins Browser Launchers Test Framework Reporters Preprocessors
  27. 27. karma-coverage preprocessors: { './app/assets/javascripts/**/*.js': 'coverage' } preprocessors: { '**/*.handlebars': 'ember' } karma-ember-preprocessor
  28. 28. Running just one spec?
  29. 29. Running just one spec? iit(“should do something”, function(){}); ddescribe(“component”, function(){});
  30. 30. Debug http://localhost:9876/debug.html
  31. 31. Grunt-Karma karma: { ci: { configFile: 'karma.conf.js', singleRun: true, browsers: ['PhantomJS'] } }
  32. 32. Running on CI?
  33. 33. Running on CI? karma start --singleRun=true --browsers PhantomJS --reporters junit
  34. 34. Karma!

×