Skip to content

Commit f38d13d

Browse files
committed
feat: add WASM unit tests with browser execution (fixes #73)
- Add 20 WASM integration tests running in headless Chrome - Add 10 native Unix error handling tests with mock FFI - Add Windows error handling test infrastructure - Add CI job for automated WASM testing - Add wasm-bindgen-test dev dependency
1 parent 322405c commit f38d13d

File tree

8 files changed

+2036
-1
lines changed

8 files changed

+2036
-1
lines changed

.github/workflows/ci.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,33 @@ jobs:
136136
- run: cargo update
137137
- run: cargo build --no-default-features --target=${{ matrix.cc }}
138138
- run: RUSTFLAGS="--cfg daku" cargo build --target=${{ matrix.cc }}
139+
test-wasm:
140+
runs-on: ubuntu-latest
141+
strategy:
142+
matrix:
143+
tc: [stable, nightly]
144+
steps:
145+
- uses: taiki-e/checkout-action@v1
146+
- uses: taiki-e/install-action@v2
147+
- name: Install wasm-pack
148+
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
149+
- name: Setup Chrome for headless testing
150+
uses: browser-actions/setup-chrome@latest
151+
- run: rustup set profile minimal
152+
- run: rustup toolchain install ${{ matrix.tc }}
153+
- run: rustup target add wasm32-unknown-unknown
154+
- name: Run WASM tests in headless browser
155+
run: |
156+
cd whoami
157+
wasm-pack test --headless --chrome --all-features
158+
- name: Run WASM tests for web feature
159+
run: |
160+
cd whoami
161+
wasm-pack test --headless --chrome --features web
162+
- name: Run WASM tests without default features
163+
run: |
164+
cd whoami
165+
wasm-pack test --headless --chrome --no-default-features
139166
cross-compile-illumos:
140167
runs-on: ${{ matrix.os }}
141168
strategy:

Cargo.lock

Lines changed: 178 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

whoami/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,12 @@ version = "0.1.0"
3636
# Target-specific dependency for web browser
3737
[target.'cfg(all(target_arch = "wasm32", not(target_os = "wasi"), not(daku)))'.dependencies.web-sys]
3838
version = "0.3.77"
39-
features = ["Navigator", "Document", "Window", "Location"]
39+
features = ["Navigator", "Document", "Window", "Location", "console"]
4040
optional = true
4141

42+
[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
43+
wasm-bindgen-test = "0.3"
44+
4245
[features]
4346
default = ["web"]
4447
# Enabling this feature indicates that the wasm32-unknown-unknown target should

0 commit comments

Comments
 (0)