Skip to content

Commit

Permalink
wasm-bindgen-test: Rename console_*_redirect to on_console_*
Browse files Browse the repository at this point in the history
Since we are no longer redirecting all console logs, and are instead just
observing them.
  • Loading branch information
fitzgen committed Jan 14, 2019
1 parent a94f3f4 commit 56c4385
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@
};

console.log = function(...args) {
if (window.console_log_redirect) {
window.console_log_redirect(args);
if (window.on_console_log) {
window.on_console_log(args);
}

orig_console_log.apply(this, args);
};

console.error = function(...args) {
if (window.console_error_redirect) {
window.console_error_redirect(args);
if (window.on_console_error) {
window.on_console_error(args);
}

orig_console_error.apply(this, args);
Expand Down
8 changes: 4 additions & 4 deletions crates/cli/src/bin/wasm-bindgen-test-runner/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
const orig_console_error = console.error;

console.log = function(...args) {
if (window.console_log_redirect) {
window.console_log_redirect(args);
if (window.on_console_log) {
window.on_console_log(args);
}

orig_console_log.apply(this, args);
};

console.error = function(...args) {
if (window.console_error_redirect) {
window.console_error_redirect(args);
if (window.on_console_error) {
window.on_console_error(args);
}

orig_console_error.apply(this, args);
Expand Down
16 changes: 8 additions & 8 deletions crates/cli/src/bin/wasm-bindgen-test-runner/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@ pub fn execute(
r#"
const {{ exit }} = require('process');
let console_log_redirect = null;
let console_error_redirect = null;
let on_console_log = null;
let on_console_error = null;
// override `console.log` and `console.error` before we import tests to
// ensure they're bound correctly in wasm. This'll allow us to intercept
// all these calls and capture the output of tests
const prev_log = console.log;
console.log = function(...args) {{
if (console_log_redirect) {{
console_log_redirect(args);
if (on_console_log) {{
on_console_log(args);
}}
prev_log.apply(null, args);
}};
const prev_error = console.error;
console.error = function(...args) {{
if (console_error_redirect) {{
console_error_redirect(args);
if (on_console_error) {{
on_console_error(args);
}}
prev_error.apply(null, args);
}};
Expand All @@ -44,8 +44,8 @@ pub fn execute(
const wasm = require("./{0}_bg");
cx = new support.Context();
console_log_redirect = support.__wbgtest_console_log;
console_error_redirect = support.__wbgtest_console_error;
on_console_log = support.__wbgtest_console_log;
on_console_error = support.__wbgtest_console_error;
// Forward runtime arguments. These arguments are also arguments to the
// `wasm-bindgen-test-runner` which forwards them to node which we
Expand Down
4 changes: 2 additions & 2 deletions crates/cli/src/bin/wasm-bindgen-test-runner/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ pub fn spawn(
await wasm.booted;
const cx = new Context();
window.console_log_redirect = __wbgtest_console_log;
window.console_error_redirect = __wbgtest_console_error;
window.on_console_log = __wbgtest_console_log;
window.on_console_error = __wbgtest_console_error;
// Forward runtime arguments. These arguments are also arguments to the
// `wasm-bindgen-test-runner` which forwards them to node which we
Expand Down

0 comments on commit 56c4385

Please sign in to comment.