Created
August 8, 2014 22:29
-
-
Save dtolb/233a6c5dd3f0835ec65d to your computer and use it in GitHub Desktop.
grunt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
path = require("path"); | |
module.exports = function (grunt) { | |
function runTests (browser, done) { | |
var bin = path.join(__dirname, "bin"); | |
var environment = Object.create(process.env); | |
var options = { | |
cmd : "mocha", | |
args : [ "--reporter", "spec", "--timeout", "30000", "specs/*.js" ], | |
opts : { stdio : "inherit" } | |
}; | |
function checkResult (error) { | |
if (error) { | |
grunt.fail.fatal("Some tests failed."); | |
} | |
else { | |
grunt.log.ok("All tests passed."); | |
} | |
done(); | |
} | |
// Configure environment for child process. | |
environment.BROWSER = browser; | |
environment.PATH = environment.PATH.split(path.delimiter).concat(bin).join(path.delimiter); | |
options.opts.env = environment; | |
grunt.util.spawn(options, checkResult); | |
} | |
grunt.initConfig({ | |
jshint : { | |
options : { | |
bitwise : true, | |
camelcase : true, | |
curly : true, | |
eqeqeq : true, | |
es3 : false, | |
forin : false, | |
immed : true, | |
indent : 4, | |
latedef : true, | |
newcap : true, | |
noarg : true, | |
noempty : true, | |
nonew : true, | |
plusplus : true, | |
quotmark : "double", | |
undef : true, | |
unused : true, | |
strict : false, | |
trailing : true, | |
maxparams : 3, | |
maxdepth : 3, | |
maxstatements : false, | |
maxlen : 120, | |
expr : true, | |
globals : { | |
after : false, | |
before : false, | |
afterEach : false, | |
beforeEach : false, | |
describe : false, | |
it : false | |
}, | |
node : true, | |
ignores : [ "node_modules/**/*.js" ] | |
}, | |
src : "**/*.js" | |
} | |
}); | |
grunt.loadNpmTasks("grunt-contrib-jshint"); | |
grunt.registerTask("chrome", "Run the UI tests in Chrome.", [ "chrome-driver", "chrome-test" ]); | |
grunt.registerTask("chrome-driver", "Download the appropriate Chrome driver.", function () { | |
var done = this.async(); | |
var options = { | |
cmd : "lib/prepare-chrome.sh", | |
args : [], | |
opts : { stdio : "inherit" } | |
}; | |
function checkResult (error) { | |
if (error) { | |
grunt.fail.fatal("Failed to setup the Chrome driver."); | |
} | |
else { | |
grunt.log.ok("Successfully setup the Chrome driver."); | |
} | |
done(); | |
} | |
grunt.util.spawn(options, checkResult); | |
}); | |
grunt.registerTask("chrome-test", "Execute the test cases in Chrome.", function () { | |
var done = this.async(); | |
runTests("chrome", done); | |
}); | |
grunt.registerTask("default", [ "lint", "test" ]); | |
grunt.registerTask("firefox", "Run the UI tests in Firefox.", function () { | |
var done = this.async(); | |
runTests("firefox", done); | |
}); | |
grunt.registerTask("lint", "Check for common code problems.", [ "jshint" ]); | |
grunt.registerTask("test", "Run the test suite on all browsers.", [ "chrome", "firefox" ]); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment