Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpedda committed Dec 8, 2024
1 parent 0045d6b commit 8ef40bc
Show file tree
Hide file tree
Showing 13 changed files with 116 additions and 229 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/coverage-documentation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
coverage:
name: Test Coverage ${{ matrix.mt.description }} ${{ matrix.features.description }}

runs-on: ubuntu-latest
runs-on: ubuntu-24.04

timeout-minutes: 10

Expand Down Expand Up @@ -67,6 +67,7 @@ jobs:
run: echo "BUILD_STD_COMPONENTS=-Zbuild-std=core,alloc" >> $GITHUB_ENV
- name: Test
env:
#WASM_BINDGEN_USE_BROWSER: 1
CHROMEDRIVER: chromedriver
run: |
mkdir coverage-output
Expand Down
145 changes: 41 additions & 104 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,20 @@ env:
jobs:
test:
name:
Test ${{ matrix.target.description }} ${{ matrix.rust.description }} ${{
matrix.features.description }}
Test ${{ matrix.driver.description }} ${{ matrix.environment.description }} ${{
matrix.rust.description }} ${{ matrix.features.description }}

runs-on: ${{ matrix.target.os }}
runs-on: ${{ matrix.driver.os }}

timeout-minutes: 10

strategy:
fail-fast: false
matrix:
target:
- {
os: ubuntu-latest,
target: wasm32-unknown-unknown,
description: Chrome,
name: CHROMEDRIVER,
value: chromedriver,
}
- {
os: ubuntu-latest,
target: wasm32-unknown-unknown,
description: Firefox,
name: GECKODRIVER,
value: geckodriver,
}
- {
os: macos-latest,
target: wasm32-unknown-unknown,
description: Safari,
name: SAFARIDRIVER,
value: safaridriver,
}
- { target: wasm32-unknown-unknown, docargs: -Zdoctest-xcompile }
rust:
- { version: stable }
- { version: nightly }
- {
version: nightly,
description: with Atomics,
Expand All @@ -59,100 +39,57 @@ jobs:
features:
- { features: "", no_std: false }
- { features: --no-default-features, no_std: true, description: "(`no_std`)" }
include:
- target:
{
os: ubuntu-latest,
target: x86_64-unknown-linux-gnu,
description: Native,
native: true,
}
rust: { version: stable }
features: { features: "", no_std: false }

steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install `wasm-bindgen-cli`
uses: taiki-e/install-action@v2
with:
tool: wasm-bindgen-cli
- name: Install Rust
run: |
rustup toolchain install ${{ matrix.rust.version }} --profile minimal ${{ matrix.rust.component }} --target ${{ matrix.target.target }}
rustup default ${{ matrix.rust.version }}
- name: Set `build-std` components
if: matrix.rust.build-std == true && matrix.features.no_std == false
run: echo "BUILD_STD_COMPONENTS=-Zbuild-std=panic_abort,std" >> $GITHUB_ENV
- name: Set `build-std` `no_std` components
if: matrix.rust.build-std == true && matrix.features.no_std == true
run: echo "BUILD_STD_COMPONENTS=-Zbuild-std=core,alloc" >> $GITHUB_ENV
- name: Set Driver
if: matrix.target.native == false
run: echo "${{ matrix.target.name }}=${{ matrix.target.value }}" >> $GITHUB_ENV
- name: Test
env:
RUSTFLAGS: ${{ matrix.rust.flags }}
run:
cargo test --features serde ${{ matrix.features.features }} --target ${{
matrix.target.target }} $BUILD_STD_COMPONENTS --workspace

doctest:
name:
Doctest ${{ matrix.target.description }} ${{ matrix.rust.description }} ${{
matrix.features.description }}

runs-on: ${{ matrix.target.os }}

timeout-minutes: 10

strategy:
fail-fast: false
matrix:
target:
driver:
- {
os: ubuntu-latest,
target: wasm32-unknown-unknown,
description: Chrome,
name: CHROMEDRIVER,
value: chromedriver,
browser: true,
}
- {
os: ubuntu-latest,
target: wasm32-unknown-unknown,
description: Firefox,
name: GECKODRIVER,
value: geckodriver,
browser: true,
firefox: true,
}
- {
os: macos-latest,
target: wasm32-unknown-unknown,
description: Safari,
name: SAFARIDRIVER,
value: safaridriver,
browser: true,
}
rust:
- { version: nightly }
- { os: ubuntu-24.04, description: Node.js, nodejs: true }
environment:
- { name: WASM_BINDGEN_USE_BROWSER, browser: true }
- {
version: nightly,
description: with Atomics,
component: --component rust-src,
flags: "-Ctarget-feature=+atomics,+bulk-memory",
build-std: true,
description: Dedicated Worker,
name: WASM_BINDGEN_USE_DEDICATED_WORKER,
browser: true,
}
features:
- { features: "", no_std: false }
- { features: --no-default-features, no_std: true, description: "(`no_std`)" }
- { description: Shared Worker, name: WASM_BINDGEN_USE_SHARED_WORKER, browser: true }
- {
description: Service Worker,
name: WASM_BINDGEN_USE_SERVICE_WORKER,
browser: true,
service-worker: true,
}
- { browser: false }
include:
- target:
{
os: ubuntu-latest,
target: x86_64-unknown-linux-gnu,
description: Native,
native: true,
}
- target: { target: x86_64-unknown-linux-gnu }
rust: { version: stable }
features: { features: "", no_std: false }
driver: { os: ubuntu-latest, description: Native, native: true }
exclude:
- driver: { browser: true }
environment: { browser: false }
- driver: { nodejs: true }
environment: { browser: true }
- driver: { firefox: true }
environment: { service-worker: true }

steps:
- name: Checkout
Expand All @@ -171,16 +108,16 @@ jobs:
- name: Set `build-std` `no_std` components
if: matrix.rust.build-std == true && matrix.features.no_std == true
run: echo "BUILD_STD_COMPONENTS=-Zbuild-std=core,alloc" >> $GITHUB_ENV
- name: Set Driver and enable cross-compilation
if: matrix.target.native == false
run: |
echo "${{ matrix.target.name }}=${{ matrix.target.value }}" >> $GITHUB_ENV
echo "DOCTEST_XCOMPILE_ARG=-Zdoctest-xcompile" >> $GITHUB_ENV
- name: Doctest
- name: Set Driver
if: matrix.driver.browser == true
run: echo "${{ matrix.driver.name }}=${{ matrix.driver.value }}" >> $GITHUB_ENV
- name: Set Environment
if: matrix.environment.browser == true
run: echo "${{ matrix.environment.name }}=1" >> $GITHUB_ENV
- name: Test
env:
RUSTFLAGS: ${{ matrix.rust.flags }}
RUSTDOCFLAGS: ${{ matrix.rust.flags }}
run:
cargo test --features serde ${{ matrix.features.features }} --target ${{
matrix.target.target }} $BUILD_STD_COMPONENTS --workspace --doc ${{ matrix.target.args }}
$DOCTEST_XCOMPILE_ARG
matrix.target.target }} $BUILD_STD_COMPONENTS --workspace ${{ matrix.target.docargs }}
5 changes: 0 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@
//! # #[cfg(target_arch = "wasm32")]
//! # use tests_web as _;
//! #
//! # wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
//! #
//! # #[wasm_bindgen_test::wasm_bindgen_test]
//! # fn main() {
//! let now = Instant::now();
Expand Down Expand Up @@ -190,8 +188,5 @@ pub use self::time::*;
#[cfg(all(not(doc), docsrs))]
compile_error!("`--cfg docsrs` must only be used via `RUSTDOCFLAGS`, not `RUSTFLAGS`");

