diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2dce770..b1ef59d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,3 +35,16 @@ jobs: env: RUSTDOCFLAGS: -Dwarnings run: cargo doc --all --no-deps + + wasm: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Install stable toolchain + uses: dtolnay/rust-toolchain@stable + - name: Install wasm-pack + uses: taiki-e/install-action@wasm-pack + - name: Run wasm tests (`--no-default-features`) + run: wasm-pack test --node --no-default-features + - name: Run wasm tests (`--all-features`) + run: wasm-pack test --node --all-features diff --git a/Cargo.toml b/Cargo.toml index 1fb5ef9..e1d276c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,8 +14,6 @@ categories = ["os", "hardware-support", "filesystem", "accessibility"] all-features = true rustdoc-args = ["--cfg", "docsrs"] -# TODO: test more features in CI - [features] default = ["locate"] locate = ["locate_backend"] @@ -34,3 +32,16 @@ locate_backend = { package = "dirs", version = "5", optional = true } [dev-dependencies] insta = { version = "1.34.0", features = ["ron"] } +wasm-bindgen-test = "0.3.39" + +[[example]] +name = "appmanifest" +required-features = ["locate"] + +[[example]] +name = "overview" +required-features = ["locate"] + +[[example]] +name = "shortcuts" +required-features = ["locate"] diff --git a/src/error.rs b/src/error.rs index 882b7f2..6176a36 100644 --- a/src/error.rs +++ b/src/error.rs @@ -53,6 +53,7 @@ impl fmt::Display for Error { impl std::error::Error for Error {} impl Error { + #[cfg(feature = "locate")] pub(crate) fn locate(locate: LocateError) -> Self { Self::FailedLocate(locate) } @@ -110,6 +111,7 @@ impl fmt::Display for LocateError { #[derive(Clone, Debug)] pub struct BackendError { + #[cfg(feature = "locate")] #[allow(dead_code)] // Only used for displaying currently inner: BackendErrorInner, } @@ -126,11 +128,18 @@ impl fmt::Display for BackendError { BackendErrorInner::NoHome => f.write_str("Unable to locate the user's $HOME"), } } + #[cfg(not(feature = "locate"))] + { + // "Use" the unused value + let _ = f; + unreachable!("This should never be constructed!"); + } } } // TODO: move all this conditional junk into different modules, so that I don't have to keep // repeating it everywhere +// TODO: ^^ #[derive(Clone, Debug)] #[cfg(all(feature = "locate", target_os = "windows"))] struct BackendErrorInner(std::sync::Arc); diff --git a/src/tests/mod.rs b/src/tests/mod.rs index d24aa8b..6d036c2 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -2,6 +2,8 @@ pub mod helpers; #[cfg(test)] mod legacy; mod temp; +#[cfg(test)] +mod wasm; pub type TestError = Box; pub type TestResult = Result<(), TestError>; diff --git a/src/tests/wasm.rs b/src/tests/wasm.rs new file mode 100644 index 0000000..1cdef6d --- /dev/null +++ b/src/tests/wasm.rs @@ -0,0 +1,10 @@ +use wasm_bindgen_test::wasm_bindgen_test; + +#[wasm_bindgen_test] +#[cfg_attr(not(feature = "locate"), ignore = "Needs `locate` feature")] +fn locate() { + #[cfg(not(feature = "locate"))] + unreachable!("Don't run ignored tests silly"); + #[cfg(feature = "locate")] + let _ = crate::SteamDir::locate().unwrap_err(); +}