{"record":{"id":"8f55ae2b43b4b6d5","repo":"swc-project/swc","slug":"failed-to-find-mocha-from-path","errorCode":null,"errorMessage":"failed to find `mocha` from path","messagePattern":"failed to find `mocha` from path","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_ecma_transforms_testing/src/lib.rs","lineNumber":667,"sourceCode":"            return Ok(());\n        }\n    }\n\n    let tmp_dir = tempdir_in(&root).expect(\"failed to create a temp directory\");\n    create_dir_all(&tmp_dir).unwrap();\n\n    let path = tmp_dir.path().join(format!(\"{hash}.test.js\"));\n\n    let mut tmp = OpenOptions::new()\n        .create(true)\n        .truncate(true)\n        .write(true)\n        .open(&path)\n        .expect(\"failed to create a temp file\");\n    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));","sourceCodeStart":649,"sourceCodeEnd":685,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_ecma_transforms_testing/src/lib.rs#L649-L685","documentation":"Execution tests run their generated test file under mocha. The harness locates the runner with `find_executable(\"mocha\")` (crates/testing/src/lib.rs:54), which searches PATH for `mocha`/`mocha.exe`/`mocha.cmd`/`mocha.bat` and, failing that, tries `pnpm bin`. The `expect(\"failed to find `mocha` from path\")` panics when neither yields a mocha executable — i.e. mocha is simply not installed anywhere the harness can see.","triggerScenarios":"Running any `test_exec!`-style execution test with `EXEC != 0` in an environment where mocha is absent: fresh clones without node_modules, global-only npm setups, PATH scrubbed by CI, and no `pnpm` on PATH to provide the fallback lookup.","commonSituations":"CI images with node but no mocha; running tests before `pnpm install` in the swc repo (mocha is a repo devDependency); environments using yarn/npm where the `pnpm bin` fallback cannot help.","solutions":["Install mocha in the workspace and ensure node_modules/.bin is resolvable: in the swc repo run `pnpm install`; elsewhere `npm i -D mocha` or `npm i -g mocha`.","Ensure the package manager's bin dir is on PATH for the test process (or that `pnpm` is on PATH so the fallback works).","Verify with `mocha --version` (or `npx mocha --version`) from the same shell that runs `cargo test`.","If node tooling is intentionally absent, disable execution tests with `EXEC=0 cargo test`."],"exampleFix":"# before\n$ cargo test -p swc_ecma_transforms_testing   # mocha missing -> panic\n\n# after\n$ npm i -D mocha   # or: pnpm install\n$ cargo test -p swc_ecma_transforms_testing","handlingStrategy":"validation","validationCode":"// Run once in test setup (or CI preflight) to fail with a clear message\n// instead of a mid-test panic.\nfn require_mocha() {\n    let found = [\"mocha\", \"mocha.cmd\", \"mocha.bat\"]\n        .iter()\n        .any(|name| which::which(name).is_ok());\n    if !found {\n        panic!(\"mocha not found: run `npm i -D mocha` (repo: `pnpm install`)\");\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run the repo's package-manager install (`pnpm install`) before cargo test in CI.","Add a CI preflight step asserting `npx mocha --version` succeeds.","Keep `pnpm` on PATH too — the harness falls back to `pnpm bin` to locate mocha."],"tags":["test-harness","mocha","path","missing-dependency","swc"],"backgroundTag":"executable-not-found-in-path","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}