@@ -8539,3 +8539,56 @@ def test_html_preprocess(self):
85398539T4:NO_EXIT_RUNTIME > 1
85408540T5:NO_EXIT_RUNTIME
85418541T6:(else) !NO_EXIT_RUNTIME""" , output )
8542+
8543+ # Tests that Emscripten-compiled applications can be run from a relative path with node command line that is different than the current working directory.
8544+ def test_node_js_run_from_different_directory (self ):
8545+ args = ['-O3' , '-s' , 'WASM=1' , '--memory-init-file' , '1' , '-s' , 'BINARYEN_METHOD="asmjs,native-wasm"' ]
8546+ # Test that .mem.js is loaded up properly even if running the build output from a separate directory.
8547+ os .mkdir ('subdir' )
8548+ Popen ([PYTHON , EMCC , path_from_root ('tests' , 'hello_world.c' ), '-o' , os .path .join ('subdir' , 'a.js' )] + args ).communicate ()
8549+ ret = Popen (NODE_JS + [os .path .join ('subdir' , 'a.js' )], stdout = PIPE ).communicate ()[0 ]
8550+ try_delete ('subdir' )
8551+ assert 'hello, world!' in ret
8552+
8553+ # Test that the build is loaded properly when Module.locateFile is being used, where Module.locateFile() specifies an absolute path already.
8554+ os .mkdir ('subdir' )
8555+ open (os .path .join ('subdir' , 'pre.js' ), 'w' ).write ('''
8556+ var Module = {};
8557+ Module.memoryInitializerPrefixURL = 'this_should_be_getting_ignored_since_locateFile_is_specified/';
8558+ Module.locateFile = function(f) { return __dirname + '/' + f; }
8559+ ''' )
8560+
8561+ Popen ([PYTHON , EMCC , path_from_root ('tests' , 'hello_world.c' ), '-o' , os .path .join ('subdir' , 'a.js' ), '--pre-js' , os .path .join ('subdir' , 'pre.js' )] + args ).communicate ()
8562+ ret = Popen (NODE_JS + [os .path .join ('subdir' , 'a.js' )], stdout = PIPE ).communicate ()[0 ]
8563+ try_delete ('subdir' )
8564+ assert 'hello, world!' in ret
8565+
8566+ # Test that the build is loaded properly when Module.locateFile is being used, and it returns a relative path.
8567+ os .mkdir ('subdir' )
8568+ open (os .path .join ('subdir' , 'pre.js' ), 'w' ).write ('''
8569+ var Module = {};
8570+ Module.memoryInitializerPrefixURL = 'this_should_be_getting_ignored_since_locateFile_is_specified/';
8571+ Module.locateFile = function(f) { return 'data/' + f; }
8572+ ''' )
8573+
8574+ Popen ([PYTHON , EMCC , path_from_root ('tests' , 'hello_world.c' ), '-o' , os .path .join ('subdir' , 'a.js' ), '--pre-js' , os .path .join ('subdir' , 'pre.js' )] + args ).communicate ()
8575+ os .mkdir (os .path .join ('subdir' , 'data' ))
8576+ os .rename (os .path .join ('subdir' , 'a.js.mem' ), os .path .join ('subdir' , 'data' , 'a.js.mem' ))
8577+ os .rename (os .path .join ('subdir' , 'a.asm.js' ), os .path .join ('subdir' , 'data' , 'a.asm.js' ))
8578+ ret = Popen (NODE_JS + [os .path .join ('subdir' , 'a.js' )], stdout = PIPE ).communicate ()[0 ]
8579+ try_delete ('subdir' )
8580+ assert 'hello, world!' in ret
8581+
8582+ # Test that the build is loaded properly when memoryInitializerPrefixURL is being used, and it returns a relative path.
8583+ os .mkdir ('subdir' )
8584+ open (os .path .join ('subdir' , 'pre.js' ), 'w' ).write ('''
8585+ var Module = {};
8586+ Module.memoryInitializerPrefixURL = 'data/';
8587+ ''' )
8588+
8589+ Popen ([PYTHON , EMCC , path_from_root ('tests' , 'hello_world.c' ), '-o' , os .path .join ('subdir' , 'a.js' ), '--pre-js' , os .path .join ('subdir' , 'pre.js' )] + args ).communicate ()
8590+ os .mkdir (os .path .join ('subdir' , 'data' ))
8591+ os .rename (os .path .join ('subdir' , 'a.js.mem' ), os .path .join ('subdir' , 'data' , 'a.js.mem' ))
8592+ ret = Popen (NODE_JS + [os .path .join ('subdir' , 'a.js' )], stdout = PIPE ).communicate ()[0 ]
8593+ try_delete ('subdir' )
8594+ assert 'hello, world!' in ret
0 commit comments