Merge pull request #728 from n1k0/prevent-casper-instance-creation-in-test-env
Prevent overriding of preconfigured casper instance in a test environment
Showing
3 changed files
with
23 additions
and
0 deletions
... | @@ -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, [ | ... | ... |
-
Please register or sign in to post a comment