Skip to content

Commit

Permalink
fixtures verify test setups are resolved correctly by node runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam McKee committed Nov 7, 2024
1 parent a1e9be1 commit f87753c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- uses: dtolnay/rust-toolchain@stable
- uses: swatinem/rust-cache@v2
- name: cargo test
Expand Down
36 changes: 35 additions & 1 deletion fn_build/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ use std::collections::HashMap;
use std::future::Future;
use std::path::{Path, PathBuf};
use std::pin::Pin;
use std::process::{Command, Output};
use std::sync::Arc;
use std::{env, fs};
use std::{env, fs, io};
use temp_dir::TempDir;

#[allow(unused)]
Expand Down Expand Up @@ -68,6 +69,15 @@ impl BuildProcess for JavaScriptBuild {
fn runtime_config(&self, project_dir: &Path) -> Runtime {
Runtime::Node(NodeConfig::read_node_config(&project_dir).unwrap())
}

fn verify_runtime(&self, project_dir: &Path, entrypoint: &Path) -> Option<io::Result<Output>> {
Some(
Command::new("node")
.arg(entrypoint)
.current_dir(project_dir)
.output(),
)
}
}

#[derive(Deserialize, Serialize)]
Expand Down Expand Up @@ -111,6 +121,8 @@ trait BuildProcess {
fn parse(&self, parse_spec: FnParseSpec) -> BuildProcessResult<FnManifest>;

fn runtime_config(&self, project_dir: &Path) -> Runtime;

fn verify_runtime(&self, project_dir: &Path, entrypoint: &Path) -> Option<io::Result<Output>>;
}

fn collect_fixture_dirs(p: PathBuf) -> Vec<PathBuf> {
Expand Down Expand Up @@ -159,6 +171,7 @@ impl TestFixture {
}

async fn test(&self) -> Result<(), anyhow::Error> {
self.runtime_verify_fixture().await?;
let temp_build_dir = TempDir::new()?;
let build_dir_root = temp_build_dir.path().to_path_buf();
if self.leak_build_dir {
Expand All @@ -183,6 +196,27 @@ impl TestFixture {
Ok(())
}

async fn runtime_verify_fixture(&self) -> Result<(), anyhow::Error> {
if let Some(result) = self
.build_process
.verify_runtime(&self.fixture_dir, &self.spec.entrypoint)
{
let output = result?;
if !output.status.success() {
panic!(
"fixture {} failed verifying with runtime with output:\n{}",
self.fixture_label(),
format!(
"~~STDERR~~\n{}\n~~STDOUT~~\n{}",
String::from_utf8(output.stderr)?,
String::from_utf8(output.stdout)?,
)
);
}
}
Ok(())
}

async fn build(&self, build_dir: PathBuf, build_mode: BuildMode) -> Result<(), anyhow::Error> {
self.build_process
.build(FnBuildSpec {
Expand Down

0 comments on commit f87753c

Please sign in to comment.