Crate wasmer_pack_testing
source ·Expand description
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
:
[package]
...
[[test]]
name = "integration-tests"
harness = false
[dev-dependencies]
wasmer-pack-testing = { path = "../../crates/testing" }
Next, add the following integration test:
// 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
withpoetry init
- Add the generated bindings as a dependency with
poetry add --editable ...
- Create a
- 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
),
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
withyarn init
- Add any necessary dev-dependencies with
yarn add
(e.g.jest
) - Use
yarn link
to add the generated bindings as a dependency
- Create a
- Run
yarn install
to install any missing dependencies - Execute tests using
yarn test
(the default is to use jest)