@@ -3897,27 +3897,28 @@ def test_unicode_html_shell(self):
3897
3897
self .run_browser ('test.html' , None , '/report_result?0' )
3898
3898
3899
3899
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'
3923
3924
0 commit comments