Compare commits

...
Author SHA1 Message Date
Adrien Eppling 51668f3cdd refactor(js): decouple vitest/jest runner from CLI Commands enum
run_test(&Commands) → run_vitest/run_jest over a shared helper, dropping the
module dependency on the CLI Commands enum and the unreachable!() arm. Also fix
two doctests that surface once the crate is bundled as a lib: correct
join_with_overflow (Unicode ellipsis) and mark the TimedExecution example ignore.
2026-06-12 18:27:45 +02:00
4 changed files with 26 additions and 31 deletions

No files matched your search

+22 -26
View File
@@ -11,7 +11,7 @@ use crate::parser::{
emit_degradation_warning, emit_passthrough_warning, extract_json_object, truncate_passthrough,
FormatMode, OutputParser, ParseResult, TestFailure, TestResult, TokenFormatter,
};
use crate::Commands;
use std::process::Command;
/// Vitest JSON output structures (tool-specific format)
#[derive(Debug, Deserialize)]
@@ -204,32 +204,28 @@ fn extract_failures_regex(output: &str) -> Vec<TestFailure> {
failures
}
pub fn run_test(command: &Commands, args: &[String], verbose: u8) -> Result<i32> {
let timer = tracking::TimedExecution::start();
pub fn run_vitest(args: &[String], verbose: u8) -> Result<i32> {
let mut cmd = package_manager_exec("vitest");
cmd
// Force non-watch mode
.arg("run")
// Enable JSON structured output
.arg("--reporter=json");
run_framework_test("vitest", cmd, args, verbose)
}
let (framework, mut cmd) = match command {
Commands::Vitest { .. } => {
let framework = "vitest";
let mut cmd = package_manager_exec(framework);
cmd
// Force non-watch mode
.arg("run")
// Enable JSON structured output
.arg("--reporter=json");
(framework, cmd)
}
Commands::Jest { .. } => {
let framework = "jest";
let mut cmd = package_manager_exec(framework);
cmd
// Force non-watch mode
.arg("--no-watch")
// Enable JSON structured output
.arg("--json");
(framework, cmd)
}
_ => unreachable!(),
};
pub fn run_jest(args: &[String], verbose: u8) -> Result<i32> {
let mut cmd = package_manager_exec("jest");
cmd
// Force non-watch mode
.arg("--no-watch")
// Enable JSON structured output
.arg("--json");
run_framework_test("jest", cmd, args, verbose)
}
fn run_framework_test(framework: &str, mut cmd: Command, args: &[String], verbose: u8) -> Result<i32> {
let timer = tracking::TimedExecution::start();
for arg in args {
if arg == "run"
+1 -1
View File
@@ -1294,7 +1294,7 @@ pub fn estimate_tokens(text: &str) -> usize {
///
/// # Examples
///
/// ```no_run
/// ```ignore
/// use rtk::tracking::TimedExecution;
///
/// let timer = TimedExecution::start();
+1 -1
View File
@@ -141,7 +141,7 @@ pub fn format_cpt(cpt: f64) -> String {
/// ```
/// use rtk::utils::join_with_overflow;
/// let items = vec!["a".to_string(), "b".to_string()];
/// assert_eq!(join_with_overflow(&items, 5, 3, "items"), "a\nb\n... +2 more items");
/// assert_eq!(join_with_overflow(&items, 5, 3, "items"), "a\nb\n… +2 more items");
/// assert_eq!(join_with_overflow(&items, 2, 3, "items"), "a\nb");
/// ```
pub fn join_with_overflow(items: &[String], total: usize, max: usize, label: &str) -> String {
+2 -3
View File
@@ -1990,9 +1990,8 @@ fn run_cli() -> Result<i32> {
0
}
Commands::Jest { ref args } | Commands::Vitest { ref args } => {
vitest_cmd::run_test(&cli.command, args, cli.verbose)?
}
Commands::Vitest { ref args } => vitest_cmd::run_vitest(args, cli.verbose)?,
Commands::Jest { ref args } => vitest_cmd::run_jest(args, cli.verbose)?,
Commands::Prisma { command } => match command {
PrismaCommands::Generate { args } => {