@@ -8121,9 +8121,10 @@ def test_noderawfs_disables_embedding(self):
8121
8121
8122
8122
# Tests that Emscripten-compiled applications can be run from a relative path with node command line that is different than the current working directory.
8123
8123
def test_node_js_run_from_different_directory (self ):
8124
+ args = ['-O3' , '-s' , 'WASM=1' , '--memory-init-file' , '1' , '-s' , 'BINARYEN_METHOD="asmjs,native-wasm"' ]
8124
8125
# Test that .mem.js is loaded up properly even if running the build output from a separate directory.
8125
8126
os .mkdir ('subdir' )
8126
- Popen ([PYTHON , EMCC , path_from_root ('tests' , 'hello_world.c' ), '-o' , os .path .join ('subdir' , 'a.js' ), '-O3' ] ).communicate ()
8127
+ Popen ([PYTHON , EMCC , path_from_root ('tests' , 'hello_world.c' ), '-o' , os .path .join ('subdir' , 'a.js' )] + args ).communicate ()
8127
8128
ret = Popen (NODE_JS + [os .path .join ('subdir' , 'a.js' )], stdout = PIPE ).communicate ()[0 ]
8128
8129
try_delete ('subdir' )
8129
8130
assert 'hello, world!' in ret
@@ -8132,11 +8133,41 @@ def test_node_js_run_from_different_directory(self):
8132
8133
os .mkdir ('subdir' )
8133
8134
open (os .path .join ('subdir' , 'pre.js' ), 'w' ).write ('''
8134
8135
var Module = {};
8136
+ Module.memoryInitializerPrefixURL = 'this_should_be_getting_ignored_since_locateFile_is_specified/';
8135
8137
Module.locateFile = function(f) { return __dirname + '/' + f; }
8136
8138
''' )
8137
8139
8138
- 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' ), '-O3' ] ).communicate ()
8140
+ 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 ()
8139
8141
ret = Popen (NODE_JS + [os .path .join ('subdir' , 'a.js' )], stdout = PIPE ).communicate ()[0 ]
8140
8142
try_delete ('subdir' )
8141
8143
assert 'hello, world!' in ret
8142
8144
8145
+ # Test that the build is loaded properly when Module.locateFile is being used, and it returns a relative path.
8146
+ os .mkdir ('subdir' )
8147
+ open (os .path .join ('subdir' , 'pre.js' ), 'w' ).write ('''
8148
+ var Module = {};
8149
+ Module.memoryInitializerPrefixURL = 'this_should_be_getting_ignored_since_locateFile_is_specified/';
8150
+ Module.locateFile = function(f) { return 'data/' + f; }
8151
+ ''' )
8152
+
8153
+ 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 ()
8154
+ os .mkdir (os .path .join ('subdir' , 'data' ))
8155
+ os .rename (os .path .join ('subdir' , 'a.js.mem' ), os .path .join ('subdir' , 'data' , 'a.js.mem' ))
8156
+ os .rename (os .path .join ('subdir' , 'a.asm.js' ), os .path .join ('subdir' , 'data' , 'a.asm.js' ))
8157
+ ret = Popen (NODE_JS + [os .path .join ('subdir' , 'a.js' )], stdout = PIPE ).communicate ()[0 ]
8158
+ try_delete ('subdir' )
8159
+ assert 'hello, world!' in ret
8160
+
8161
+ # Test that the build is loaded properly when memoryInitializerPrefixURL is being used, and it returns a relative path.
8162
+ os .mkdir ('subdir' )
8163
+ open (os .path .join ('subdir' , 'pre.js' ), 'w' ).write ('''
8164
+ var Module = {};
8165
+ Module.memoryInitializerPrefixURL = 'data/';
8166
+ ''' )
8167
+
8168
+ 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 ()
8169
+ os .mkdir (os .path .join ('subdir' , 'data' ))
8170
+ os .rename (os .path .join ('subdir' , 'a.js.mem' ), os .path .join ('subdir' , 'data' , 'a.js.mem' ))
8171
+ ret = Popen (NODE_JS + [os .path .join ('subdir' , 'a.js' )], stdout = PIPE ).communicate ()[0 ]
8172
+ try_delete ('subdir' )
8173
+ assert 'hello, world!' in ret
0 commit comments