Skip to content

Commit 3081a26

Browse files
authored
Improve testing of mainScriptUrlOrBlob. NFC (#21728)
I noticed when working on #21701 then these tests were not renaming the `.js` output, which meant that if `mainScriptUrlOrBlob` was completely ignored the tests would still pass. These changes rename the output `.js` file such that the default name will not longer work and the tests would fail if `mainScriptUrlOrBlob` were ignored.
1 parent edf2d4f commit 3081a26

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

test/manual_download_data.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
var dataDownload = download('/test/manual_download_data.data').then((data) => {
187187
console.log('downloaded data file');
188188
Module['downloadedData'] = data;
189-
var jsDownload = download('manual_download_data.js').then((data) => {
189+
var jsDownload = download('/test/manual_download_data.js').then((data) => {
190190
console.log('downloaded js file');
191191
Module['mainScriptUrlOrBlob'] = new Blob([data], { type: 'application/javascript' });
192192
addScriptToDom(data);

test/test_browser.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -443,12 +443,13 @@ def make_main_two_files(path1, path2, nonexistingpath):
443443
def test_preload_file_with_manual_data_download(self, args):
444444
create_file('file.txt', 'Hello!')
445445

446-
self.compile_btest('manual_download_data.cpp', ['-o', 'manual_download_data.js', '--preload-file', 'file.txt@/file.txt'] + args)
446+
self.compile_btest('manual_download_data.cpp', ['-o', 'out.js', '--preload-file', 'file.txt@/file.txt'] + args)
447447
shutil.copyfile(test_file('manual_download_data.html'), 'manual_download_data.html')
448448

449449
# Move .data file out of server root to ensure that getPreloadedPackage is actually used
450450
os.mkdir('test')
451-
shutil.move('manual_download_data.data', 'test/manual_download_data.data')
451+
shutil.move('out.js', 'test/manual_download_data.js')
452+
shutil.move('out.data', 'test/manual_download_data.data')
452453

453454
self.run_browser('manual_download_data.html', '/report_result?1')
454455

@@ -4817,11 +4818,16 @@ def test_pthread_growth(self, emcc_args):
48174818
def test_pthread_reltime(self):
48184819
self.btest_exit('pthread/test_pthread_reltime.cpp', args=['-pthread', '-sPTHREAD_POOL_SIZE'])
48194820

4820-
# Tests that it is possible to load the main .js file of the application manually via a Blob URL, and still use pthreads.
4821+
# Tests that it is possible to load the main .js file of the application manually via a Blob URL,
4822+
# and still use pthreads.
48214823
def test_load_js_from_blob_with_pthreads(self):
48224824
# TODO: enable this with wasm, currently pthreads/atomics have limitations
48234825
self.set_setting('EXIT_RUNTIME')
4824-
self.compile_btest('pthread/hello_thread.c', ['-pthread', '-o', 'hello_thread_with_blob_url.js'], reporting=Reporting.JS_ONLY)
4826+
self.compile_btest('pthread/hello_thread.c', ['-pthread', '-o', 'out.js'], reporting=Reporting.JS_ONLY)
4827+
4828+
# Now run the test with the JS file renamed and with its content
4829+
# stored in Module['mainScriptUrlOrBlob'].
4830+
shutil.move('out.js', 'hello_thread_with_blob_url.js')
48254831
shutil.copyfile(test_file('pthread/main_js_as_blob_loader.html'), 'hello_thread_with_blob_url.html')
48264832
self.run_browser('hello_thread_with_blob_url.html', '/report_result?exit:0')
48274833

test/test_core.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7669,8 +7669,9 @@ def test_webidl(self, mode, allow_memory_growth):
76697669
post_js += '\n\n'
76707670
create_file('extern-post.js', post_js)
76717671

7672-
# Export things on "TheModule". This matches the typical use pattern of the bound library
7673-
# being used as Box2D.* or Ammo.*, and we cannot rely on "Module" being always present (closure may remove it).
7672+
# Export things on "TheModule". This matches the typical use pattern of
7673+
# the bound library being used as Box2D.* or Ammo.*, and we cannot rely
7674+
# on "Module" being always present (closure may remove it).
76747675
self.emcc_args += ['--post-js=glue.js', '--extern-post-js=extern-post.js']
76757676
if mode == 'ALL':
76767677
self.emcc_args += ['-sASSERTIONS']
@@ -7681,8 +7682,10 @@ def test_webidl(self, mode, allow_memory_growth):
76817682

76827683
self.do_run_in_out_file_test(test_file('webidl/test.cpp'), out_suffix='_' + mode, includes=['.'])
76837684

7684-
# Test that we can perform fully-synchronous initialization when combining WASM_ASYNC_COMPILATION=0 + PTHREAD_POOL_DELAY_LOAD=1.
7685-
# Also checks that PTHREAD_POOL_DELAY_LOAD=1 adds a pthreadPoolReady promise that users can wait on for pthread initialization.
7685+
# Test that we can perform fully-synchronous initialization when combining
7686+
# WASM_ASYNC_COMPILATION=0 + PTHREAD_POOL_DELAY_LOAD=1. Also checks that
7687+
# PTHREAD_POOL_DELAY_LOAD=1 adds a pthreadPoolReady promise that users
7688+
# can wait on for pthread initialization.
76867689
@node_pthreads
76877690
def test_embind_sync_if_pthread_delayed(self):
76887691
self.set_setting('WASM_ASYNC_COMPILATION', 0)

0 commit comments

Comments
 (0)