cross_test/lib.rs
1//! # cross-test
2//! Run Rust native and web tests with a single framework.
3//!
4//! ### Platforms
5//! * Web: web-sys
6//! * Native: tokio
7//!
8//! ### Requirements
9//!
10//! To run the `wasm-bindgen-test`s, you need to have the nightly toolchain installed (there is no need to make it default).
11//!
12//! You will also need to manually include `wasm-bindgen-test` as a dev dependency in your project because `#[wasm_bindgen_test]` macro can't be re-exported to avoid this requirement because of how it was designed.
13//!
14//! ```
15//! [target.'cfg(target_arch = "wasm32")'.dependencies]
16//! wasm-bindgen-test = "0.3.20"
17//! ```
18//!
19//! ### Usage
20//! ```
21//!use cross_test::prelude::*;
22//!
23//!cross_test_configure!();
24//!
25//!#[cross_test]
26//!async fn it_works() {
27//! assert_eq!(2 + 2, 4);
28//!}
29//! ```
30//!
31//! ### Important issue
32//!
33//! Because `#[cross_test]` gets translated to `#[tokio::test]` all the tests must be `async`.
34//!
35//! A custom proc-macro will be provided to select the test executor if the `async` work is present or not.
36
37#[warn(missing_docs)]
38
39pub mod prelude;
40
41#[cfg(not(target_arch = "wasm32"))]
42mod platform {
43 pub use tokio::test as test;
44
45 #[macro_export]
46 macro_rules! configure {
47 () => {}
48 }
49}
50
51#[cfg(target_arch = "wasm32")]
52mod platform {
53 pub use wasm_bindgen_test::wasm_bindgen_test as test;
54
55 #[macro_export]
56 macro_rules! configure {
57 () => {
58 wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
59 }
60 }
61}
62
63pub use platform::*;
64
65#[cfg(test)]
66mod tests {
67 use crate as cross_test;
68 use cross_test::prelude::*;
69
70 cross_test_configure!();
71
72 #[cross_test]
73 async fn it_works() {
74 assert_eq!(2 + 2, 4);
75 }
76}