Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

component test: inherit stdout from host #223

Merged
merged 3 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/cli/src/commands/components/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ async fn test_data_collection_component(opts: Options) -> anyhow::Result<()> {
let context = ComponentsContext::new(&config)
.map_err(|_e| anyhow::anyhow!("Something went wrong when trying to load the Wasm file. Please re-build and try again."))?;

let mut store = context.empty_store();
let mut store = context.empty_store_with_stdout();

let instance = context
.get_data_collection_instance(&component_path, &mut store)
Expand Down
13 changes: 11 additions & 2 deletions crates/components-runtime/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ impl ComponentsContext {
Store::new(&self.engine, HostState::new())
}

pub fn empty_store_with_stdout(&self) -> Store<HostState> {
Store::new(&self.engine, HostState::new_with_stdout())
}

pub async fn get_data_collection_instance(
&self,
id: &str,
Expand Down Expand Up @@ -170,10 +174,15 @@ pub struct HostState {

impl HostState {
fn new() -> Self {
let ctx = WasiCtx::builder().build();
Self::new_with_ctx(WasiCtx::builder().build())
}

let table = ResourceTable::new();
fn new_with_stdout() -> Self {
Self::new_with_ctx(WasiCtx::builder().inherit_stdout().build())
}

fn new_with_ctx(ctx: WasiCtx) -> Self {
let table = ResourceTable::new();
Self { ctx, table }
}
}
Expand Down