wasm-bindgen
wasm-bindgen copied to clipboard
ReferenceError: Can't find variable: cov_import when testing with no_module
Describe the Bug
After updating wasm-bindgen-test to version 0.3.50, tests are no longer loading when run with the WASM_BINDGEN_USE_NO_MODULE=1 flag.
Steps to Reproduce
- Update wasm-bindgen-test to version 0.3.50
- Run tests with the WASM_BINDGEN_USE_NO_MODULE=1 flag
- Check the developer console
Expected Behavior
Tests should load and execute successfully.
Actual Behavior
Tests fail to load and the following error appears in the developer console:
ReferenceError: Can't find variable: cov_import
The issue is in crates/cli/src/bin/wasm-bindgen-test-runner/server.rs where the {cov_import} placeholder is not being substituted in the no_modules path:
let wbg_import_script = if test_mode.no_modules() {
String::from(
r#"
let Context = wasm_bindgen.WasmBindgenTestContext;
let __wbgtest_console_debug = wasm_bindgen.__wbgtest_console_debug;
let __wbgtest_console_log = wasm_bindgen.__wbgtest_console_log;
let __wbgtest_console_info = wasm_bindgen.__wbgtest_console_info;
let __wbgtest_console_warn = wasm_bindgen.__wbgtest_console_warn;
let __wbgtest_console_error = wasm_bindgen.__wbgtest_console_error;
{cov_import}
let init = wasm_bindgen;
"#,
)
} else {
...
Additional Context
The {cov_import} token in the string is likely meant to be replaced via string formatting but this substitution isn't happening, causing the JavaScript to reference an undefined variable.