Skip to content
76 changes: 70 additions & 6 deletions rust/execution/counterfactual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,34 @@ pub(crate) async fn run_one(
} else {
approval.timeout()
};
let mut args = Vec::new();
if target.file.ends_with(".ts")
let ts_mode = target.file.ends_with(".ts")
|| target.file.ends_with(".mts")
|| target.file.ends_with(".cts")
{
|| owner.root().join("tsconfig.json").is_file();
let run_node = if ts_mode {
tools::find_modern_node(node)
} else {
node.to_path_buf()
};
let mut args = Vec::new();
if ts_mode {
for cand in [
Some(owner.root().join("node_modules")),
owner
.root()
.parent()
.and_then(Path::parent)
.map(|p| p.join("node_modules")),
]
.into_iter()
.flatten()
{
if cand.is_dir() {
env.insert("ROSTER_NODE_MODULES".to_owned(), cand.display().to_string());
break;
}
}
args.push("--experimental-transform-types".to_owned());
args.push("--import".to_owned());
args.push(tools::TS_IMPORT_HOOK.to_owned());
}
Expand All @@ -214,16 +237,57 @@ pub(crate) async fn run_one(
format!("--test-timeout={per_test_timeout}"),
target.file.clone(),
]);
return owner
let run = owner
.run(
directory,
node,
&run_node,
&args,
&env,
approval.timeout(),
evidence::MAX_DIFF_BYTES,
)
.await;
.await?;
if !run.success() && ts_mode {
let combined = format!(
"{}\n{}",
String::from_utf8_lossy(&run.stdout),
String::from_utf8_lossy(&run.stderr)
);
if tools::Boundary::is_node_ts_transform_limitation(&combined)
&& let Some(vitest) = [
Some(owner.root().join("node_modules")),
owner
.root()
.parent()
.and_then(Path::parent)
.map(|p| p.join("node_modules")),
]
.into_iter()
.flatten()
.map(|nm| nm.join("vitest").join("vitest.mjs"))
.find(|p| p.is_file())
{
let vargs = vec![
vitest.display().to_string(),
"run".to_owned(),
"--no-file-parallelism".to_owned(),
"--no-cache".to_owned(),
"--reporter=tap-flat".to_owned(),
target.file.clone(),
];
return owner
.run(
directory,
&run_node,
&vargs,
&env,
approval.timeout(),
evidence::MAX_DIFF_BYTES,
)
.await;
}
}
return Ok(run);
}
let cargo = owner
.host()
Expand Down
7 changes: 5 additions & 2 deletions rust/execution/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ pub fn relevant_tests(files: &[String]) -> Result<Vec<String>, Error> {
return Ok(Vec::new());
}
let pattern = regex(
r"(?:^tests?/.+\.[cm]?[jt]s$|(?:^|/)(?:test(?:[._-][^/]+)?|[^/]+[._-](?:test|spec))\.[cm]?[jt]s$)",
r"(?:^(?:tests?|__tests__)/.+\.[cm]?[jt]s$|(?:^|/)__tests__/.+\.[cm]?[jt]s$|(?:^|/)(?:test(?:[._-][^/]+)?|[^/]+[._-](?:test|spec))\.[cm]?[jt]s$)",
)?;
let extension = regex(r"\.[cm]?[jt]s$")?;
let mut tests = Vec::new();
Expand Down Expand Up @@ -240,7 +240,10 @@ pub fn verification_decision(files: &[String]) -> Result<Value, Error> {
let update = relevant_tests(files)?
.into_iter()
.filter(|file| {
files.contains(file) || file.starts_with("tests/") || file.starts_with("test/")
files.contains(file)
|| file.starts_with("tests/")
|| file.starts_with("test/")
|| file.starts_with("__tests__/")
})
.collect::<Vec<_>>();
Ok(Value::object(vec![
Expand Down
Loading
Loading