Repository navigation
Implement js-bindgen test runner #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
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 d20f61b
Remove js panic stack output
Spxg 2d14d14
Add error stack output
Spxg 558458a
Format tomls
Spxg 3eae2dc
Clean up
Spxg 479b66f
Update console capture
Spxg 956cea7
Add COPE/COOP headers
Spxg 83b715d
Clean up
Spxg 14ff66e
Add console hook
Spxg d74ca8f
Fix warning
Spxg 75dfc98
Add client test workflow
Spxg 2724ab2
Update runner shim
Spxg 45345f8
Fix cargo format
Spxg 827d104
No alias
Spxg b2bfe58
Update workflow
Spxg ea2b08f
Efficient parse arguments
Spxg c466541
Add const for ascii color
Spxg 5b4b16c
Clean up
Spxg b3480f4
Rename to `js-bindgen-runner`
Spxg 7999676
Clean up
Spxg d27f21a
Update workflow
Spxg 10d241d
Rename env
Spxg b456568
Reduce read
Spxg 3096d69
Mmap
Spxg cc01b38
Update driver and worker parse
Spxg a732330
Read tests by path
Spxg 112de9f
Add comment
Spxg 2542527
Move tempfile to workspace
Spxg 9a2c2b7
Replace the code of creating js file
Spxg 41ac558
Nits
daxpedda d8e7159
Format
daxpedda 6041a5a
Slight Improvements
daxpedda 4ae9de6
Init instance for each test
Spxg 019e61f
Use clap to parse args
Spxg 273c4f5
typo
Spxg 8be4f64
Use axum
Spxg 09a71d2
Add doctest
Spxg a7f73aa
Random Improvements
daxpedda 5aa21b3
Run Taplo
daxpedda edf2a58
Use Fantoccini
Spxg d394eb8
Fix node no capture
Spxg f06c077
Add no-capture alias
Spxg f7b4203
Close browser for safari
Spxg c7fa17c
Clean up
Spxg 1a369bd
Clean up
Spxg 604abc5
Clean up
Spxg b802a6b
Clean up
Spxg a96def9
Clean up
Spxg a144628
Clean up
Spxg 317e7e2
Use `JBG_TEST_RUNNER`
Spxg 7cefb13
Add deno support
Spxg 1749f45
Update TEST.md
Spxg d3703ee
JS panic handler
Spxg 5d47596
Kill process when guard drop
Spxg 4695cd8
Format
Spxg 5f7f5dd
Add More TODOs
daxpedda 674f1de
Remove unused option
Spxg c478aac
Remove duplicated todo
Spxg 105d4e3
Cleanup
daxpedda e703546
Cleanup
Spxg 9549ccf
Passing arguments to Node and Deno via command arguments
Spxg 7fd2e7b
Use webdriver to get output
Spxg d7f2352
Remove parking_lot
Spxg b8a15e8
Fix shared worker
Spxg 6db8362
Clean up
Spxg f8c7bc7
Add env prefix
Spxg 2563357
Better WebDriver Error Handling
daxpedda e1abb9d
Clean up
Spxg 560cf43
Run Prettier
daxpedda 9e978f8
Move `js` Folder to `src`
daxpedda 1a9c984
Move and Rename Some Stuff
daxpedda 7cb347c
Fix Windows Tests
daxpedda 1151c3e
Fix MacOS CI
daxpedda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)); | ||
| } | ||
| })); | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.