diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index af61ec86..7cb13225 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -76,12 +76,51 @@ jobs: wasm-pack test --headless --firefox --chrome crates/$x --no-default-features done - - name: Run tests for gloo worker + + + test-worker: + name: Test gloo-worker + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + target: wasm32-unknown-unknown + override: true + profile: minimal + + - name: Install wasm-pack + run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh + + - name: Setup trunk + uses: jetli/trunk-action@v0.1.0 + with: + version: 'latest' + + - uses: actions/cache@v2 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + target + key: cargo-${{ runner.os }}-browser-tests-${{ hashFiles('**/Cargo.toml') }} + restore-keys: | + cargo-${{ runner.os }}-test-worker- + cargo-${{ runner.os }}- + + - name: Build and Run Test Server + run: | + cargo build -p example-markdown --bin example_markdown_test_server + nohup target/debug/example_markdown_test_server examples/markdown/dist & + + - name: Build Test Worker run: | trunk build examples/markdown/index.html - nohup cargo run -p example-markdown --bin example_markdown_test_server -- examples/markdown/dist & - wasm-pack test --headless --firefox --chrome examples/markdown + - name: Run tests for gloo worker + run: | + wasm-pack test --headless --firefox --chrome examples/markdown test-net: diff --git a/examples/markdown/src/bin/example_markdown_test_server.rs b/examples/markdown/src/bin/example_markdown_test_server.rs index 9b34852b..a880ce3a 100755 --- a/examples/markdown/src/bin/example_markdown_test_server.rs +++ b/examples/markdown/src/bin/example_markdown_test_server.rs @@ -1,5 +1,6 @@ #![cfg(not(target_arch = "wasm32"))] +use warp::reply::with_header; use warp::Filter; // This server is purely to faclitate testing. @@ -10,14 +11,18 @@ use warp::Filter; async fn main() { let dir = std::env::args().nth(1).expect("expected a target dir."); - let route = warp::fs::dir(dir).with( - // We need a server that serves the request with cross origin resource sharing. - warp::cors() - .allow_method("GET") - .allow_method("HEAD") - .allow_method("OPTIONS") - .allow_any_origin(), - ); + let route = warp::fs::dir(dir) + .with( + // We need a server that serves the request with cross origin resource sharing. + warp::cors() + .allow_method("GET") + .allow_method("HEAD") + .allow_method("OPTIONS") + .allow_any_origin(), + ) + .map(|m| with_header(m, "cross-origin-resource-policy", "cross-origin")); + + println!("Test server is running at: http://127.0.0.1:9999/"); warp::serve(route).run(([127, 0, 0, 1], 9999)).await; }