Skip to content

Commit 8b0fc33

Browse files
committed
fix(presets): fix Next.js Docker e2e test reliability
- Add .dockerignore to exclude node_modules from build context (local macOS binaries overwrote Docker-installed ones via COPY . .) - Remove node_modules from copied fixture before Docker build - Use --no-cache flag to prevent stale Docker layer cache issues - Use dynamic port instead of hardcoded 3099 to avoid bind conflicts - Clean up stale containers from previous test runs before starting
1 parent c23139c commit 8b0fc33

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

crates/temps-presets/src/nextjs.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,17 @@ mod tests {
745745

746746
let project_dir = temp_dir.join("nextjs-hello-world");
747747

748+
// Remove node_modules from copied fixture — Docker must install its own
749+
// (local node_modules may contain platform-specific binaries)
750+
let _ = std::fs::remove_dir_all(project_dir.join("node_modules"));
751+
752+
// Write .dockerignore to prevent node_modules from leaking into build context
753+
std::fs::write(
754+
project_dir.join(".dockerignore"),
755+
"node_modules\n.next\n",
756+
)
757+
.expect("Failed to write .dockerignore");
758+
748759
// Generate Dockerfile using the preset
749760
let preset = NextJs;
750761
let dockerfile_result = preset.dockerfile(DockerfileConfig {
@@ -772,6 +783,7 @@ mod tests {
772783
let build_result = Command::new("docker")
773784
.args([
774785
"build",
786+
"--no-cache",
775787
"-t", &image_name,
776788
"-f", dockerfile_path.to_str().unwrap(),
777789
project_dir.to_str().unwrap(),
@@ -800,7 +812,14 @@ mod tests {
800812

801813
// Run the container
802814
let container_name = format!("temps-nextjs-test-{}", test_id);
803-
let host_port = 3099; // Use a non-standard port to avoid conflicts
815+
816+
// Clean up any stale containers from previous test runs
817+
let _ = Command::new("docker")
818+
.args(["rm", "-f", &container_name])
819+
.output();
820+
821+
// Use a dynamic port to avoid conflicts
822+
let host_port = 30000 + (test_id % 10000) as u16;
804823

805824
println!("Starting container: {}", container_name);
806825

0 commit comments

Comments
 (0)