mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-31 01:11:06 +00:00
Merge pull request #1178 from fitzgen/issue-1167
Some wasm-bindgen-test runtime fixes
This commit is contained in:
commit
1526d18ed6
@ -13,24 +13,30 @@
|
|||||||
logs.innerHTML += `${msg}\n`;
|
logs.innerHTML += `${msg}\n`;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const orig_console_error = function(...args) {
|
const orig_console_error = function(...args) {
|
||||||
const logs = document.getElementById('console_error');
|
const logs = document.getElementById('console_error');
|
||||||
for (let msg of args) {
|
for (let msg of args) {
|
||||||
logs.innerHTML += `${msg}\n`;
|
logs.innerHTML += `${msg}\n`;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log = function(...args) {
|
console.log = function(...args) {
|
||||||
if (window.console_log_redirect)
|
if (window.on_console_log) {
|
||||||
window.console_log_redirect(orig_console_log, args);
|
window.on_console_log(args);
|
||||||
else
|
}
|
||||||
orig_console_log.apply(this, args);
|
|
||||||
|
orig_console_log.apply(this, args);
|
||||||
};
|
};
|
||||||
|
|
||||||
console.error = function(...args) {
|
console.error = function(...args) {
|
||||||
if (window.console_error_redirect)
|
if (window.on_console_error) {
|
||||||
window.console_error_redirect(orig_console_error, args);
|
window.on_console_error(args);
|
||||||
else
|
}
|
||||||
orig_console_error.apply(this, args);
|
|
||||||
|
orig_console_error.apply(this, args);
|
||||||
};
|
};
|
||||||
|
|
||||||
window.__wbg_test_invoke = f => f();
|
window.__wbg_test_invoke = f => f();
|
||||||
</script>
|
</script>
|
||||||
<script src='run.js' type=module></script>
|
<script src='run.js' type=module></script>
|
||||||
|
@ -7,17 +7,21 @@
|
|||||||
<script>
|
<script>
|
||||||
const orig_console_log = console.log;
|
const orig_console_log = console.log;
|
||||||
const orig_console_error = console.error;
|
const orig_console_error = console.error;
|
||||||
console.log = function() {
|
|
||||||
if (window.console_log_redirect)
|
console.log = function(...args) {
|
||||||
window.console_log_redirect(orig_console_log, arguments);
|
if (window.on_console_log) {
|
||||||
else
|
window.on_console_log(args);
|
||||||
orig_console_log.apply(this, arguments);
|
}
|
||||||
|
|
||||||
|
orig_console_log.apply(this, args);
|
||||||
};
|
};
|
||||||
console.error = function() {
|
|
||||||
if (window.console_error_redirect)
|
console.error = function(...args) {
|
||||||
window.console_error_redirect(orig_console_error, arguments);
|
if (window.on_console_error) {
|
||||||
else
|
window.on_console_error(args);
|
||||||
orig_console_error.apply(this, arguments);
|
}
|
||||||
|
|
||||||
|
orig_console_error.apply(this, args);
|
||||||
};
|
};
|
||||||
|
|
||||||
window.__wbg_test_invoke = f => f();
|
window.__wbg_test_invoke = f => f();
|
||||||
|
@ -16,27 +16,25 @@ pub fn execute(
|
|||||||
r#"
|
r#"
|
||||||
const {{ exit }} = require('process');
|
const {{ exit }} = require('process');
|
||||||
|
|
||||||
let console_log_redirect = null;
|
let on_console_log = null;
|
||||||
let console_error_redirect = null;
|
let on_console_error = null;
|
||||||
|
|
||||||
// override `console.log` and `console.error` before we import tests to
|
// override `console.log` and `console.error` before we import tests to
|
||||||
// ensure they're bound correctly in wasm. This'll allow us to intercept
|
// ensure they're bound correctly in wasm. This'll allow us to intercept
|
||||||
// all these calls and capture the output of tests
|
// all these calls and capture the output of tests
|
||||||
const prev_log = console.log;
|
const prev_log = console.log;
|
||||||
console.log = function(...args) {{
|
console.log = function(...args) {{
|
||||||
if (console_log_redirect === null) {{
|
if (on_console_log) {{
|
||||||
prev_log.apply(null, args);
|
on_console_log(args);
|
||||||
}} else {{
|
|
||||||
console_log_redirect(prev_log, args);
|
|
||||||
}}
|
}}
|
||||||
|
prev_log.apply(null, args);
|
||||||
}};
|
}};
|
||||||
const prev_error = console.error;
|
const prev_error = console.error;
|
||||||
console.error = function(...args) {{
|
console.error = function(...args) {{
|
||||||
if (console_error_redirect === null) {{
|
if (on_console_error) {{
|
||||||
prev_error.apply(null, args);
|
on_console_error(args);
|
||||||
}} else {{
|
|
||||||
console_error_redirect(prev_error, args);
|
|
||||||
}}
|
}}
|
||||||
|
prev_error.apply(null, args);
|
||||||
}};
|
}};
|
||||||
|
|
||||||
global.__wbg_test_invoke = f => f();
|
global.__wbg_test_invoke = f => f();
|
||||||
@ -46,8 +44,8 @@ pub fn execute(
|
|||||||
const wasm = require("./{0}_bg");
|
const wasm = require("./{0}_bg");
|
||||||
|
|
||||||
cx = new support.Context();
|
cx = new support.Context();
|
||||||
console_log_redirect = support.__wbgtest_console_log;
|
on_console_log = support.__wbgtest_console_log;
|
||||||
console_error_redirect = support.__wbgtest_console_error;
|
on_console_error = support.__wbgtest_console_error;
|
||||||
|
|
||||||
// Forward runtime arguments. These arguments are also arguments to the
|
// Forward runtime arguments. These arguments are also arguments to the
|
||||||
// `wasm-bindgen-test-runner` which forwards them to node which we
|
// `wasm-bindgen-test-runner` which forwards them to node which we
|
||||||
|
@ -31,8 +31,8 @@ pub fn spawn(
|
|||||||
await wasm.booted;
|
await wasm.booted;
|
||||||
|
|
||||||
const cx = new Context();
|
const cx = new Context();
|
||||||
window.console_log_redirect = __wbgtest_console_log;
|
window.on_console_log = __wbgtest_console_log;
|
||||||
window.console_error_redirect = __wbgtest_console_error;
|
window.on_console_error = __wbgtest_console_error;
|
||||||
|
|
||||||
// Forward runtime arguments. These arguments are also arguments to the
|
// Forward runtime arguments. These arguments are also arguments to the
|
||||||
// `wasm-bindgen-test-runner` which forwards them to node which we
|
// `wasm-bindgen-test-runner` which forwards them to node which we
|
||||||
|
@ -29,7 +29,9 @@ macro_rules! console_log {
|
|||||||
///
|
///
|
||||||
/// This macro is invoked as:
|
/// This macro is invoked as:
|
||||||
///
|
///
|
||||||
/// wasm_bindgen_test_configure!(foo bar baz);
|
/// ```ignore
|
||||||
|
/// wasm_bindgen_test_configure!(foo bar baz);
|
||||||
|
/// ```
|
||||||
///
|
///
|
||||||
/// where all of `foo`, `bar`, and `baz`, would be recognized options to this
|
/// where all of `foo`, `bar`, and `baz`, would be recognized options to this
|
||||||
/// macro. The currently known options to this macro are:
|
/// macro. The currently known options to this macro are:
|
||||||
|
@ -305,21 +305,20 @@ scoped_thread_local!(static CURRENT_OUTPUT: RefCell<Output>);
|
|||||||
// attach it to. The main `test` crate in the rust repo also has issues about
|
// attach it to. The main `test` crate in the rust repo also has issues about
|
||||||
// how not all output is captured, causing some inconsistencies sometimes.
|
// how not all output is captured, causing some inconsistencies sometimes.
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn __wbgtest_console_log(original: &Function, args: &Array) {
|
pub fn __wbgtest_console_log(args: &Array) {
|
||||||
record(original, args, |output| &mut output.log)
|
record(args, |output| &mut output.log)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handler for `console.error` invocations.
|
/// Handler for `console.error` invocations.
|
||||||
///
|
///
|
||||||
/// Works the same as `console_log` above.
|
/// Works the same as `console_log` above.
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn __wbgtest_console_error(original: &Function, args: &Array) {
|
pub fn __wbgtest_console_error(args: &Array) {
|
||||||
record(original, args, |output| &mut output.error)
|
record(args, |output| &mut output.error)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn record(orig: &Function, args: &Array, dst: impl FnOnce(&mut Output) -> &mut String) {
|
fn record(args: &Array, dst: impl FnOnce(&mut Output) -> &mut String) {
|
||||||
if !CURRENT_OUTPUT.is_set() {
|
if !CURRENT_OUTPUT.is_set() {
|
||||||
drop(orig.apply(&JsValue::null(), args));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user