8000 ci(browser): run the BrowserDb tests in Firefox, Chrome and Safari on main by adityamukho · Pull Request #906 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: Lint
# is installed. Clippy lints the library and binary with every feature; tests,
# examples and benches are not linted (the panic-prevention lints in Cargo.toml
# would need thousands of changes there). A separate job lints the browser
# library on wasm32, including code that native builds do not compile.
# library on wasm32; wasm.yml runs the browser tests.

on:
push:
Expand Down
68 changes: 68 additions & 0 deletions .github/workflows/wasm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: WASM

# Core's BrowserDb and IndexedDB tests only compile with the browser feature
# on wasm32, so native CI never runs them. v2 supports main-thread tests only.

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

env:
CARGO_TERM_COLOR: always

permissions:
contents: read

jobs:
browser:
name: Browser tests (headless ${{ matrix.browser }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
# Both browsers and their WebDriver binaries are preinstalled on
# ubuntu-latest; wasm-pack finds them on PATH.
browser: [firefox, chrome]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown
- name: Install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- name: wasm-bindgen tests (lib, incl. BrowserDb and IndexedDB)
run: wasm-pack test --headless --${{ matrix.browser }} --features browser

safari:
name: Safari tests (main thread)
# Real Safari through safaridriver. Safari has no headless mode; the
# hosted runner's GUI session runs it. Private windows cannot be opened
# over WebDriver, so Safari private browsing is not covered here.
runs-on: macos-15
env:
WASM_BINDGEN_TEST_TIMEOUT: 180
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown
- name: Install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
# The test runner's own safaridriver launch times out on hosted runners
# ("driver failed to bind port"), so start it here and point the runner
# at it with SAFARIDRIVER_REMOTE.
- name: Start safaridriver
run: |
sudo safaridriver --enable
safaridriver -p 4444 &
for _ in $(seq 1 60); do
curl -sf http://127.0.0.1:4444/status >/dev/null && exit 0
sleep 1
done
echo "::error::safaridriver did not start"; exit 1
- name: wasm-bindgen tests in Safari
env:
SAFARIDRIVER_REMOTE: http://127.0.0.1:4444
run: wasm-pack test --headless --safari --features browser
31 changes: 28 additions & 3 deletions docs/TEST_COVERAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,32 @@ The **26 `BrowserDb` wasm-bindgen tests** (12 existing, 14 added for #894) run
only on wasm32 in a browser and are not in the native counts above. All 26 passed
in headless Firefox on 2026-11-18.

`.github/workflows/wasm.yml` runs these tests on pushes and pull requests to
`main`: headless Firefox and Chrome on Ubuntu, and real Safari through
`safaridriver` on `macos-15`. All three lanes run on the main thread. v2 has no
`minigraf_browser_worker` cfg or OPFS/worker mode, so there are no worker lanes.
Safari uses the hosted runner's GUI session; private browsing is not covered.

Run locally with Rust's `wasm32-unknown-unknown` target, `wasm-pack`, and the
chosen browser installed (with its WebDriver on `PATH` or installed by wasm-pack):

```bash
wasm-pack test --headless --firefox --features browser
wasm-pack test --headless --chrome --features browser
# macOS: enable Safari remote automation first.
sudo safaridriver --enable
wasm-pack test --headless --safari --features browser
```

The Safari `--headless` flag selects wasm-bindgen's automated WebDriver runner;
Safari itself opens a visible window. CI starts `safaridriver` separately and
sets `SAFARIDRIVER_REMOTE` to avoid the hosted runner's driver startup timeout.
Native-only file and WAL tests are cfg-gated off wasm32, so the standard
wasm-pack command can compile all test targets without the native `tempfile`
dev-dependency. Native `cargo test` still runs those tests.
The PID-namespace example helper also compiles with an empty main on wasm32,
as the other native-only examples do.

- The IndexedDB flush returns every page a write dirtied.
- A dirty page that cannot be read is an error rather than left out.
- A parse, query and transact error reject with their codes (`PRS-011`, `QRY-007`, `PRS-046`), as on the native API (#673).
Expand Down Expand Up @@ -189,9 +215,8 @@ cargo build
python3 scripts/check_browser_exports.py target/browser-exports.log target/debug/minigraf
```

`wasm-pack test --headless --firefox --features browser` currently also compiles
native-only integration tests that call `Minigraf::open`, unavailable on wasm.
The direct library runner above exercises the browser suite without those tests.
The direct library runner above is for opt-in recovery-export verification;
the standard browser test run uses wasm-pack as shown above.

Before the production fix, the abort-only regression failed at its 1.5-second
deadline (`deadline: flush did not settle`), and the multi-page regression failed
Expand Down
4 changes: 4 additions & 0 deletions examples/pid_ns_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
//! release by the library, nothing but whatever the kernel does on its own.
//! That is the exact state #317 is about.

#[cfg(target_arch = "wasm32")]
fn main() {}

#[cfg(not(target_arch = "wasm32"))]
fn main() {
let args: Vec<String> = std::env::args().collect();
let path = &args[1];
Expand Down
1 change: 1 addition & 0 deletions tests/error_codes_foundation_test.rs
10BC8
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ fn in_memory_open_returns_ok() {
}

#[test]
#[cfg(not(target_arch = "wasm32"))]
fn open_nonexistent_directory_returns_coded_error() {
let bad_path = "/nonexistent-dir-for-minigraf-test-277/db.graph";
let result = Minigraf::open(bad_path);
Expand Down
2 changes: 2 additions & 0 deletions tests/error_codes_storage_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
//! directly — see the unit tests inside `src/storage/*.rs` for codes that
//! are only reachable at that lower level).

#![cfg(not(target_arch = "wasm32"))] // Minigraf::open requires the native file backend.

use minigraf::{ErrorCategory, Minigraf};
use std::io::Write;

Expand Down
2 changes: 2 additions & 0 deletions tests/error_codes_wal_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
//! no way to trigger them from the public API without an unrealistic (multi-GB)
//! fixture, so they are intentionally not exercised here.

#![cfg(not(target_arch = "wasm32"))] // File-backed WAL tests use native-only tempfile.

use minigraf::{ErrorCategory, Minigraf, OpenOptions};
use std::io::Write;

Expand Down
Loading
0