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