Commit 69f94829 69f948292fb1de941dd240d806ff24025cd5d8e3 by Nicolas Perriault

Merge pull request #728 from n1k0/prevent-casper-instance-creation-in-test-env

Prevent overriding of preconfigured casper instance in a test environment
2 parents 0a09159a 29907e58
......@@ -48,6 +48,13 @@ var defaultUserAgent = phantom.defaultPageSettings.userAgent
exports.create = function create(options) {
"use strict";
// This is a bit of a hack to check if one is trying to override the preconfigured
// casper instance from within a test environment.
if (phantom.casperTest && window.casper) {
console.error("Fatal: you can't override the preconfigured casper instance in a test environment.");
console.error("Docs: http://docs.casperjs.org/en/latest/testing.html#test-command-args-and-options");
phantom.exit(1);
}
return new Casper(options);
};
......
......@@ -304,6 +304,13 @@ class TestCommandOutputTest(CasperExecTestBase):
], failing=True)
@timeout(20)
def test_casper_test_instance_overriding(self):
script_path = os.path.join(TEST_ROOT, 'tester', 'casper-instance-override.js')
self.assertCommandOutputContains('test ' + script_path, [
"Fatal: you can't override the preconfigured casper instance",
], failing=True)
@timeout(20)
def test_dubious_test(self):
script_path = os.path.join(TEST_ROOT, 'tester', 'dubious.js')
self.assertCommandOutputContains('test ' + script_path, [
......
// this should never happen
// http://docs.casperjs.org/en/latest/testing.html#test-command-args-and-options
var casper = require("casper").create();
casper.test.begin("foo", function(test) {
"use strict";
test.assert(true);
test.done();
});