From 23da1d8dacb8c51ca6eb13d4006597c14d2130fe Mon Sep 17 00:00:00 2001 From: sapphi-red <49056869+sapphi-red@users.noreply.github.com> Date: Fri, 9 Jan 2026 18:47:01 +0900 Subject: [PATCH] test: add test to point out tsconfig cache pollution --- .../tsconfig/cases/simple-paths/bar/index.ts | 0 fixtures/tsconfig/cases/simple-paths/foo.ts | 0 .../tsconfig/cases/simple-paths/tsconfig.json | 7 +++ src/tests/tsconfig_paths.rs | 48 +++++++++++++++++++ 4 files changed, 55 insertions(+) create mode 100644 fixtures/tsconfig/cases/simple-paths/bar/index.ts create mode 100644 fixtures/tsconfig/cases/simple-paths/foo.ts create mode 100644 fixtures/tsconfig/cases/simple-paths/tsconfig.json diff --git a/fixtures/tsconfig/cases/simple-paths/bar/index.ts b/fixtures/tsconfig/cases/simple-paths/bar/index.ts new file mode 100644 index 00000000..e69de29b diff --git a/fixtures/tsconfig/cases/simple-paths/foo.ts b/fixtures/tsconfig/cases/simple-paths/foo.ts new file mode 100644 index 00000000..e69de29b diff --git a/fixtures/tsconfig/cases/simple-paths/tsconfig.json b/fixtures/tsconfig/cases/simple-paths/tsconfig.json new file mode 100644 index 00000000..071bf3fe --- /dev/null +++ b/fixtures/tsconfig/cases/simple-paths/tsconfig.json @@ -0,0 +1,7 @@ +{ + "compilerOptions": { + "paths": { + "bar/*": ["./bar/*"] + } + } +} diff --git a/src/tests/tsconfig_paths.rs b/src/tests/tsconfig_paths.rs index 4146afa7..783551f7 100644 --- a/src/tests/tsconfig_paths.rs +++ b/src/tests/tsconfig_paths.rs @@ -292,6 +292,54 @@ fn test_parent_base_url() { } } +#[test] +fn test_tsconfig_mixed_root_non_root_cache() { + let f = super::fixture_root().join("tsconfig"); + let f2 = f.join("cases").join("simple-paths"); + + // NOTE: should remove this line before merging as it's not thread safe + std::env::set_current_dir(&f2).unwrap(); + + let resolver = Resolver::new(ResolveOptions { + tsconfig: Some(TsconfigDiscovery::Auto), + ..ResolveOptions::default() + }); + resolver.cache.get_tsconfig(false, &f2.join("tsconfig.json"), |_| Ok(())).unwrap(); + let resolved_path = + resolver.resolve_file(f2.join("foo.ts"), "bar/index.ts").map(|f| f.full_path()); + assert_eq!(resolved_path, Ok(f2.join("bar/index.ts"))); +} + +#[test] +fn test_tsconfig_mixed_root_non_root_cache2() { + let f = super::fixture_root().join("tsconfig"); + let f2 = f.join("cases").join("extends-paths"); + + let resolver = Resolver::new(ResolveOptions { + tsconfig: Some(TsconfigDiscovery::Auto), + ..ResolveOptions::default() + }); + resolver.cache.get_tsconfig(true, &f2.join("tsconfig.base.json"), |_| Ok(())).unwrap(); + let resolved_path = + resolver.resolve_file(f2.join("test.ts"), "@/index.js").map(|f| f.full_path()); + assert_eq!(resolved_path, Ok(f2.join("src/index.js"))); +} + +#[test] +fn test_tsconfig_mixed_root_non_root_cache3() { + let f = super::fixture_root().join("tsconfig"); + let f2 = f.join("cases").join("extends-paths"); + + let resolver = Resolver::new(ResolveOptions { + tsconfig: Some(TsconfigDiscovery::Auto), + ..ResolveOptions::default() + }); + resolver.cache.get_tsconfig(false, &f2.join("tsconfig.json"), |_| Ok(())).unwrap(); + let resolved_path = + resolver.resolve_file(f2.join("test.ts"), "@/index.js").map(|f| f.full_path()); + assert_eq!(resolved_path, Ok(f2.join("src/index.js"))); +} + #[cfg(not(target_os = "windows"))] // MemoryFS's path separator is always `/` so the test will not pass in windows. mod windows_test { use std::path::{Path, PathBuf};