mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-20 08:16:31 +00:00
wasm-bindgen-test: Have the test runner JS call the original console.log
This makes control flow a little easier to follow and avoids wasm->js->wasm re-entrancy.
This commit is contained in:
@ -13,24 +13,30 @@
|
||||
logs.innerHTML += `${msg}\n`;
|
||||
}
|
||||
};
|
||||
|
||||
const orig_console_error = function(...args) {
|
||||
const logs = document.getElementById('console_error');
|
||||
for (let msg of args) {
|
||||
logs.innerHTML += `${msg}\n`;
|
||||
}
|
||||
};
|
||||
|
||||
console.log = function(...args) {
|
||||
if (window.console_log_redirect)
|
||||
window.console_log_redirect(orig_console_log, args);
|
||||
else
|
||||
orig_console_log.apply(this, args);
|
||||
if (window.console_log_redirect) {
|
||||
window.console_log_redirect(args);
|
||||
}
|
||||
|
||||
orig_console_log.apply(this, args);
|
||||
};
|
||||
|
||||
console.error = function(...args) {
|
||||
if (window.console_error_redirect)
|
||||
window.console_error_redirect(orig_console_error, args);
|
||||
else
|
||||
orig_console_error.apply(this, args);
|
||||
if (window.console_error_redirect) {
|
||||
window.console_error_redirect(args);
|
||||
}
|
||||
|
||||
orig_console_error.apply(this, args);
|
||||
};
|
||||
|
||||
window.__wbg_test_invoke = f => f();
|
||||
</script>
|
||||
<script src='run.js' type=module></script>
|
||||
|
@ -7,17 +7,21 @@
|
||||
<script>
|
||||
const orig_console_log = console.log;
|
||||
const orig_console_error = console.error;
|
||||
|
||||
console.log = function(...args) {
|
||||
if (window.console_log_redirect)
|
||||
window.console_log_redirect(orig_console_log, args);
|
||||
else
|
||||
orig_console_log.apply(this, args);
|
||||
if (window.console_log_redirect) {
|
||||
window.console_log_redirect(args);
|
||||
}
|
||||
|
||||
orig_console_log.apply(this, args);
|
||||
};
|
||||
|
||||
console.error = function(...args) {
|
||||
if (window.console_error_redirect)
|
||||
window.console_error_redirect(orig_console_error, args);
|
||||
else
|
||||
orig_console_error.apply(this, args);
|
||||
if (window.console_error_redirect) {
|
||||
window.console_error_redirect(args);
|
||||
}
|
||||
|
||||
orig_console_error.apply(this, args);
|
||||
};
|
||||
|
||||
window.__wbg_test_invoke = f => f();
|
||||
|
@ -24,19 +24,17 @@ pub fn execute(
|
||||
// all these calls and capture the output of tests
|
||||
const prev_log = console.log;
|
||||
console.log = function(...args) {{
|
||||
if (console_log_redirect === null) {{
|
||||
prev_log.apply(null, args);
|
||||
}} else {{
|
||||
console_log_redirect(prev_log, args);
|
||||
if (console_log_redirect) {{
|
||||
console_log_redirect(args);
|
||||
}}
|
||||
prev_log.apply(null, args);
|
||||
}};
|
||||
const prev_error = console.error;
|
||||
console.error = function(...args) {{
|
||||
if (console_error_redirect === null) {{
|
||||
prev_error.apply(null, args);
|
||||
}} else {{
|
||||
console_error_redirect(prev_error, args);
|
||||
if (console_error_redirect) {{
|
||||
console_error_redirect(args);
|
||||
}}
|
||||
prev_error.apply(null, args);
|
||||
}};
|
||||
|
||||
global.__wbg_test_invoke = f => f();
|
||||
|
Reference in New Issue
Block a user