{"record":{"id":"66073761f673478a","repo":"swc-project/swc","slug":"test-inlined-transform-does-not-support-paths-outs","errorCode":null,"errorMessage":"test_inlined_transform does not support paths outside of the crate root","messagePattern":"test_inlined_transform does not support paths outside of the crate root","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_ecma_transforms_testing/src/lib.rs","lineNumber":414,"sourceCode":"    test_name: &str,\n    syntax: Syntax,\n    module: Option<bool>,\n    tr: F,\n    input: &str,\n) where\n    F: FnOnce(&mut Tester) -> P,\n    P: Pass,\n{\n    let loc = panic::Location::caller();\n\n    let manifest_dir = PathBuf::from(env::var(\"CARGO_MANIFEST_DIR\").expect(\"CARGO_MANIFEST_DIR\"));\n\n    let test_file_path = CARGO_WORKSPACE_ROOT.join(loc.file());\n\n    let snapshot_dir = manifest_dir.join(\"tests\").join(\"__swc_snapshots__\").join(\n        test_file_path\n            .strip_prefix(&manifest_dir)\n            .expect(\"test_inlined_transform does not support paths outside of the crate root\"),\n    );\n\n    test_fixture_inner(\n        syntax,\n        Box::new(move |tester| Box::new(tr(tester))),\n        input,\n        &snapshot_dir.join(format!(\"{test_name}.js\")),\n        FixtureTestConfig {\n            module,\n            ..Default::default()\n        },\n    )\n}\n\n/// NOT A PUBLIC API. DO NOT USE.\n#[doc(hidden)]\n#[macro_export]\nmacro_rules! test_location {","sourceCodeStart":396,"sourceCodeEnd":432,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_ecma_transforms_testing/src/lib.rs#L396-L432","documentation":"`test_inlined_transform` locates snapshots by joining the caller's file path (from `panic::Location::caller()`) onto `CARGO_WORKSPACE_ROOT`, then requires it to sit under the current crate's manifest dir via `strip_prefix(&manifest_dir)`. The expect fires when the file that invoked `test_inlined_transform` does not live inside the crate being compiled — the harness has no place to put the `__swc_snapshots__` output.","triggerScenarios":"Thrown at crates/swc_ecma_transforms_testing/src/lib.rs:414 when the library encounters an invalid state.","commonSituations":"Test helpers that live in a shared crate but call `test_inlined_transform` on behalf of another crate; vendored or symlinked source layouts where the compile-time file path and the manifest dir disagree; moving tests between workspace members without moving the snapshot helper call.","solutions":["Invoke `test_inlined_transform` directly from a test file inside the crate whose snapshots you want (each crate owns tests/__swc_snapshots__).","If a shared helper must drive inlined tests, make the helper take explicit paths and use `test_fixture`/`test_transform` style APIs that accept a snapshot path, instead of this caller-location-based helper.","Check for path oddities (symlinks, `#[path]` includes from outside the crate root) in the failing test's file."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Call test_inlined_transform only from test files inside the crate that owns the snapshots.","Avoid #[path] includes and symlinks that place the calling file outside the crate root.","For shared harnesses, pass explicit snapshot paths instead of relying on caller location."],"tags":["test-harness","snapshot","path-resolution","runtime-panic","swc"],"backgroundTag":"path-outside-project-root","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}