Skip to content

Commit 6841391

Browse files
authored
[testing] Use customizable port for the browser test server. (#24976)
Add a helper to copy `browser_reporting.js` file with the test server URL inlined. We could do `globalThis.location` for some tests, but that doesn't work for audio worklets and when using blob urls. Where possible just remove the reference to `http:://localhost:8888` and use `/`.
1 parent b805400 commit 6841391

14 files changed

+37
-29
lines changed

test/browser/async_bad_list.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ int main() {
1717
Module.reported = true;
1818
console.log("reporting success");
1919
// manually REPORT_RESULT; we shouldn't call back into native code at this point
20-
await fetch("http://localhost:8888/report_result?0");
20+
await fetch("/report_result?0");
2121
window.close();
2222
}
2323
};

test/browser/async_returnvalue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ int main() {
3939
Module.reported = true;
4040
console.log("reporting success");
4141
// manually REPORT_RESULT; we shouldn't call back into native code at this point
42-
await fetch("http://localhost:8888/report_result?0");
42+
await fetch("/report_result?0");
4343
window.close();
4444
}
4545
};

test/browser/test_cwrap_early.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Module['preRun'] = () => {
99
console.log('onRuntimeInitialized');
1010
if (wrappedAdd(5, 6) != 11) throw '5 + 6 should be 11';
1111
// report success
12-
await fetch('http://localhost:8888/report_result?0');
12+
await fetch('/report_result?0');
1313
window.close();
1414
};
1515
};

test/browser_reporting.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var captureStdio = false;
33

44
var hasModule = typeof Module === 'object' && Module;
55

6-
var reportingURL = 'http://localhost:8888';
6+
var reportingURL = '{{{REPORTING_URL}}}';
77

88
async function reportResultToServer(result) {
99
if (reportResultToServer.reported) {

test/canvas_style_proxy_shell.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@
153153

154154
window.verifyCanvasStyle = async () => {
155155
var success = Module.canvas.style.cursor === 'pointer';
156-
await fetch('http://localhost:8888/report_result?' + (success ? 1 : 0));
156+
await fetch('/report_result?' + (success ? 1 : 0));
157157
window.close();
158158
}
159159

test/common.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2310,7 +2310,8 @@ class BrowserCore(RunnerCore):
23102310
# single test (hundreds of minutes)
23112311
MAX_UNRESPONSIVE_TESTS = 10
23122312
PORT = 8888
2313-
HARNESS_URL = 'http://localhost:%s/run_harness' % PORT
2313+
SERVER_URL = f'http://localhost:{PORT}'
2314+
HARNESS_URL = f'{SERVER_URL}/run_harness'
23142315
BROWSER_TIMEOUT = 60
23152316

23162317
unresponsive_tests = 0
@@ -2378,6 +2379,11 @@ def tearDownClass(cls):
23782379
def is_browser_test(self):
23792380
return True
23802381

2382+
def add_browser_reporting(self):
2383+
contents = read_file(test_file('browser_reporting.js'))
2384+
contents = contents.replace('{{{REPORTING_URL}}}', BrowserCore.SERVER_URL)
2385+
create_file('browser_reporting.js', contents)
2386+
23812387
def assert_out_queue_empty(self, who):
23822388
if not self.harness_out_queue.empty():
23832389
responses = []
@@ -2461,7 +2467,8 @@ def compile_btest(self, filename, cflags, reporting=Reporting.FULL):
24612467
# the header as there may be multiple files being compiled here).
24622468
if reporting != Reporting.NONE:
24632469
# For basic reporting we inject JS helper funtions to report result back to server.
2464-
cflags += ['--pre-js', test_file('browser_reporting.js')]
2470+
self.add_browser_reporting()
2471+
cflags += ['--pre-js', 'browser_reporting.js']
24652472
if reporting == Reporting.FULL:
24662473
# If C reporting (i.e. the REPORT_RESULT macro) is required we
24672474
# also include report_result.c and force-include report_result.h
@@ -2473,6 +2480,9 @@ def compile_btest(self, filename, cflags, reporting=Reporting.FULL):
24732480
if not os.path.exists(filename):
24742481
filename = test_file(filename)
24752482
self.run_process([compiler_for(filename), filename] + self.get_cflags() + cflags)
2483+
# Remove the file since some tests have assertions for how many files are in
2484+
# the output directory.
2485+
utils.delete_file('browser_reporting.js')
24762486

24772487
def btest_exit(self, filename, assert_returncode=0, *args, **kwargs):
24782488
"""Special case of `btest` that reports its result solely via exiting

test/custom_messages_proxy_shell.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
function sendResult(success) {
1717
if (window.sentTestResult) return;
1818
window.sentTestResult = true;
19-
fetch('http://localhost:8888/report_result?' + (success ? 1 : 0))
19+
fetch('/report_result?' + (success ? 1 : 0))
2020
.then(() => window.close());
2121
}
2222

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
addEventListener('error', (event) => {
22
window.disableErrorReporting = true;
33
var result = event.error === 42 ? 0 : 1;
4-
fetch('http://localhost:8888/report_result?' + result);
4+
fetch('/report_result?' + result);
55
});
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
addEventListener('error', (event) => {
22
window.disableErrorReporting = true;
33
var result = event.error === 'Hello!' ? 0 : 1;
4-
fetch('http://localhost:8888/report_result?' + result);
4+
fetch('/report_result?' + result);
55
});

test/fetch/test_fetch_redirect.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
#include <stdlib.h>
1010
#include <emscripten/fetch.h>
1111

12-
#define SERVER "http://localhost:8888"
13-
1412
// 301: Moved Permanently - https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/301
1513
// 302: Found (Previously "Moved Temporarily") - https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/302
1614
// 303: See Other - https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/303

0 commit comments

Comments
 (0)