gloo 0.12.0

A modular toolkit for Rust and WebAssembly
name: Tests

on:
  pull_request:
  push:
    branches: [master]

jobs:
  native_tests:
    strategy:
      fail-fast: false
      matrix:
        rust-version: [1.82, stable, nightly]
    name: Native Tests
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ matrix.rust-version }}

      - uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: cargo-${{ runner.os }}-native-tests-${{ hashFiles('**/Cargo.toml') }}
          restore-keys: |
            cargo-${{ runner.os }}-doc-tests-
            cargo-${{ runner.os }}-

      - name: Run tests
        run: cargo test --workspace --exclude gloo-net

  browser_tests:
    strategy:
      fail-fast: false
      matrix:
        rust-version: [1.82, stable, nightly]
    name: Browser Tests
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ matrix.rust-version }}
          target: wasm32-unknown-unknown

      - 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.5.1
        with:
          version: 'latest'

      - uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: cargo-${{ runner.os }}-browser-tests-${{ hashFiles('**/Cargo.toml') }}
          restore-keys: |
            cargo-${{ runner.os }}-browser-tests-
            cargo-${{ runner.os }}-

      - name: Run tests
        run: |
          for x in $(ls crates); do
            # gloo-net is tested separately
            if [[ "$x" == "net" ]]; then
              continue
            fi
            if [[ "$x" == "worker-macros" ]]; then
              continue
            fi
            wasm-pack test --headless --firefox --chrome crates/$x --all-features
            wasm-pack test --headless --firefox --chrome crates/$x --no-default-features
          done

  node_tests:
    strategy:
      fail-fast: false
      matrix:
        rust-version: [1.82, stable, nightly]
    name: Node Tests
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ matrix.rust-version }}
          target: wasm32-unknown-unknown

      - name: Install wasm-pack
        run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh

      - uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: cargo-${{ runner.os }}-node-tests-${{ hashFiles('**/Cargo.toml') }}
          restore-keys: |
            cargo-${{ runner.os }}-node-tests-
            cargo-${{ runner.os }}-

      - name: Run tests
        run: |
          for x in $(ls crates); do
            # gloo-net is tested separately
            if [[ "$x" == "net" ]]; then
              continue
            fi
            wasm-pack test --node crates/$x --all-features
            wasm-pack test --node crates/$x --no-default-features
          done

  test-history-wasi:
    name: Test gloo-history WASI
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        rust-version: [1.82, stable, nightly]
    steps:
      - uses: actions/checkout@v6
      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ matrix.rust-version }}
          target: wasm32-wasip1

      - name: Install wasmtime
        run: |
          wget https://github.com/bytecodealliance/wasmtime/releases/download/v43.0.0/wasmtime-v43.0.0-x86_64-linux.tar.xz
          tar xf wasmtime-v43.0.0-x86_64-linux.tar.xz
          mv wasmtime-v43.0.0-x86_64-linux/wasmtime ~/wasmtime
          rm -rf wasmtime-v43.0.0-x86_64-linux.tar.xz wasmtime-v43.0.0-x86_64-linux
          chmod +x ~/wasmtime

      - uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: cargo-${{ runner.os }}-node-tests-${{ hashFiles('**/Cargo.toml') }}
          restore-keys: |
            cargo-${{ runner.os }}-node-tests-
            cargo-${{ runner.os }}-

      - name: Build and run example history-wasi
        run: |
          cargo build --package example-history-wasi --target wasm32-wasip1
          ~/wasmtime run -W unknown-imports-trap target/wasm32-wasip1/debug/example-history-wasi.wasm

  test-worker:
    name: Test gloo-worker
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        # example: [ markdown, prime ]
        example: [markdown]
        rust-version: [1.82, stable, nightly]
    steps:
      - uses: actions/checkout@v6
      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ matrix.rust-version }}
          target: wasm32-unknown-unknown

      - 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.5.1
        with:
          version: 'latest'

      - uses: actions/cache@v4
        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 Test Worker
        run: |
          trunk build --dist examples/${{ matrix.example }}/dist examples/${{ matrix.example }}/index.html

      - name: Build and Run Test Server
        run: |
          cargo build -p example-${{ matrix.example }} --bin example_${{ matrix.example }}_test_server
          nohup target/debug/example_${{ matrix.example }}_test_server examples/${{ matrix.example }}/dist &

      - name: Run tests for gloo worker
        run: |
          wasm-pack test --headless --chrome --firefox  examples/${{ matrix.example }}

  test-net:
    strategy:
      fail-fast: false
      matrix:
        rust-version: [1.82, stable, nightly]
    name: Test gloo-net
    runs-on: ubuntu-latest
    services:
      httpbin:
        image: kennethreitz/httpbin@sha256:599fe5e5073102dbb0ee3dbb65f049dab44fa9fc251f6835c9990f8fb196a72b
        ports:
          - 8080:80
      echo_server:
        image: jmalloc/echo-server@sha256:e43a10c9ecbd025df7ed6dac1e45551ce7bd676142600b0734fe7dcd10a47abe
        ports:
          - 8081:8080

    steps:
      - uses: actions/checkout@v6
      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: stable
          target: wasm32-unknown-unknown

      - name: Install wasm-pack
        run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh

      - uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: cargo-${{ runner.os }}-test-${{ hashFiles('**/Cargo.toml') }}
          restore-keys: |
            cargo-${{ runner.os }}-test-
            cargo-${{ runner.os }}-

      - name: Run browser tests
        env:
          HTTPBIN_URL: 'http://localhost:8080'
          WS_ECHO_SERVER_URL: 'ws://localhost:8081'
          SSE_ECHO_SERVER_URL: 'http://localhost:8081/.sse'
        run: |
          cd crates/net
          wasm-pack test --chrome --firefox --headless --features=default,io-util,browser-test

      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ matrix.rust-version }}
          target: wasm32-unknown-unknown

      - name: Run native tests
        env:
          HTTPBIN_URL: 'http://localhost:8080'
          WS_ECHO_SERVER_URL: 'ws://localhost:8081'
          SSE_ECHO_SERVER_URL: 'http://localhost:8081/.sse'
        run: cargo test -p gloo-net --features=default,io-util

      - name: Run node tests
        env:
          HTTPBIN_URL: 'http://localhost:8080'
          WS_ECHO_SERVER_URL: 'ws://localhost:8081'
          SSE_ECHO_SERVER_URL: 'http://localhost:8081/.sse'
        run: wasm-pack test --node crates/net --features=default,io-util