mirror of
https://github.com/zhom/banderole.git
synced 2026-06-06 06:23:53 +02:00
chore: linting
This commit is contained in:
+16
-18
@@ -265,7 +265,7 @@ process.exit(0);"#;
|
||||
let mut package_json = self.generate_package_json(config)?;
|
||||
// Update main to point to compiled output
|
||||
let mut package_obj: serde_json::Value = serde_json::from_str(&package_json)?;
|
||||
package_obj["main"] = serde_json::Value::String(format!("{}/index.js", out_dir));
|
||||
package_obj["main"] = serde_json::Value::String(format!("{out_dir}/index.js"));
|
||||
package_json = serde_json::to_string_pretty(&package_obj)?;
|
||||
|
||||
fs::write(self.project_path.join("package.json"), package_json)?;
|
||||
@@ -315,7 +315,7 @@ try {
|
||||
)?;
|
||||
|
||||
// Create a marker file to verify correct source directory is used
|
||||
let marker_js = format!(r#"module.exports = {{ source: "{}" }};"#, out_dir);
|
||||
let marker_js = format!(r#"module.exports = {{ source: "{out_dir}" }};"#);
|
||||
fs::write(self.project_path.join(out_dir).join("marker.js"), marker_js)?;
|
||||
|
||||
Ok(())
|
||||
@@ -468,12 +468,12 @@ process.exit(0);"#;
|
||||
if deps.is_empty() {
|
||||
String::new()
|
||||
} else {
|
||||
format!(",\n \"dependencies\": {{\n{}\n }}", deps)
|
||||
format!(",\n \"dependencies\": {{\n{deps}\n }}")
|
||||
},
|
||||
if dev_deps.is_empty() {
|
||||
String::new()
|
||||
} else {
|
||||
format!(",\n \"devDependencies\": {{\n{}\n }}", dev_deps)
|
||||
format!(",\n \"devDependencies\": {{\n{dev_deps}\n }}")
|
||||
}
|
||||
);
|
||||
|
||||
@@ -482,7 +482,7 @@ process.exit(0);"#;
|
||||
|
||||
fn format_dependencies(&self, deps: &[(String, String)]) -> String {
|
||||
deps.iter()
|
||||
.map(|(name, version)| format!(" \"{}\": \"{}\"", name, version))
|
||||
.map(|(name, version)| format!(" \"{name}\": \"{version}\""))
|
||||
.collect::<Vec<_>>()
|
||||
.join(",\n")
|
||||
}
|
||||
@@ -556,7 +556,7 @@ impl BundlerTestHelper {
|
||||
// Find the created executable
|
||||
let executable_name = custom_name.unwrap_or("test-project");
|
||||
let executable_path = output_dir.join(if cfg!(windows) {
|
||||
format!("{}.exe", executable_name)
|
||||
format!("{executable_name}.exe")
|
||||
} else {
|
||||
executable_name.to_string()
|
||||
});
|
||||
@@ -564,9 +564,9 @@ impl BundlerTestHelper {
|
||||
// Check if collision avoidance was used
|
||||
if !executable_path.exists() || !executable_path.is_file() {
|
||||
let bundle_executable_path = output_dir.join(if cfg!(windows) {
|
||||
format!("{}-bundle.exe", executable_name)
|
||||
format!("{executable_name}-bundle.exe")
|
||||
} else {
|
||||
format!("{}-bundle", executable_name)
|
||||
format!("{executable_name}-bundle")
|
||||
});
|
||||
|
||||
if bundle_executable_path.exists() {
|
||||
@@ -634,7 +634,7 @@ impl BundlerTestHelper {
|
||||
#[cfg(unix)]
|
||||
{
|
||||
let _ = std::process::Command::new("kill")
|
||||
.args(&["-9", &child_id.to_string()])
|
||||
.args(["-9", &child_id.to_string()])
|
||||
.output();
|
||||
}
|
||||
#[cfg(windows)]
|
||||
@@ -663,16 +663,14 @@ impl TestCacheManager {
|
||||
} else {
|
||||
return Ok(()); // Can't determine cache dir, skip cleanup
|
||||
}
|
||||
} else if let Some(xdg_cache) = std::env::var_os("XDG_CACHE_HOME") {
|
||||
std::path::PathBuf::from(xdg_cache).join("banderole")
|
||||
} else if let Some(home) = std::env::var_os("HOME") {
|
||||
std::path::PathBuf::from(home)
|
||||
.join(".cache")
|
||||
.join("banderole")
|
||||
} else {
|
||||
if let Some(xdg_cache) = std::env::var_os("XDG_CACHE_HOME") {
|
||||
std::path::PathBuf::from(xdg_cache).join("banderole")
|
||||
} else if let Some(home) = std::env::var_os("HOME") {
|
||||
std::path::PathBuf::from(home)
|
||||
.join(".cache")
|
||||
.join("banderole")
|
||||
} else {
|
||||
std::path::PathBuf::from("/tmp").join("banderole-cache")
|
||||
}
|
||||
std::path::PathBuf::from("/tmp").join("banderole-cache")
|
||||
};
|
||||
|
||||
if cache_dir.exists() {
|
||||
|
||||
@@ -54,8 +54,8 @@ async fn test_concurrent_first_launch() -> Result<()> {
|
||||
|
||||
// Execute the binary
|
||||
let output = Command::new(executable_path.as_ref())
|
||||
.env("TEST_VAR", format!("thread_{}", i))
|
||||
.args(&[format!("--thread-id={}", i)])
|
||||
.env("TEST_VAR", format!("thread_{i}"))
|
||||
.args(&[format!("--thread-id={i}")])
|
||||
.output()
|
||||
.map_err(|e| anyhow::anyhow!("Failed to execute binary: {}", e))?;
|
||||
|
||||
@@ -87,7 +87,7 @@ async fn test_concurrent_first_launch() -> Result<()> {
|
||||
}
|
||||
|
||||
let total_time = start_time.elapsed();
|
||||
println!("Total concurrent execution time: {:?}", total_time);
|
||||
println!("Total concurrent execution time: {total_time:?}");
|
||||
|
||||
// Verify all executions succeeded
|
||||
assert_eq!(
|
||||
@@ -98,28 +98,22 @@ async fn test_concurrent_first_launch() -> Result<()> {
|
||||
|
||||
// Verify each execution produced expected output
|
||||
for (thread_id, duration, stdout) in &results {
|
||||
println!("Thread {} completed in {:?}", thread_id, duration);
|
||||
println!("Thread {thread_id} completed in {duration:?}");
|
||||
|
||||
// Check for expected output
|
||||
assert!(
|
||||
stdout.contains("Hello from test project!"),
|
||||
"Thread {} missing expected greeting in output: {}",
|
||||
thread_id,
|
||||
stdout
|
||||
"Thread {thread_id} missing expected greeting in output: {stdout}"
|
||||
);
|
||||
|
||||
assert!(
|
||||
stdout.contains(&format!("thread_{}", thread_id)),
|
||||
"Thread {} missing environment variable in output: {}",
|
||||
thread_id,
|
||||
stdout
|
||||
stdout.contains(&format!("thread_{thread_id}")),
|
||||
"Thread {thread_id} missing environment variable in output: {stdout}"
|
||||
);
|
||||
|
||||
assert!(
|
||||
stdout.contains(&format!("--thread-id={}", thread_id)),
|
||||
"Thread {} missing argument in output: {}",
|
||||
thread_id,
|
||||
stdout
|
||||
stdout.contains(&format!("--thread-id={thread_id}")),
|
||||
"Thread {thread_id} missing argument in output: {stdout}"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -135,7 +129,7 @@ async fn test_concurrent_first_launch() -> Result<()> {
|
||||
.min()
|
||||
.unwrap();
|
||||
|
||||
println!("Duration range: {:?} - {:?}", min_duration, max_duration);
|
||||
println!("Duration range: {min_duration:?} - {max_duration:?}");
|
||||
|
||||
// The difference shouldn't be too extreme if queueing is working properly
|
||||
// Allow up to 30 seconds difference for extraction + queue processing
|
||||
@@ -201,7 +195,7 @@ async fn test_cached_concurrent_execution() -> Result<()> {
|
||||
let thread_start = Instant::now();
|
||||
|
||||
let output = Command::new(executable_path.as_ref())
|
||||
.env("TEST_VAR", format!("cached_{}", i))
|
||||
.env("TEST_VAR", format!("cached_{i}"))
|
||||
.output()
|
||||
.map_err(|e| anyhow::anyhow!("Failed to execute binary: {}", e))?;
|
||||
|
||||
@@ -230,21 +224,19 @@ async fn test_cached_concurrent_execution() -> Result<()> {
|
||||
}
|
||||
|
||||
let total_time = start_time.elapsed();
|
||||
println!("Total cached concurrent execution time: {:?}", total_time);
|
||||
println!("Total cached concurrent execution time: {total_time:?}");
|
||||
|
||||
// Verify all executions succeeded
|
||||
assert_eq!(results.len(), NUM_CONCURRENT);
|
||||
|
||||
// With cache populated, all executions should be relatively fast
|
||||
for (thread_id, duration) in &results {
|
||||
println!("Cached thread {} completed in {:?}", thread_id, duration);
|
||||
println!("Cached thread {thread_id} completed in {duration:?}");
|
||||
|
||||
// Each execution should be fast since cache is populated
|
||||
assert!(
|
||||
*duration < Duration::from_secs(10),
|
||||
"Cached execution took too long: {:?} for thread {}",
|
||||
duration,
|
||||
thread_id
|
||||
"Cached execution took too long: {duration:?} for thread {thread_id}"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -316,7 +308,7 @@ process.exit(0);
|
||||
thread::sleep(Duration::from_millis(i as u64 * 10));
|
||||
|
||||
let output = Command::new(executable_path.as_ref())
|
||||
.args(&[format!("--thread-id={}", i)])
|
||||
.args(&[format!("--thread-id={i}")])
|
||||
.output()
|
||||
.map_err(|e| anyhow::anyhow!("Failed to execute binary: {}", e))?;
|
||||
|
||||
@@ -354,15 +346,13 @@ process.exit(0);
|
||||
);
|
||||
|
||||
assert!(
|
||||
stdout.contains(&format!("Thread {} started", thread_id)),
|
||||
"Thread {} missing start message",
|
||||
thread_id
|
||||
stdout.contains(&format!("Thread {thread_id} started")),
|
||||
"Thread {thread_id} missing start message"
|
||||
);
|
||||
|
||||
assert!(
|
||||
stdout.contains(&format!("Thread {} completed", thread_id)),
|
||||
"Thread {} missing completion message",
|
||||
thread_id
|
||||
stdout.contains(&format!("Thread {thread_id} completed")),
|
||||
"Thread {thread_id} missing completion message"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -405,8 +395,7 @@ async fn test_extraction_failure_recovery() -> Result<()> {
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
assert!(
|
||||
stdout.contains("Hello from test project!"),
|
||||
"Recovery test missing expected output: {}",
|
||||
stdout
|
||||
"Recovery test missing expected output: {stdout}"
|
||||
);
|
||||
|
||||
println!("✅ Extraction failure recovery test passed!");
|
||||
|
||||
+19
-21
@@ -162,8 +162,8 @@ process.exit(0);"#;
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
|
||||
println!("Test 1 - Exit status: {}", output.status);
|
||||
println!("Test 1 - Stdout: {}", stdout);
|
||||
println!("Test 1 - Stderr: {}", stderr);
|
||||
println!("Test 1 - Stdout: {stdout}");
|
||||
println!("Test 1 - Stderr: {stderr}");
|
||||
|
||||
// Check for expected output
|
||||
assert!(output.status.success(), "First run failed");
|
||||
@@ -193,7 +193,7 @@ process.exit(0);"#;
|
||||
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
println!("Test 2 - Exit status: {}", output.status);
|
||||
println!("Test 2 - Output: {}", stdout);
|
||||
println!("Test 2 - Output: {stdout}");
|
||||
|
||||
assert!(output.status.success(), "Cached run failed");
|
||||
assert!(
|
||||
@@ -236,7 +236,7 @@ process.exit(0);"#;
|
||||
// Build banderole
|
||||
println!("Building banderole for Node version test...");
|
||||
let output = Command::new("cargo")
|
||||
.args(&["build", "--release"])
|
||||
.args(["build", "--release"])
|
||||
.output()
|
||||
.expect("Failed to build banderole");
|
||||
|
||||
@@ -254,7 +254,7 @@ process.exit(0);"#;
|
||||
println!("Bundling test app with .nvmrc...");
|
||||
let mut bundle_cmd = Command::new(&banderole_path);
|
||||
bundle_cmd
|
||||
.args(&["bundle", test_app_path.to_str().unwrap()])
|
||||
.args(["bundle", test_app_path.to_str().unwrap()])
|
||||
.current_dir(temp_dir.path());
|
||||
|
||||
let bundle_output = bundle_cmd.output().expect("Failed to bundle test app");
|
||||
@@ -279,13 +279,12 @@ process.exit(0);"#;
|
||||
// Check that the output mentions the correct Node.js version
|
||||
let stdout = String::from_utf8_lossy(&bundle_output.stdout);
|
||||
let stderr = String::from_utf8_lossy(&bundle_output.stderr);
|
||||
let combined_output = format!("{}{}", stdout, stderr);
|
||||
println!("Bundle output: {}", combined_output);
|
||||
let combined_output = format!("{stdout}{stderr}");
|
||||
println!("Bundle output: {combined_output}");
|
||||
|
||||
assert!(
|
||||
combined_output.contains("Node.js v20.18.1"),
|
||||
"Expected Node.js version not found in output: {}",
|
||||
combined_output
|
||||
"Expected Node.js version not found in output: {combined_output}"
|
||||
);
|
||||
|
||||
// Find and run the created executable to verify it uses the correct Node version
|
||||
@@ -338,12 +337,11 @@ process.exit(0);"#;
|
||||
);
|
||||
|
||||
let stdout = String::from_utf8_lossy(&run_output.stdout);
|
||||
println!("Executable output: {}", stdout);
|
||||
println!("Executable output: {stdout}");
|
||||
|
||||
assert!(
|
||||
stdout.contains("v20.18.1"),
|
||||
"Expected Node.js version not found in executable output: {}",
|
||||
stdout
|
||||
"Expected Node.js version not found in executable output: {stdout}"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -435,7 +433,7 @@ async fn test_output_path_collision_handling() -> Result<(), Box<dyn std::error:
|
||||
let output = Command::new(&expected_executable).output()?;
|
||||
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
println!("Collision test output: {}", stdout);
|
||||
println!("Collision test output: {stdout}");
|
||||
|
||||
assert!(output.status.success(), "Collision test executable failed");
|
||||
assert!(
|
||||
@@ -587,7 +585,7 @@ try {
|
||||
let output = Command::new(&executable_path).output()?;
|
||||
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
println!("TypeScript test output: {}", stdout);
|
||||
println!("TypeScript test output: {stdout}");
|
||||
|
||||
assert!(output.status.success(), "TypeScript executable failed");
|
||||
assert!(
|
||||
@@ -727,7 +725,7 @@ try {
|
||||
let output = Command::new(&executable_path).output()?;
|
||||
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
println!("Custom outDir test output: {}", stdout);
|
||||
println!("Custom outDir test output: {stdout}");
|
||||
|
||||
assert!(output.status.success(), "Custom outDir executable failed");
|
||||
assert!(
|
||||
@@ -874,7 +872,7 @@ try {
|
||||
let output = Command::new(&executable_path).output()?;
|
||||
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
println!("Extends tsconfig test output: {}", stdout);
|
||||
println!("Extends tsconfig test output: {stdout}");
|
||||
|
||||
assert!(
|
||||
output.status.success(),
|
||||
@@ -1053,8 +1051,8 @@ packages:
|
||||
|
||||
let bundle_stdout = String::from_utf8_lossy(&bundle_output.stdout);
|
||||
let bundle_stderr = String::from_utf8_lossy(&bundle_output.stderr);
|
||||
println!("Bundle stdout: {}", bundle_stdout);
|
||||
println!("Bundle stderr: {}", bundle_stderr);
|
||||
println!("Bundle stdout: {bundle_stdout}");
|
||||
println!("Bundle stderr: {bundle_stderr}");
|
||||
|
||||
// The bundling succeeded if we can find the executable - output parsing is unreliable in tests
|
||||
|
||||
@@ -1102,9 +1100,9 @@ packages:
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
|
||||
println!("pnpm test stdout: {}", stdout);
|
||||
println!("pnpm test stdout: {stdout}");
|
||||
if !stderr.is_empty() {
|
||||
println!("pnpm test stderr: {}", stderr);
|
||||
println!("pnpm test stderr: {stderr}");
|
||||
}
|
||||
|
||||
// The critical assertions - the app should run successfully and load its dependencies
|
||||
@@ -1300,7 +1298,7 @@ fn run_with_timeout(cmd: &mut Command, timeout: Duration) -> std::io::Result<std
|
||||
#[cfg(unix)]
|
||||
{
|
||||
let _ = std::process::Command::new("kill")
|
||||
.args(&["-9", &child_id.to_string()])
|
||||
.args(["-9", &child_id.to_string()])
|
||||
.output();
|
||||
}
|
||||
#[cfg(windows)]
|
||||
|
||||
@@ -79,7 +79,7 @@ async fn test_pnpm_workspace_dependency_bundling() -> Result<()> {
|
||||
println!("Successfully installed pnpm workspace dependencies");
|
||||
}
|
||||
Err(e) => {
|
||||
println!("Pnpm installation failed, falling back to npm: {}", e);
|
||||
println!("Pnpm installation failed, falling back to npm: {e}");
|
||||
manager.install_workspace_dependencies()?;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,9 +153,9 @@ async fn test_version_format_compatibility() -> Result<()> {
|
||||
];
|
||||
|
||||
for (version_spec, test_name) in test_cases {
|
||||
println!("Testing version format: {} ({})", version_spec, test_name);
|
||||
println!("Testing version format: {version_spec} ({test_name})");
|
||||
|
||||
let project = TestProject::new(&format!("version-format-{}", test_name))
|
||||
let project = TestProject::new(&format!("version-format-{test_name}"))
|
||||
.workspace()
|
||||
.with_dependency("fs-extra", "^11.1.1");
|
||||
|
||||
@@ -172,7 +172,7 @@ async fn test_version_format_compatibility() -> Result<()> {
|
||||
let executable_path = BundlerTestHelper::bundle_project_with_compression(
|
||||
manager.project_path(),
|
||||
manager.temp_dir(),
|
||||
Some(&format!("version-format-{}-test", test_name)),
|
||||
Some(&format!("version-format-{test_name}-test")),
|
||||
false,
|
||||
)?;
|
||||
|
||||
@@ -188,7 +188,7 @@ async fn test_version_format_compatibility() -> Result<()> {
|
||||
&[],
|
||||
)?;
|
||||
|
||||
println!("✅ version format {} test passed!", version_spec);
|
||||
println!("✅ version format {version_spec} test passed!");
|
||||
}
|
||||
|
||||
println!("✅ all version format compatibility tests passed!");
|
||||
@@ -209,14 +209,14 @@ async fn test_nested_workspace_package_version_resolution() -> Result<()> {
|
||||
|
||||
// Create version files at different levels
|
||||
let workspace_root = manager.workspace_root().unwrap();
|
||||
|
||||
|
||||
// Workspace root has Node 20
|
||||
fs::write(workspace_root.join(".nvmrc"), "20")?;
|
||||
|
||||
|
||||
// Create an intermediate directory (simulating packages/ directory)
|
||||
let packages_dir = workspace_root.join("packages");
|
||||
fs::create_dir_all(&packages_dir)?;
|
||||
|
||||
|
||||
// Packages directory has Node 18 (should be ignored since project is deeper)
|
||||
fs::write(packages_dir.join(".node-version"), "18")?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user