#[cfg(all(test, target_arch = "wasm32"))]
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);

#[cfg(all(test, not(target_arch = "wasm32")))]
fn main() {}
6 changes: 1 addition & 5 deletions tests-web/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@ web-time = { path = "../", default-features = false }
[target.'cfg(all(target_arch = "wasm32", target_feature = "atomics"))'.dependencies]
futures-channel = { version = "0.3", default-features = false, features = ["alloc"] }
futures-util = { version = "0.3", default-features = false }
web-sys = { version = "0.3", default-features = false, features = [
"DedicatedWorkerGlobalScope",
"OfflineAudioContext",
"WorkerGlobalScope",
] }
web-sys = { version = "0.3", default-features = false, features = ["OfflineAudioContext"] }
web-thread = { git = "https://github.com/daxpedda/wasm-worker", rev = "93236ab92354cbe0a0c07e71b9888be8b3e45999", optional = true, features = [
"audio-worklet",
] }
Expand Down
8 changes: 4 additions & 4 deletions tests/atomic_success.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use wasm_bindgen_test::wasm_bindgen_test;
use web_thread::web;
use web_time::{Duration, Instant};

use self::util::{sleep, Flag, DIFF};
use self::util::{sleep, Flag, DIFF, WAIT};

#[wasm_bindgen_test]
async fn basic() {
Expand All @@ -24,7 +24,7 @@ async fn basic() {
let later = Instant::now();
assert!(earlier <= later, "{:?}", earlier - later);

sleep(DIFF).await;
sleep(WAIT).await;

let later = Instant::now();
assert!((later - earlier) >= DIFF, "{:?}", later - earlier);
Expand Down Expand Up @@ -53,7 +53,7 @@ async fn delay() {
let later = Instant::now();
assert!(earlier <= later, "{:?}", earlier - later);

sleep(DIFF).await;
sleep(WAIT).await;

let later = Instant::now();
assert!((later - earlier) >= DIFF, "{:?}", later - earlier);
Expand All @@ -77,7 +77,7 @@ async fn worker() {
let later = Instant::now();
assert!(earlier <= later, "{:?}", earlier - later);

sleep(DIFF).await;
sleep(WAIT).await;

let later = Instant::now();
assert!((later - earlier) >= DIFF, "{:?}", later - earlier);
Expand Down
4 changes: 2 additions & 2 deletions tests/instant_failure_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ mod util;
use wasm_bindgen_test::wasm_bindgen_test;
use web_time::{Duration, Instant};

use self::util::{sleep, DIFF};
use self::util::{sleep, WAIT};

/// [`Instant::add()`] failure.
#[wasm_bindgen_test(unsupported = pollster::test)]
#[should_panic = "overflow when adding duration to instant"]
async fn add_failure() {
sleep(DIFF).await;
sleep(WAIT).await;
let _ = Instant::now() + Duration::MAX;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/instant_failure_2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ mod util;
use wasm_bindgen_test::wasm_bindgen_test;
use web_time::{Duration, Instant};

use self::util::{sleep, DIFF};
use self::util::{sleep, WAIT};

/// [`Instant::add_assign()`] failure.
#[wasm_bindgen_test(unsupported = pollster::test)]
#[should_panic = "overflow when adding duration to instant"]
async fn add_assign_failure() {
sleep(DIFF).await;
sleep(WAIT).await;
let mut instant = Instant::now();
instant += Duration::MAX;
}
Loading

0 comments on commit 8ef40bc

Please sign in to comment.