Skip to content

Commit

Permalink
Added command line arguments from running PhantomJS for karma tests.
Browse files Browse the repository at this point in the history
Also fixed karma-chrome-launcher bug windows 8.1
  • Loading branch information
atruskie committed Nov 12, 2013
1 parent 49abcce commit d5ba2d4
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 50 deletions.
9 changes: 9 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ module.exports = function (grunt) {
/**
* Process the build option.
*/
var usePhantomJsTestRunner = grunt.option('use-phantomjs') === true;
grunt.log.writeln("Test runner should use " + (usePhantomJsTestRunner ? "PhantomJS" : "Chrome"));
userConfig.usePhantomJs = usePhantomJsTestRunner;




var development = grunt.option('development') === true,
staging = grunt.option('staging') === true,
production = grunt.option('production') === true,
Expand Down Expand Up @@ -867,11 +874,13 @@ module.exports = function (grunt) {
*/
grunt.registerMultiTask('karmaconfig', 'Process karma config templates', function () {
var jsFiles = filterForJS(this.filesSrc);
var usePhantomJs = grunt.config('usePhantomJs');

grunt.file.copy('karma/karma-unit.tpl.js', grunt.config('build_dir') + '/karma-unit.js', {
process: function (contents, path) {
return grunt.template.process(contents, {
data: {
usePhantomJs: usePhantomJs,
scripts: jsFiles
}
});
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ The `grunt` runner will accept three build options that will rewrite important v

These variables are configured in `build.config.js`.

Additionally, the grunt command will accept a `--use-phantomjs` JS options which will switch the default `karma` test runner
from Chrome to PhantomJS.

---
# Licence
Apache License, Version 2.0
Expand Down
109 changes: 59 additions & 50 deletions karma/karma-unit.tpl.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
module.exports = function ( config ) {
module.exports = function (config) {

var fileJson = '[<% scripts.forEach( function ( file, index, array ) { %>"<%= file %>"<%= index == array.length - 1 ? "": ","%> <% }); %>]';



config.set({

//logLevel: config.LOG_DEBUG,

/**
* From where to look for files, starting with the location of this file.
*/
Expand All @@ -8,54 +16,55 @@ module.exports = function ( config ) {
/**
* This is the list of file patterns to load into the browser during testing.
*/
files: [
<% scripts.forEach( function ( file ) { %>'<%= file %>',
<% }); %>
files: JSON.parse(fileJson).concat([
'src/**/*.js',
'src/**/*.coffee',
],
exclude: [
'src/assets/**/*.js'
],
frameworks: [ 'jasmine' ],
plugins: [ 'karma-jasmine', 'karma-firefox-launcher', 'karma-chrome-launcher', 'karma-phantomjs-launcher', 'karma-coffee-preprocessor' ],
preprocessors: {
'**/*.coffee': 'coffee',
},

/**
* How to report, by default.
*/
reporters: 'dots',

/**
* On which port should the browser connect, on which port is the test runner
* operating, and what is the URL path for the browser to use.
*/
port: 9018,
runnerPort: 9100,
urlRoot: '/',

/**
* Disable file watching by default.
*/
autoWatch: false,

/**
* The list of browsers to launch to test on. This includes only "Firefox" by
* default, but other browser names include:
* Chrome, ChromeCanary, Firefox, Opera, Safari, PhantomJS
*
* Note that you can also use the executable name of the browser, like "chromium"
* or "firefox", but that these vary based on your operating system.
*
* You may also leave this blank and manually navigate your browser to
* http://localhost:9018/ when you're running tests. The window/tab can be left
* open and the tests will automatically occur there during the build. This has
* the aesthetic advantage of not launching a browser every time you save.
*/
/* browsers: [
'Chrome'
]*/
});
'src/**/*.coffee'
]),
exclude: [
'src/assets/**/*.js'
],
frameworks: [ 'jasmine' ],
plugins: [ 'karma-jasmine', 'karma-firefox-launcher',
/*'karma-chrome-launcher',*/
require('../node_modules/karma-chrome-launcher'),
'karma-phantomjs-launcher', 'karma-coffee-preprocessor' ],
preprocessors: {
'**/*.coffee': 'coffee'
},

/**
* How to report, by default.
*/
reporters: 'dots',

/**
* On which port should the browser connect, on which port is the test runner
* operating, and what is the URL path for the browser to use.
*/
port: 9018,
runnerPort: 9100,
urlRoot: '/',

/**
* Disable file watching by default.
*/
autoWatch: false,

/**
* The list of browsers to launch to test on. This includes only "Firefox" by
* default, but other browser names include:
* Chrome, ChromeCanary, Firefox, Opera, Safari, PhantomJS
*
* Note that you can also use the executable name of the browser, like "chromium"
* or "firefox", but that these vary based on your operating system.
*
* You may also leave this blank and manually navigate your browser to
* http://localhost:9018/ when you're running tests. The window/tab can be left
* open and the tests will automatically occur there during the build. This has
* the aesthetic advantage of not launching a browser every time you save.
*/
browsers: [
"<%= usePhantomJs ? 'PhantomJS' : 'Chrome' %>"
]
});
};
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"type": "git",
"url": "https://github.com/QutBioacoustics/baw-client.git"
},
"//": "THE karma-chrome-launcher IS NEEDED TO LAUCH CHROME PROPERLY ON WINDOWS. REMOVE WHEN PULL REQUEST COMPLETED https://github.com/karma-runner/karma-chrome-launcher",
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-clean": "~0.4.1",
Expand All @@ -21,6 +22,7 @@
"grunt-contrib-watch": "~0.4.0",
"grunt-contrib-uglify": "~0.2.0",
"grunt-karma": "~0.7.0",
"karma-chrome-launcher": "https://github.com/EE/karma-chrome-launcher/tarball/windows",
"grunt-ngmin": "0.0.2",
"grunt-html2js": "~0.1.3",
"grunt-contrib-coffee": "~0.7.0",
Expand Down

0 comments on commit d5ba2d4

Please sign in to comment.