{"record":{"id":"566d205192b661f7","repo":"swc-project/swc","slug":"failed-to-run-mocha","errorCode":null,"errorMessage":"failed to run mocha","messagePattern":"failed to run mocha","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_ecma_transforms_testing/src/lib.rs","lineNumber":682,"sourceCode":"    write!(tmp, \"{src}\").expect(\"failed to write to temp file\");\n    tmp.flush().unwrap();\n\n    let test_runner_path = find_executable(\"mocha\").expect(\"failed to find `mocha` from path\");\n\n    let mut base_cmd = if cfg!(target_os = \"windows\") {\n        let mut c = Command::new(\"cmd\");\n        c.arg(\"/C\").arg(&test_runner_path);\n        c\n    } else {\n        Command::new(&test_runner_path)\n    };\n\n    let output = base_cmd\n        .arg(format!(\"{}\", path.display()))\n        .arg(\"--color\")\n        .current_dir(root)\n        .output()\n        .expect(\"failed to run mocha\");\n\n    println!(\">>>>> {} <<<<<\", Color::Red.paint(\"Stdout\"));\n    println!(\"{}\", String::from_utf8_lossy(&output.stdout));\n    println!(\">>>>> {} <<<<<\", Color::Red.paint(\"Stderr\"));\n    println!(\"{}\", String::from_utf8_lossy(&output.stderr));\n\n    if output.status.success() {\n        fs::write(&success_cache, \"\").unwrap();\n        return Ok(());\n    }\n    let dir_name = path.display().to_string();\n    ::std::mem::forget(tmp_dir);\n    panic!(\"Execution failed: {dir_name}\")\n}\n\nfn stdout_of(code: &str) -> Result<String, Error> {\n    exec_node_js(\n        code,","sourceCodeStart":664,"sourceCodeEnd":700,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_ecma_transforms_testing/src/lib.rs#L664-L700","documentation":"After locating mocha, `exec_with_node_test_runner` spawns it (`Command::new(&test_runner_path).output()`; `cmd /C` wrapper on Windows). The `expect(\"failed to run mocha\")` panics when the spawn itself fails — the executable file was found but cannot be executed: missing execute permission, noexec mounts, a bad interpreter line, or OS-level spawn errors. This is distinct from mocha running and exiting non-zero, which takes the separate \"Execution failed\" path.","triggerScenarios":"A mocha shim/script in PATH without the executable bit (`chmod -x`), node_modules on a noexec-mounted filesystem, Windows where the found file is a `.js`/shell shim without a valid handler, or system resource limits preventing process creation (EAGAIN).","commonSituations":"Mocha found via `pnpm bin` on a mounted volume with noexec; manually copied mocha shims; fork-bomb-guarded CI limiting process creation; Windows permissions on .cmd shims.","solutions":["Check the located path is executable: `ls -l $(which mocha)` and `chmod +x` the shim or reinstall mocha properly (`npm i -D mocha`).","If node_modules lives on a noexec mount, move the target/workspace or remount with exec.","On Windows, prefer a real mocha install so `mocha.cmd` has a valid handler; avoid bare .js shims in PATH.","Raise process/fd limits in the CI job if spawn fails with resource errors."],"exampleFix":"# before\n$ ls -l node_modules/.bin/mocha   # no execute bit -> spawn fails\n\n# after\n$ chmod +x node_modules/.bin/mocha   # or: npm reinstall mocha\n$ cargo test -p swc_ecma_transforms_testing","handlingStrategy":"validation","validationCode":"// Verify the resolved mocha is actually executable before spawning tests.\nuse std::os::unix::fs::PermissionsExt;\n\nfn mocha_is_executable(path: &std::path::Path) -> bool {\n    #[cfg(unix)]\n    {\n        std::fs::metadata(path)\n            .map(|m| m.permissions().mode() & 0o111 != 0)\n            .unwrap_or(false)\n    }\n    #[cfg(not(unix))]\n    { path.is_file() }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure node_modules is not on a noexec mount.","Reinstall mocha if its bin shim lost the execute bit.","On CI, avoid copying shims manually; use the package manager's installed bin."],"tags":["test-harness","mocha","process-spawn","permissions","swc"],"backgroundTag":"process-spawn-failed","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}