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 ...@@ -48,6 +48,13 @@ var defaultUserAgent = phantom.defaultPageSettings.userAgent
48 48
49 exports.create = function create(options) { 49 exports.create = function create(options) {
50 "use strict"; 50 "use strict";
51 // This is a bit of a hack to check if one is trying to override the preconfigured
52 // casper instance from within a test environment.
53 if (phantom.casperTest && window.casper) {
54 console.error("Fatal: you can't override the preconfigured casper instance in a test environment.");
55 console.error("Docs: http://docs.casperjs.org/en/latest/testing.html#test-command-args-and-options");
56 phantom.exit(1);
57 }
51 return new Casper(options); 58 return new Casper(options);
52 }; 59 };
53 60
......
...@@ -304,6 +304,13 @@ class TestCommandOutputTest(CasperExecTestBase): ...@@ -304,6 +304,13 @@ class TestCommandOutputTest(CasperExecTestBase):
304 ], failing=True) 304 ], failing=True)
305 305
306 @timeout(20) 306 @timeout(20)
307 def test_casper_test_instance_overriding(self):
308 script_path = os.path.join(TEST_ROOT, 'tester', 'casper-instance-override.js')
309 self.assertCommandOutputContains('test ' + script_path, [
310 "Fatal: you can't override the preconfigured casper instance",
311 ], failing=True)
312
313 @timeout(20)
307 def test_dubious_test(self): 314 def test_dubious_test(self):
308 script_path = os.path.join(TEST_ROOT, 'tester', 'dubious.js') 315 script_path = os.path.join(TEST_ROOT, 'tester', 'dubious.js')
309 self.assertCommandOutputContains('test ' + script_path, [ 316 self.assertCommandOutputContains('test ' + script_path, [
......
1 // this should never happen
2 // http://docs.casperjs.org/en/latest/testing.html#test-command-args-and-options
3 var casper = require("casper").create();
4
5 casper.test.begin("foo", function(test) {
6 "use strict";
7 test.assert(true);
8 test.done();
9 });