Skip to content

Commit

Permalink
Close GH-714: Added support for running tests with Karma.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrw95 authored and heff committed Sep 19, 2013
1 parent b2098e0 commit 13dbf23
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ npm-debug.log
sandbox/*
!sandbox/*.example

# ignore any Karma conf.js files in the test/ directory
test/*.conf.js

*.swp
*.swo

*.orig

*results.xml
*.log
10 changes: 10 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,16 @@ grunt
grunt test
```

Video.js is also configured to run tests with Karma. Karma is installed as a grunt plugin to run QUnit tests in real browsers, as opposed to simply running the tests in phantomjs, a headless browser.

To run the QUnit test suite in Karma, do the following:
1. Copy test/karma.conf.js.example and rename the copy test/karma.conf.js. Please note that if you decide to name the file something other than karma.conf.js, or if you decide to change the location of your conf.js file from the test/ folder, you will need to change references to karma.conf.js in Gruntfile and .gitignore to your new file name and location, so that you don't inadvertently add your conf.js file to any of your video.js pull requests.
2. Open test/karma.conf.js in an editor, and configure the properties in it as desired. At a minimum, you'll want to add the browsers that you want to run your tests in. The karma.conf.js.example file has detailed information on usage in the file itself.
After you've configured the desired properties in your karma.conf.js, run:
```bash
grunt karma:dev
```

At this point you should have a built copy of video.js in a directory named `dist`, and all tests should be passing.

### Making Changes
Expand Down
14 changes: 14 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,19 @@ module.exports = function(grunt) {
'build/files/video-js.css': 'src/css/video-js.less'
}
}
},
karma: {
options: {
configFile: 'test/karma.conf.js'
},
dev: {
configFile: 'test/karma.conf.js',
autoWatch: true
},
ci: {
configFile: 'test/karma.conf.js',
autoWatch: false
}
}
});

Expand All @@ -130,6 +143,7 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-s3');
grunt.loadNpmTasks('contribflow');
grunt.loadNpmTasks('grunt-karma');

// Default task.
grunt.registerTask('default', ['jshint', 'less', 'build', 'minify', 'dist']);
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
"semver": "~1.1.4",
"grunt-contrib-cssmin": "~0.6.0",
"uglify-js": "~2.3.6",
"grunt-contrib-less": "~0.6.4"
"grunt-contrib-less": "~0.6.4",
"grunt-karma": "~0.4.4",
"karma-qunit": "~0.0.2"
},
"testling": {
"browsers": [
Expand Down
3 changes: 3 additions & 0 deletions test/karma-qunit-shim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var fixture = document.createElement('div');
fixture.id = 'qunit-fixture';
document.body.appendChild(fixture);
101 changes: 101 additions & 0 deletions test/karma.conf.js.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Karma example configuration file
// NOTE: To configure Karma tests, do the following:
// 1. Copy this file and rename the copy with a .conf.js extension, for example: karma.conf.js
// 2. Configure the properties below in your conf.js copy
// 3. Run your tests

// base path, that will be used to resolve files and exclude
basePath = '';

frameworks = ['qunit'];

// Set autoWatch to true if you plan to run `grunt karma` continuously, to automatically test changes as you make them.
autoWatch = false;

// Setting singleRun to true here will start up your specified browsers, run tests, and then shut down the browsers. Helpful to have in a CI environment, where you don't want to leave browsers running continuously.
singleRun = true;

// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
// Example usage:
// browsers = ['Chrome','Firefox','Safari'];
browsers = [];

// List of files / patterns to load in the browser
// Add any new src files to this list.
// If you add new unit tests, they will be picked up automatically by Karma,
// unless you've added them to a nested directory, in which case you should
// add their paths to this list.
files = [
'../test/karma-qunit-shim.js',
QUNIT,
QUNIT_ADAPTER,
'../src/js/core.js',
'../src/js/core-object.js',
'../src/js/events.js',
'../src/js/lib.js',
'../src/js/component.js',
'../src/js/button.js',
'../src/js/slider.js',
'../src/js/menu.js',
'../src/js/player.js',
'../src/js/control-bar/control-bar.js',
'../src/js/control-bar/play-toggle.js',
'../src/js/control-bar/time-display.js',
'../src/js/control-bar/fullscreen-toggle.js',
'../src/js/control-bar/progress-control.js',
'../src/js/control-bar/volume-control.js',
'../src/js/control-bar/mute-toggle.js',
'../src/js/control-bar/volume-menu-button.js',
'../src/js/poster.js',
'../src/js/loading-spinner.js',
'../src/js/big-play-button.js',
'../src/js/media/media.js',
'../src/js/media/html5.js',
'../src/js/media/flash.js',
'../src/js/media/loader.js',
'../src/js/tracks.js',
'../src/js/json.js',
'../src/js/setup.js',
'../src/js/plugins.js',
'../test/unit/*.js'
];

plugins = ['karma-qunit', 'karma-chrome-launcher'];

// list of files to exclude
exclude = [

];


// test results reporter to use
// possible values: 'dots', 'progress', 'junit'
reporters = ['progress'];


// web server port
port = 9876;


// cli runner port
runnerPort = 9100;


// enable / disable colors in the output (reporters and logs)
colors = true;


// level of logging
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
//logLevel = LOG_INFO;

// If browser does not capture in given timeout [ms], kill it
captureTimeout = 60000;

0 comments on commit 13dbf23

Please sign in to comment.