Skip to content

Commit 196cb75

Browse files
committed
fix test
1 parent 9c0230b commit 196cb75

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

tests/test_browser.py

+24-23
Original file line numberDiff line numberDiff line change
@@ -3897,27 +3897,28 @@ def test_unicode_html_shell(self):
38973897
self.run_browser('test.html', None, '/report_result?0')
38983898

38993899
def test_ENVIRONMENT(self):
3900-
for work in (1, 0):
3901-
for assertions in (0, 1):
3902-
if work and assertions: continue # we care about assertions when we fail
3903-
# tell the compiler to build with just that engine
3904-
args = []
3905-
if work:
3906-
args += ['-s', 'ENVIRONMENT="web"']
3907-
else:
3908-
args += ['-s', 'ENVIRONMENT="node"']
3909-
if assertions:
3910-
args += ['-s', 'ASSERTIONS=1']
3911-
print(work, assertions, args)
3912-
try:
3913-
self.btest('browser_test_hello_world.c', expected='0', args=args)
3914-
except Exception as e:
3915-
if not work:
3916-
if assertions:
3917-
# with assertions, an error should be shown
3918-
self.assertContained('not compiled with support for that', str(e))
3919-
else:
3920-
raise
3921-
js = open('src.cpp.o.js').read()
3922-
assert ('require(' in js) == ('node' in str(args)), 'we should have require() calls only if node js specified'
3900+
# handle when errors occur, report 999
3901+
open('pre.js', 'w').write('''
3902+
window.onerror = function(error) {
3903+
window.onerror = null;
3904+
var xhr = new XMLHttpRequest();
3905+
xhr.open('GET', 'http://localhost:8888/report_result?999', true);
3906+
xhr.send();
3907+
setTimeout(function() { window.close() }, 1000);
3908+
}
3909+
''')
3910+
jses = {}
3911+
for env in ['web', 'node', None]:
3912+
# tell the compiler to build with just that engine
3913+
args = ['--pre-js', 'pre.js']
3914+
if env:
3915+
args += ['-s', 'ENVIRONMENT="%s"' % env]
3916+
print(env, args)
3917+
fail = 'node' in str(args)
3918+
self.btest('browser_test_hello_world.c', expected='0' if not fail else '999', args=args)
3919+
js = open('test.js').read()
3920+
assert ('require(' in js) == fail, 'we should have require() calls only if node js specified'
3921+
jses[str(env)] = js
3922+
assert jses['None'] == jses['web'], 'not saying web but html output means web'
3923+
assert jses['None'] != jses['node'], 'but node leads to different output of course'
39233924

0 commit comments

Comments
 (0)