Created
June 17, 2012 19:15
-
-
Save rdingwall/2945485 to your computer and use it in GitHub Desktop.
Jasmine PhantomJS event based exit
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8" /> | |
<title>Console Reporter Spec</title> | |
<link rel="stylesheet" href="../ext/jasmine.css" type="text/css" /> | |
<script type="text/javascript" src="../ext/jasmine.js"></script> | |
<script type="text/javascript" src="../ext/jasmine-html.js"></script> | |
<script type="text/javascript" src="../src/jasmine.teamcity_reporter.js"></script> | |
</head> | |
<body> | |
<script type="text/javascript"> | |
describe("Basic Suite", function() { | |
it("Should pass a basic truthiness test.", function() { | |
expect(true).toEqual(true); | |
}); | |
it("Should fail when it hits an inequal statement.", function() { | |
expect(1+1).toEqual(3); | |
}); | |
}); | |
describe("Another Suite", function() { | |
it("Should pass this test as well.", function() { | |
expect(0).toEqual(0); | |
}); | |
}); | |
var OnCompleteReporter = _.extend(function () {}, jasmine.Reporter); | |
OnCompleteReporter.prototype.reportRunnerResults = function () { | |
console.log("##jasmine.reportRunnerResults"); | |
}; | |
jasmineEnv.addReporter(new OnCompleteReporter()); | |
jasmine.getEnv().addReporter(new jasmine.TeamcityReporter()); | |
jasmine.getEnv().addReporter(new jasmine.TrivialReporter()); | |
jasmine.getEnv().execute(); | |
</script> | |
</body> | |
</html> |
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
console.log('Loading a web page'); | |
var page = new WebPage(); | |
//This was tricky, this is the way to open LOCAL files | |
var url = "file://localhost/Users/danmerino/test/teamcity_reporter.html"; | |
phantom.viewportSize = {width: 800, height: 600}; | |
//This is required because PhantomJS sandboxes the website and it does not show up the console messages form that page by default | |
page.onConsoleMessage = function (msg) { | |
console.log(msg); | |
if (msg && msg.indexOf("##jasmine.reportRunnerResults") !== -1) { | |
phantom.exit(); | |
} | |
}; | |
//Open the website | |
page.open(url, function (status) { | |
//Page is loaded! | |
if (status !== 'success') { | |
console.log('Unable to load the address!'); | |
} else { | |
//Using a delay to make sure the JavaScript is executed in the browser | |
window.setTimeout(function () { | |
page.render("output.png"); | |
phantom.exit(); | |
}, 200); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Modified version of http://blog.danmerino.com/continuos-integration-ci-for-javascript-jasmine-and-teamcity/, that sends a message from Jasmine to notify PhantomJS to exit as soon as the last test has completed (not wait for the timeout).