wasmer_pack_testing/
lib.rs

1//! Utilities for testing bindings generated by Wasmer Pack.
2//!
3//! # Setup
4//!
5//! To use the `wasmer-pack-testing` crate, you need to create an integration
6//! test that has its own runner.
7//!
8//! First, add the following to your `Cargo.toml`:
9//!
10//! ```toml
11//! [package]
12//! ...
13//!
14//! [[test]]
15//! name = "integration-tests"
16//! harness = false
17//!
18//! [dev-dependencies]
19//! wasmer-pack-testing = { path = "../../crates/testing" }
20//! ```
21//!
22//! Next, add the following integration test:
23//!
24//! ```rust,no_run
25//! // tests/integration-tests.rs
26//!
27//! use anyhow::Error;
28//! use tracing_subscriber::EnvFilter;
29//!
30//! fn main() -> Result<(), Error> {
31//!     tracing_subscriber::fmt()
32//!         .with_env_filter(EnvFilter::from_default_env())
33//!         .init();
34//!     wasmer_pack_testing::autodiscover(env!("CARGO_MANIFEST_DIR"))?;
35//!     Ok(())
36//! }
37//! ```
38//!
39//! Under the hood, this will try to detect which languages you have written
40//! integration tests for, then automatically generate bindings to your package
41//! and run the tests with the bindings.
42//!
43//! # Python
44//!
45//! When Python tests are detected, [`autodiscover()`] will do the following:
46//!
47//! - Compile the crate into a WAPM package
48//! - Generate Python bindings for the package
49//! - If necessary, initialize a Python project
50//!   - Create a `pyproject.toml` with `poetry init`
51//!   - Add the generated bindings as a dependency with `poetry add --editable ...`
52//! - Run `poetry install` to install any missing dependencies
53//! - Execute tests with [pytest]
54//!
55//! Note that Wasmer's Python bindings don't work on a M1 Mac
56//! ([`wasmer-python#680`](https://github.com/wasmerio/wasmer-python/issues/680)),
57//! so the code will be generated but no tests will be executed on this
58//! platform.
59//!
60//! # JavaScript
61//!
62//! When JavaScript or TypeScript tests are detected, [`autodiscover()`] will
63//! do the following:
64//!
65//! - Compile the crate into a WAPM package
66//! - Generate JavaScript bindings for the crate
67//! - If necessary, initialize the JavaScript project
68//!   - Create a `package.json` with `yarn init`
69//!   - Add any necessary dev-dependencies with `yarn add` (e.g. `jest`)
70//!   - Use `yarn link` to add the generated bindings as a dependency
71//! - Run `yarn install` to install any missing dependencies
72//! - Execute tests using `yarn test` (the default is to use [jest])
73//!
74//! [pytest]: https://docs.pytest.org/
75//! [jest]: https://jestjs.io/
76
77mod autodiscover;
78mod utils;
79
80pub use crate::{
81    autodiscover::autodiscover,
82    utils::{compile_rust_to_wapm_package, generate_bindings},
83};
84pub use wasmer_pack_cli::Language;