@@ -8166,9 +8166,10 @@ def test_noderawfs_disables_embedding(self):
8166
8166
8167
8167
# Tests that Emscripten-compiled applications can be run from a relative path with node command line that is different than the current working directory.
8168
8168
def test_node_js_run_from_different_directory (self ):
8169
+ args = ['-O3' , '-s' , 'WASM=1' , '--memory-init-file' , '1' , '-s' , 'BINARYEN_METHOD="asmjs,native-wasm"' ]
8169
8170
# Test that .mem.js is loaded up properly even if running the build output from a separate directory.
8170
8171
os .mkdir ('subdir' )
8171
- Popen ([PYTHON , EMCC , path_from_root ('tests' , 'hello_world.c' ), '-o' , os .path .join ('subdir' , 'a.js' ), '-O3' ] ).communicate ()
8172
+ Popen ([PYTHON , EMCC , path_from_root ('tests' , 'hello_world.c' ), '-o' , os .path .join ('subdir' , 'a.js' )] + args ).communicate ()
8172
8173
ret = Popen (NODE_JS + [os .path .join ('subdir' , 'a.js' )], stdout = PIPE ).communicate ()[0 ]
8173
8174
try_delete ('subdir' )
8174
8175
assert 'hello, world!' in ret
@@ -8177,11 +8178,41 @@ def test_node_js_run_from_different_directory(self):
8177
8178
os .mkdir ('subdir' )
8178
8179
open (os .path .join ('subdir' , 'pre.js' ), 'w' ).write ('''
8179
8180
var Module = {};
8181
+ Module.memoryInitializerPrefixURL = 'this_should_be_getting_ignored_since_locateFile_is_specified/';
8180
8182
Module.locateFile = function(f) { return __dirname + '/' + f; }
8181
8183
''' )
8182
8184
8183
- 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 ()
8185
+ 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 ()
8184
8186
ret = Popen (NODE_JS + [os .path .join ('subdir' , 'a.js' )], stdout = PIPE ).communicate ()[0 ]
8185
8187
try_delete ('subdir' )
8186
8188
assert 'hello, world!' in ret
8187
8189
8190
+ # Test that the build is loaded properly when Module.locateFile is being used, and it returns a relative path.
8191
+ os .mkdir ('subdir' )
8192
+ open (os .path .join ('subdir' , 'pre.js' ), 'w' ).write ('''
8193
+ var Module = {};
8194
+ Module.memoryInitializerPrefixURL = 'this_should_be_getting_ignored_since_locateFile_is_specified/';
8195
+ Module.locateFile = function(f) { return 'data/' + f; }
8196
+ ''' )
8197
+
8198
+ 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 ()
8199
+ os .mkdir (os .path .join ('subdir' , 'data' ))
8200
+ os .rename (os .path .join ('subdir' , 'a.js.mem' ), os .path .join ('subdir' , 'data' , 'a.js.mem' ))
8201
+ os .rename (os .path .join ('subdir' , 'a.asm.js' ), os .path .join ('subdir' , 'data' , 'a.asm.js' ))
8202
+ ret = Popen (NODE_JS + [os .path .join ('subdir' , 'a.js' )], stdout = PIPE ).communicate ()[0 ]
8203
+ try_delete ('subdir' )
8204
+ assert 'hello, world!' in ret
8205
+
8206
+ # Test that the build is loaded properly when memoryInitializerPrefixURL is being used, and it returns a relative path.
8207
+ os .mkdir ('subdir' )
8208
+ open (os .path .join ('subdir' , 'pre.js' ), 'w' ).write ('''
8209
+ var Module = {};
8210
+ Module.memoryInitializerPrefixURL = 'data/';
8211
+ ''' )
8212
+
8213
+ 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 ()
8214
+ os .mkdir (os .path .join ('subdir' , 'data' ))
8215
+ os .rename (os .path .join ('subdir' , 'a.js.mem' ), os .path .join ('subdir' , 'data' , 'a.js.mem' ))
8216
+ ret = Popen (NODE_JS + [os .path .join ('subdir' , 'a.js' )], stdout = PIPE ).communicate ()[0 ]
8217
+ try_delete ('subdir' )
8218
+ assert 'hello, world!' in ret
0 commit comments