Skip to content

Commit 2676fe6

Browse files
committed
feat: Add an example for gloo-history on WASI.
1 parent 9f6d39f commit 2676fe6

File tree

5 files changed

+68
-9
lines changed

5 files changed

+68
-9
lines changed

.github/workflows/tests.yml

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Tests
33
on:
44
pull_request:
55
push:
6-
branches: [ master ]
6+
branches: [master]
77

88
jobs:
99
native_tests:
@@ -119,14 +119,48 @@ jobs:
119119
wasm-pack test --node crates/$x --no-default-features
120120
done
121121
122+
test-history-wasi:
123+
name: Test gloo-history WASI
124+
runs-on: ubuntu-latest
125+
strategy:
126+
fail-fast: false
127+
matrix:
128+
example: [history-wasi]
129+
rust-version: [1.64, stable, nightly]
130+
steps:
131+
- uses: actions/checkout@v4
132+
- uses: dtolnay/rust-toolchain@master
133+
with:
134+
toolchain: ${{ matrix.rust-version }}
135+
target: wasm32-wasi
136+
137+
- name: Install wasmtime
138+
run: curl https://wasmtime.dev/install.sh -sSf | bash
139+
140+
- uses: actions/cache@v3
141+
with:
142+
path: |
143+
~/.cargo/registry
144+
~/.cargo/git
145+
target
146+
key: cargo-${{ runner.os }}-wasi-tests-${{ hashFiles('**/Cargo.toml') }}
147+
restore-keys: |
148+
cargo-${{ runner.os }}-wasi-tests-
149+
cargo-${{ runner.os }}-
150+
151+
- name: Build and run example history-wasi
152+
run: |
153+
cargo build -p example-${{ matrix.example }} --target wasm32-wasi
154+
wasmtime target/wasm32-wasi/debug/example-${{ matrix.example }}.wasm
155+
122156
test-worker:
123157
name: Test gloo-worker
124158
runs-on: ubuntu-latest
125159
strategy:
126160
fail-fast: false
127161
matrix:
128162
# example: [ markdown, prime ]
129-
example: [ markdown ]
163+
example: [markdown]
130164
rust-version: [1.64, stable, nightly]
131165
steps:
132166
- uses: actions/checkout@v4
@@ -167,7 +201,6 @@ jobs:
167201
run: |
168202
wasm-pack test --headless --chrome --firefox examples/${{ matrix.example }}
169203
170-
171204
test-net:
172205
strategy:
173206
fail-fast: false
@@ -208,9 +241,9 @@ jobs:
208241
209242
- name: Run browser tests
210243
env:
211-
HTTPBIN_URL: "http://localhost:8080"
212-
WS_ECHO_SERVER_URL: "ws://localhost:8081"
213-
SSE_ECHO_SERVER_URL: "http://localhost:8081/.sse"
244+
HTTPBIN_URL: 'http://localhost:8080'
245+
WS_ECHO_SERVER_URL: 'ws://localhost:8081'
246+
SSE_ECHO_SERVER_URL: 'http://localhost:8081/.sse'
214247
run: |
215248
cd crates/net
216249
wasm-pack test --chrome --firefox --headless --all-features
@@ -222,7 +255,7 @@ jobs:
222255

223256
- name: Run native tests
224257
env:
225-
HTTPBIN_URL: "http://localhost:8080"
226-
WS_ECHO_SERVER_URL: "ws://localhost:8081"
227-
SSE_ECHO_SERVER_URL: "http://localhost:8081/.sse"
258+
HTTPBIN_URL: 'http://localhost:8080'
259+
WS_ECHO_SERVER_URL: 'ws://localhost:8081'
260+
SSE_ECHO_SERVER_URL: 'http://localhost:8081/.sse'
228261
run: cargo test -p gloo-net --all-features

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ members = [
7777
"examples/markdown",
7878
"examples/clock",
7979
"examples/file-hash",
80+
"examples/history-wasi",
8081
"examples/prime",
8182
]
8283

examples/history-wasi/Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "example-history-wasi"
3+
version = "0.1.0"
4+
authors = ["Rust and WebAssembly Working Group"]
5+
edition = "2021"
6+
publish = false
7+
rust-version = "1.64"
8+
9+
[dependencies]
10+
gloo = { path = "../..", default-features = false, features = ["history"] }

examples/history-wasi/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# History example on WASI
2+
3+
This is a simple example showcasing the Gloo History on WASI.
4+
5+
You can run this example with `cargo wasi run --package example-history-wasi`

examples/history-wasi/src/main.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use gloo::history::{History, MemoryHistory};
2+
3+
fn main() {
4+
let history = MemoryHistory::new();
5+
history.push("/home");
6+
history.push("/about");
7+
history.push("/contact");
8+
history.go(-2);
9+
assert_eq!(history.location().path(), "/home");
10+
}

0 commit comments

Comments
 (0)