Skip to content

Instantly share code, notes, and snippets.

@clowestab
Last active August 3, 2017 21:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clowestab/f431078b317d27e6dcebf1a4ef0989bd to your computer and use it in GitHub Desktop.
Save clowestab/f431078b317d27e6dcebf1a4ef0989bd to your computer and use it in GitHub Desktop.
var page = require("webpage").create();
var args = require('system').args;
//pass in the name of the file that contains your tests
var testFile = args[1];
//pass in the url you are testing
var pageAddress = args[2];
if (typeof testFile === 'undefined') {
console.error("Did not specify a test file");
phantom.exit();
}
page.open(pageAddress, function(status) {
if (status !== 'success') {
console.error("Failed to open", page.frameUrl);
phantom.exit();
}
//Inject mocha and chai
page.injectJs("../node_modules/mocha/mocha.js");
page.injectJs("../node_modules/chai/chai.js");
//inject your test reporter
page.injectJs("mocha/reporter.js");
//inject your tests
page.injectJs("mocha/" + testFile);
page.evaluate(function() {
window.mocha.run();
});
});
page.onCallback = function(data) {
data.message && console.log(data.message);
data.exit && phantom.exit();
};
page.onConsoleMessage = function(msg, lineNum, sourceId) {
console.log('CONSOLE: ' + msg + ' (from line #' + lineNum + ' in "' + sourceId + '")');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment