Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
a56ee35
Implement js-bindgen test runner
Spxg Jan 23, 2026
d20f61b
Remove js panic stack output
Spxg Jan 26, 2026
2d14d14
Add error stack output
Spxg Jan 26, 2026
558458a
Format tomls
Spxg Jan 26, 2026
3eae2dc
Clean up
Spxg Jan 27, 2026
479b66f
Update console capture
Spxg Jan 27, 2026
956cea7
Add COPE/COOP headers
Spxg Jan 27, 2026
83b715d
Clean up
Spxg Jan 27, 2026
14ff66e
Add console hook
Spxg Jan 27, 2026
d74ca8f
Fix warning
Spxg Jan 28, 2026
75dfc98
Add client test workflow
Spxg Jan 28, 2026
2724ab2
Update runner shim
Spxg Jan 29, 2026
45345f8
Fix cargo format
Spxg Jan 29, 2026
827d104
No alias
Spxg Jan 29, 2026
b2bfe58
Update workflow
Spxg Jan 29, 2026
ea2b08f
Efficient parse arguments
Spxg Jan 29, 2026
c466541
Add const for ascii color
Spxg Jan 29, 2026
5b4b16c
Clean up
Spxg Jan 29, 2026
b3480f4
Rename to `js-bindgen-runner`
Spxg Jan 29, 2026
7999676
Clean up
Spxg Jan 29, 2026
d27f21a
Update workflow
Spxg Jan 29, 2026
10d241d
Rename env
Spxg Jan 29, 2026
b456568
Reduce read
Spxg Jan 29, 2026
3096d69
Mmap
Spxg Jan 29, 2026
cc01b38
Update driver and worker parse
Spxg Jan 29, 2026
a732330
Read tests by path
Spxg Jan 29, 2026
112de9f
Add comment
Spxg Jan 29, 2026
2542527
Move tempfile to workspace
Spxg Jan 29, 2026
9a2c2b7
Replace the code of creating js file
Spxg Jan 30, 2026
41ac558
Nits
daxpedda Jan 30, 2026
d8e7159
Format
daxpedda Jan 30, 2026
6041a5a
Slight Improvements
daxpedda Jan 30, 2026
4ae9de6
Init instance for each test
Spxg Jan 30, 2026
019e61f
Use clap to parse args
Spxg Jan 30, 2026
273c4f5
typo
Spxg Jan 30, 2026
8be4f64
Use axum
Spxg Jan 30, 2026
09a71d2
Add doctest
Spxg Jan 30, 2026
a7f73aa
Random Improvements
daxpedda Jan 30, 2026
5aa21b3
Run Taplo
daxpedda Jan 30, 2026
edf2a58
Use Fantoccini
Spxg Jan 30, 2026
d394eb8
Fix node no capture
Spxg Jan 30, 2026
f06c077
Add no-capture alias
Spxg Jan 30, 2026
f7b4203
Close browser for safari
Spxg Jan 30, 2026
c7fa17c
Clean up
Spxg Jan 30, 2026
1a369bd
Clean up
Spxg Jan 30, 2026
604abc5
Clean up
Spxg Jan 30, 2026
b802a6b
Clean up
Spxg Jan 30, 2026
a96def9
Clean up
Spxg Jan 31, 2026
a144628
Clean up
Spxg Jan 31, 2026
317e7e2
Use `JBG_TEST_RUNNER`
Spxg Jan 31, 2026
7cefb13
Add deno support
Spxg Jan 31, 2026
1749f45
Update TEST.md
Spxg Jan 31, 2026
d3703ee
JS panic handler
Spxg Jan 31, 2026
5d47596
Kill process when guard drop
Spxg Jan 31, 2026
4695cd8
Format
Spxg Jan 31, 2026
5f7f5dd
Add More TODOs
daxpedda Jan 31, 2026
674f1de
Remove unused option
Spxg Jan 31, 2026
c478aac
Remove duplicated todo
Spxg Jan 31, 2026
105d4e3
Cleanup
daxpedda Jan 31, 2026
e703546
Cleanup
Spxg Feb 1, 2026
9549ccf
Passing arguments to Node and Deno via command arguments
Spxg Feb 1, 2026
7fd2e7b
Use webdriver to get output
Spxg Feb 1, 2026
d7f2352
Remove parking_lot
Spxg Feb 1, 2026
b8a15e8
Fix shared worker
Spxg Feb 1, 2026
6db8362
Clean up
Spxg Feb 1, 2026
f8c7bc7
Add env prefix
Spxg Feb 1, 2026
2563357
Better WebDriver Error Handling
daxpedda Feb 1, 2026
e1abb9d
Clean up
Spxg Feb 2, 2026
560cf43
Run Prettier
daxpedda Feb 2, 2026
9e978f8
Move `js` Folder to `src`
daxpedda Feb 2, 2026
1a9c984
Move and Rename Some Stuff
daxpedda Feb 2, 2026
7cb347c
Fix Windows Tests
daxpedda Feb 2, 2026
1151c3e
Fix MacOS CI
daxpedda Feb 2, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# See https://github.com/oli-obk/ui_test/issues/177.
* text=auto eol=lf
32 changes: 32 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,35 @@ jobs:
llvm-version: 21
- name: Run Tests
run: cargo test --no-fail-fast

client:
name: Test Client ${{ matrix.os.description }}

runs-on: ${{ matrix.os.os }}

timeout-minutes: 10

strategy:
fail-fast: false
matrix:
os:
- { os: ubuntu-latest, description: Linux }
- { os: macos-latest, description: MacOS }
- { os: windows-latest, description: Windows }

defaults:
run:
working-directory: client

steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Rust
run: rustup target add wasm32-unknown-unknown
- name: Install LLVM
uses: ZhongRuoyu/setup-llvm@ec41d6e5f3c15c96fa642a49c6e7effac6261778
with:
# Rustc v1.93
llvm-version: 21
- name: Run Tests
run: cargo test --workspace --no-fail-fast
99 changes: 94 additions & 5 deletions TEST.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,106 @@
Manual testing commands until CI is set up:
Manual testing commands (CI not set up yet).

Quick build (from repo root):

```sh
cd client
cargo build --example basic
cargo build --example basic --release --timings
```

Test examples:

```rust
#[js_bindgen_test::test]
fn test_wasm() {}

#[js_bindgen_test::test]
#[ignore = "hah, it works"]
fn test_ignore() {
panic!("kaboom");
}

#[js_bindgen_test::test]
#[should_panic(expected = "kaboom")]
fn test_should_panic() {
panic!("kaboom");
}
```

Wasm tests: Node.js runner (default):

```sh
cargo test --target wasm32-unknown-unknown
```

Wasm tests: Browser runner (headless):

```sh
JBG_TEST_RUNNER=browser cargo test --target wasm32-unknown-unknown
```

Wasm tests: Browser server mode (open URL in a browser):

```sh
cargo build --example basic --release --timings && wasm-tools print -o examples/basic.wat target/wasm32-unknown-unknown/release/examples/basic.wasm && wasm-tools validate examples/basic.wat
JBG_TEST_RUNNER=server cargo test --target wasm32-unknown-unknown
```

Runner options:

- `JBG_TEST_RUNNER=nodejs` (run in Node.js)
- `JBG_TEST_RUNNER=deno` (run in Deno)

- `JBG_TEST_RUNNER=browser` (run in headless browser, auto detect WebDriver)
- `JBG_TEST_GECKODRIVER=<path>` (use Firefox)
- `JBG_TEST_CHROMEDRIVER=<path>` (use Chrome)
- `JBG_TEST_MSEDGEDRIVER=<path>` (use Edge)
- `JBG_TEST_WEBDRIVER_JSON` (set WebDriver conf)
- `JBG_TEST_WORKER=dedicated|shared|service`

- `JBG_TEST_RUNNER=server` (serve browser runner and print URL)
- `JBG_TEST_SERVER_ADDRESS=127.0.0.1:8000` (defaults to 8000; falls back to a random port if busy)

List and filter tests:

```sh
cargo test --target wasm32-unknown-unknown -- --list
cargo test --target wasm32-unknown-unknown -- --list --format terse
cargo test --target wasm32-unknown-unknown -- some_substring
cargo test --target wasm32-unknown-unknown -- --exact full::test::name
cargo test --target wasm32-unknown-unknown -- --ignored
```

Other test flags:

```sh
CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUSTFLAGS="-Ctarget-feature=+atomics -Clink-arg=--shared-memory -Clink-arg=--max-memory=4294967296" cargo +nightly build --example basic -Zbuild-std=panic_abort,std --release --timings && wasm-tools print -o examples/basic.wat target/wasm32-unknown-unknown/release/examples/basic.wasm && wasm-tools validate examples/basic.wat
cargo test --target wasm32-unknown-unknown -- --no-capture
```

Wasm tooling checks:

```sh
cd client
wasm-tools print -o examples/basic.wat target/wasm32-unknown-unknown/debug/examples/basic.wasm
wasm-tools validate examples/basic.wat
```

Shared-memory build (nightly):

```sh
cd client
CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUSTFLAGS="-Ctarget-feature=+atomics -Clink-arg=--shared-memory -Clink-arg=--max-memory=4294967296" \
cargo +nightly build --example basic -Zbuild-std=panic_abort,std --release --timings
```

Wasm64 builds (nightly):

```sh
cargo +nightly build --example basic --target wasm64-unknown-unknown -Zbuild-std=panic_abort,std --release --timings && wasm-tools print -o examples/basic.wat target/wasm64-unknown-unknown/release/examples/basic.wasm && wasm-tools validate examples/basic.wat
cd client
cargo +nightly build --example basic --target wasm64-unknown-unknown -Zbuild-std=panic_abort,std --release --timings
```

```sh
CARGO_TARGET_WASM64_UNKNOWN_UNKNOWN_RUSTFLAGS="-Ctarget-feature=+atomics -Clink-arg=--shared-memory -Clink-arg=--max-memory=17179869184" cargo +nightly build --example basic --target wasm64-unknown-unknown -Zbuild-std=panic_abort,std --release --timings && wasm-tools print -o examples/basic.wat target/wasm64-unknown-unknown/release/examples/basic.wasm && wasm-tools validate examples/basic.wat
cd client
CARGO_TARGET_WASM64_UNKNOWN_UNKNOWN_RUSTFLAGS="-Ctarget-feature=+atomics -Clink-arg=--shared-memory -Clink-arg=--max-memory=17179869184" \
cargo +nightly build --example basic --target wasm64-unknown-unknown -Zbuild-std=panic_abort,std --release --timings
```
25 changes: 25 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,28 @@

# High Priority

- Test Runner:
- Add various permutations to the CI.
- Run all possible runners on each OS.
- Run all worker types.
- Wasm64.
- Atomic.
- Panic strategies.
- Run tests in alphabetical order to mimic `libtest`.
- Convert JS files to TS, then compile and lint them. Compiling and linting could be built into
the runner shim to ensure freshness. Don't forget to exclude the TS files from packaging.
- Add support for `--test-threads` and multithread tests where possible for `panic = "abort"`.
- Add support for `panic = "unwind"`.
- Add support for `--force-run-in-process`.
- Add support for `--skip`, `--quiet`, `--show-output`, `--color` and `--format pretty`.
- E2E testing including output comparison with regular `cargo test`. Test output on failure
especially carefully.
- Design a way to let users set the default driver, overwrite and whitelist drivers globally or
for specific tests.
- Add multithread support when running with `target_feature = "atomics"` where possible.
- Crate feature to switch to `native-tls`.
- Add environment variable to set driver startup timeout.
- Properly emit errors when WebDrivers fail between startup and finish.
- E2E testing for the linker. Should also ensure deterministic output.
- Add a `disable_hygiene` attribute to `#[js_sys]` to reduce the compile-time of the output to an
absolute minimum. This can avoid all `interpolate`s.
Expand Down Expand Up @@ -39,6 +61,9 @@
This seems to have failed. No build script instruction can reach the linker on Wasm.
- Memory-mapped file reading should lock files to make it safe.

[Fantoccini]: https://crates.io/crates/fantoccini
[Thirtyfour]: https://crates.io/crates/thirtyfour

# Medium Priority

- Find a way to link to imports directly if no wrapper function is needed. This happens when no
Expand Down
File renamed without changes.
5 changes: 2 additions & 3 deletions linker-shim/linker.cmd → cargo-shim/linker.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
:; # Lines starting with `:;` are ignored on Windows but are executed on UNIX.
:; (
:; cd "$(dirname "$0")/../host" || exit 1
:; cargo +stable run -q -p js-bindgen-ld -- "$@"
:; )
:; exit $?
:; cargo +stable run -q -p js-bindgen-ld -- "$@"; exit $?
:; ); exit $?

:: Windows
:: Never reached on UNIX because we execute `exit`.
Expand Down
17 changes: 17 additions & 0 deletions cargo-shim/runner.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env -S DUMMY=2>NUL sh
:; # A very quirky solution to make things run cross-platform.

:; # UNIX
:; # Lines starting with `:;` are ignored on Windows but are executed on UNIX.
:; (
:; cd "$(dirname "$0")/../host" || exit 1
:; cargo +stable run -q -p js-bindgen-runner -- "$@"; exit $?
:; ); exit $?

:: Windows
:: Never reached on UNIX because we execute `exit`.
@echo off
pushd "%~dp0..\host" || exit /b 1
cargo +stable run -q -p js-bindgen-runner -- %*
popd
exit /b %ERRORLEVEL%
3 changes: 2 additions & 1 deletion client/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
target = "wasm32-unknown-unknown"

