source: pyenvjasmine/pyenvjasmine/tests/test_runner.py@ 36:4c964b691922

Last change on this file since 36:4c964b691922 was 36:4c964b691922, checked in by Mauro Molino <mauro@…>, 6 years ago

Selectable engine (phantom with jasmine3, rhino with jasmine1)

File size: 7.8 KB
Line 
1import os
2import pytest
3
4from pyenvjasmine.runner import Runner, get_environment
5
6
7class TestsRunnerRhino(object):
8
9 """
10 Run the full tests using the old rhino+jasmine1 env
11 """
12
13 def test_runner_defaults(self):
14 """
15 Test the runner, using default values (which wil run the demo specs)
16 """
17 jstests = Runner(testing_enviroment='rhino')
18 success, stdout = jstests.run()
19 assert success
20 assert 'Failed: 0' in stdout
21 assert 'Passed: 5' in stdout
22
23 def test_runner_params(self):
24 """
25 Test the runner, giving it some parameters
26 """
27 here = os.path.dirname(__file__)
28 sample = os.path.join(here, 'sample')
29 conf_file = os.path.join(sample, 'configfile.js')
30 envjasmine_dir = os.path.join(os.path.dirname(here), 'envjasmine')
31 jstests = Runner(
32 testing_enviroment='rhino',
33 rootdir=envjasmine_dir,
34 testdir=sample,
35 configfile=conf_file,
36 )
37 success, stdout = jstests.run(spec='tests/specs/test_demo.spec.js')
38 lines = stdout.splitlines()
39 assert lines[0].endswith('specs/test_demo.spec.js')
40 assert lines[1].startswith('[ Envjs/1.6 (Rhino;')
41 assert 'Passed: 4' in lines
42 assert 'Failed: 0' in lines
43 assert 'Total : 4' in lines
44
45 def test_write_browser_htmlfile_markup_is_correct(self):
46 """
47 Test the created markup
48 """
49 here = os.path.dirname(__file__)
50 sample = os.path.join(here, 'sample')
51 browser_conf_file = os.path.join(sample, 'browser.configfile.js')
52 envjasmine_dir = os.path.join(os.path.dirname(here), 'envjasmine')
53 jstests = Runner(
54 testing_enviroment='rhino',
55 rootdir=envjasmine_dir,
56 testdir=sample,
57 browser_configfile=browser_conf_file
58 )
59 expected = jstests.create_testRunnerHtml()
60 success, stdout = jstests.run(spec='tests/specs/test_demo.spec.js')
61 assert not success
62 assert 'Failed: 2' in stdout
63 with open("browser.runner.html",'r') as file:
64 actual = file.read()
65 assert expected == actual
66
67 def test_runner_with_browser_configfile(self):
68 """
69 Test the runner, giving it some parameters incl the browser config file
70 """
71 here = os.path.dirname(__file__)
72 sample = os.path.join(here, 'sample')
73 browser_conf_file = os.path.join(sample, 'browser.configfile.js')
74 envjasmine_dir = os.path.join(os.path.dirname(here), 'envjasmine')
75 jstests = Runner(
76 testing_enviroment='rhino',
77 rootdir=envjasmine_dir,
78 testdir=sample,
79 browser_configfile=browser_conf_file
80 )
81 success, stdout = jstests.run(spec='tests/specs/test_demo.spec.js')
82 assert not success
83 assert 'Failed: 2' in stdout
84
85 def test_get_environment(self):
86 """
87 Testing the OS specific code
88 Could not figure out how to do this using mock,
89 so monkey patching the old way.
90 """
91 old_os_name = os.name
92 try:
93 os.name = 'nt'
94 res = get_environment()
95 assert res == '--environment=WIN'
96 os.name = 'posix'
97 res = get_environment()
98 assert res == '--environment=UNIX'
99 finally:
100 os.name = old_os_name
101
102 def test_did_test_pass(self):
103 # there is some coverage done with the previous tests,
104 # but we want to test also the case when a test failed
105 # and it does not appear in the "Failed:" report
106 jstests = Runner(testing_enviroment='rhino')
107 success = jstests.did_test_pass('')
108 assert not success
109 success = jstests.did_test_pass('some random data '*50)
110 assert not success
111 success = jstests.did_test_pass('some data FAILED some more data')
112 assert not success
113 success = jstests.did_test_pass('some data FAILEDsome more data')
114 assert not success
115 success = jstests.did_test_pass('Failed: 0')
116 assert success
117 success = jstests.did_test_pass('Failed: 0 FAILED')
118 assert not success
119 success = jstests.did_test_pass('FAILEDFailed: 0')
120 assert not success
121 success = jstests.did_test_pass('Failed: 0FAILED')
122 assert not success
123 success = jstests.did_test_pass('Failed: 1')
124 assert not success
125 success = jstests.did_test_pass('Failed: -11')
126 assert not success
127 success = jstests.did_test_pass('Failed: something-not-a-number')
128 assert not success
129
130class TestsRunnerPhantomjs(object):
131
132 """
133 Run the full tests using the phantom+jasmine3 env
134 """
135
136 def test_write_browser_htmlfile_markup_is_correct(self):
137 """
138 Test the created markup
139 The config file doesn't contain the mock files so jasmine tests
140 are expected to fail
141 """
142 here = os.path.dirname(__file__)
143 sample = os.path.join(here, 'sample')
144 browser_conf_file = os.path.join(sample, 'browser.configfile_no_mocks.js')
145 envjasmine_dir = os.path.join(os.path.dirname(here), 'envjasmine')
146 jstests = Runner(
147 testing_enviroment='phantomjs',
148 rootdir=envjasmine_dir,
149 testdir=sample,
150 browser_configfile=browser_conf_file
151 )
152 expected = jstests.create_testRunnerHtml()
153 jstests.write_browser_htmlfile()
154 success, stdout = jstests.run()
155 assert not success
156 assert '2 test(s) FAILED:' in stdout
157 with open("browser.runner.html",'r') as file:
158 actual = file.read()
159 assert expected == actual
160
161 def test_runner_with_browser_configfile(self):
162 """
163 Test the runner, giving it some parameters incl the browser config file
164 The config file contains the mock files so jasmine tests are expected
165 to pass
166 """
167 here = os.path.dirname(__file__)
168 sample = os.path.join(here, 'sample')
169 browser_conf_file = os.path.join(sample, 'browser.configfile.js')
170 envjasmine_dir = os.path.join(os.path.dirname(here), 'envjasmine')
171 jstests = Runner(
172 testing_enviroment='phantomjs',
173 rootdir=envjasmine_dir,
174 testdir=sample,
175 browser_configfile=browser_conf_file
176 )
177 success, stdout = jstests.run()
178 assert success
179 assert '0 failures' in stdout
180
181 def test_did_test_pass(self):
182 # there is some coverage done with the previous tests,
183 # but we want to test also the case when a test failed
184 # and it does not appear in the "Failed:" report
185 here = os.path.dirname(__file__)
186 sample = os.path.join(here, 'sample')
187 browser_conf_file = os.path.join(sample, 'browser.configfile.js')
188
189 jstests = Runner(
190 testing_enviroment='phantomjs',
191 browser_configfile=browser_conf_file
192 )
193 success = jstests.did_test_pass('')
194 assert not success
195 success = jstests.did_test_pass('some random data '*50)
196 assert not success
197 success = jstests.did_test_pass('some data FAILED some more data')
198 assert not success
199 success = jstests.did_test_pass('some data FAILEDsome more data')
200 assert not success
201 success = jstests.did_test_pass('0 failures')
202 assert success
203 success = jstests.did_test_pass('0 failures FAILED')
204 assert not success
205 success = jstests.did_test_pass('0Failed: failures')
206 assert not success
207 success = jstests.did_test_pass('1 test(s) FAILED:')
208 assert not success
209 success = jstests.did_test_pass('-11 test(s) FAILED:')
210 assert not success
211 success = jstests.did_test_pass('something-not-a-number test(s) FAILED:')
212 assert not success
Note: See TracBrowser for help on using the repository browser.