[target.'cfg(all(target_family = "wasm", any(target_os = "none", target_os = "unknown")))']
linker = "../linker-shim/linker.cmd"
linker = "../cargo-shim/linker.cmd"
runner = "../cargo-shim/runner.cmd"
10 changes: 9 additions & 1 deletion client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["js-sys", "web-sys"]
members = ["js-bindgen-test", "js-sys", "web-sys"]
resolver = "2"

[workspace.package]
Expand All @@ -9,6 +9,8 @@ rust-version = "1.85"

[workspace.dependencies]
js-bindgen = { path = "../host/js-bindgen" }
js-bindgen-test = { path = "js-bindgen-test" }
js-bindgen-test-macro = { path = "../host/js-bindgen-test-macro" }
js-sys = { path = "js-sys" }
js-sys-macro = { path = "../host/js-sys-macro" }
mini-alloc = "1"
Expand All @@ -31,6 +33,12 @@ name = "basic"
[workspace.lints.rust]
linker_messages = "warn"

[workspace.lints.clippy]
obfuscated_if_else = "allow"
tabs_in_doc_comments = "allow"
undocumented_unsafe_blocks = "warn"
use_self = "warn"

[lints]
workspace = true

Expand Down
2 changes: 1 addition & 1 deletion client/examples/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<title>Basic Example</title>
<link rel="icon" href="data:," />
<script type="module">
import { importObject } from "../target/wasm32-unknown-unknown/release/examples/basic.js"
import { importObject } from "../target/wasm32-unknown-unknown/release/examples/basic.mjs"

const { module, instance } = await WebAssembly.instantiateStreaming(
fetch("../target/wasm32-unknown-unknown/release/examples/basic.wasm"),
Expand Down
12 changes: 12 additions & 0 deletions client/js-bindgen-test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
edition = { workspace = true }
name = "js-bindgen-test"
rust-version = { workspace = true }

[dependencies]
js-bindgen = { workspace = true }
js-bindgen-test-macro = { workspace = true }
js-sys = { workspace = true }

[lints]
workspace = true
53 changes: 53 additions & 0 deletions client/js-bindgen-test/src/lib.rs
Comment thread
Spxg marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use std::panic::PanicHookInfo;

use js_sys::JsString;

pub use js_bindgen_test_macro::test;

js_bindgen::embed_js!(
name = "panic.set_message",
"(message) => {{",
" globalThis.PanicMessage = String(message);",
"}}"
);

js_bindgen::embed_js!(
name = "panic.set_payload",
"(payload) => {{",
" globalThis.PanicPayload = String(payload);",
"}}"
);

#[js_sys::js_sys(js_sys = js_sys)]
extern "C" {
#[js_sys(js_embed = "panic.set_message")]
fn set_panic_message(message: &JsString);

#[js_sys(js_embed = "panic.set_payload")]
fn set_panic_payload(payload: &JsString);
}

pub fn set_panic_hook() {
// TODO: Bump msrv rustc to 1.91.0 and remove this func
fn payload_as_str<'a>(info: &'a PanicHookInfo) -> Option<&'a str> {
if let Some(s) = info.payload().downcast_ref::<&str>() {
Some(s)
} else if let Some(s) = info.payload().downcast_ref::<String>() {
Some(s)
} else {
None
}
}

static HOOK: std::sync::Once = std::sync::Once::new();

HOOK.call_once(|| {
std::panic::set_hook(Box::new(|info| {
let message = info.to_string();
set_panic_message(&JsString::from_str(&message));
if let Some(payload) = payload_as_str(info) {
set_panic_payload(&JsString::from_str(payload));
}
}));
});
}
6 changes: 6 additions & 0 deletions client/web-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@ rust-version = { workspace = true }

[dependencies]
js-sys = { workspace = true }

[dev-dependencies]
js-bindgen-test = { workspace = true }

[lints]
workspace = true
33 changes: 33 additions & 0 deletions client/web-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
pub use js_sys;
use js_sys::JsValue;

/// ```rust
/// # #[js_bindgen_test::test]
/// # fn doctest() {
/// let log = js_sys::JsString::from_str("hello world");
/// web_sys::console::log(&log);
/// # }
/// ````
pub mod console {
use super::*;

Expand All @@ -17,3 +24,29 @@ pub mod console {
pub fn log2(data1: &JsValue, data2: &JsValue);
}
}

#[cfg(test)]
mod tests {
use js_bindgen_test::test;
use js_sys::JsString;

use super::console;

#[test]
fn test_console_log() {
let value = JsString::from_str("hello world");
console::log(&value);
}

#[test]
#[ignore = "hah, it works"]
fn test_ignore() {
panic!("kaboom");
}

#[test]
#[should_panic(expected = "kaboom")]
fn test_should_panic() {
panic!("kaboom");
}
}
Loading