@@ -20,12 +20,12 @@ struct TestSuite {
2020
2121#[ cfg( test) ]
2222mod tests {
23- use std:: { fs, path:: PathBuf } ;
23+ use std:: { env , fs, path:: PathBuf } ;
2424
2525 use super :: * ;
2626 use crate :: {
2727 ResolutionConfig , ResolutionHost , init_pnp_manifest, load_pnp_manifest,
28- parse_bare_identifier, resolve_to_unqualified, resolve_to_unqualified_via_manifest,
28+ parse_bare_identifier, resolve_to_unqualified, resolve_to_unqualified_via_manifest, util ,
2929 } ;
3030
3131 #[ test]
@@ -162,4 +162,55 @@ mod tests {
162162 let parsed = parse_bare_identifier ( "@scope/pkg/a/b/c/index.js" ) ;
163163 assert_eq ! ( parsed, Ok ( ( "@scope/pkg" . to_string( ) , Some ( "a/b/c/index.js" . to_string( ) ) ) ) ) ;
164164 }
165+
166+ #[ test]
167+ fn test_global_cache ( ) {
168+ let manifest = load_pnp_manifest (
169+ env:: current_dir ( )
170+ . unwrap ( )
171+ . join ( "fixtures" )
172+ . join ( "global-cache" )
173+ . join ( ".pnp.cjs" )
174+ . as_path ( ) ,
175+ )
176+ . unwrap ( ) ;
177+
178+ let home_dir = dirs:: home_dir ( ) . unwrap ( ) ;
179+
180+ #[ cfg( windows) ]
181+ let global_cache = home_dir. join ( "AppData\\ Local\\ Yarn\\ Berry\\ cache" ) ;
182+ #[ cfg( not( windows) ) ]
183+ let global_cache = home_dir. join ( ".yarn/berry/cache" ) ;
184+
185+ let result = resolve_to_unqualified_via_manifest (
186+ & manifest,
187+ "source-map" ,
188+ global_cache
189+ . join ( "source-map-support-npm-0.5.21-09ca99e250-10c0.zip" )
190+ . join ( "node_modules" )
191+ . join ( "source-map-support" )
192+ . join ( "" )
193+ . as_path ( ) ,
194+ ) ;
195+
196+ match result {
197+ Ok ( Resolution :: Resolved ( path, subpath) ) => {
198+ assert_eq ! (
199+ path. to_string_lossy( ) ,
200+ util:: normalize_path(
201+ global_cache
202+ . join( "source-map-npm-0.6.1-1a3621db16-10c0.zip" )
203+ . join( "node_modules" )
204+ . join( "source-map" )
205+ . join( "" )
206+ . to_string_lossy( )
207+ )
208+ ) ;
209+ assert_eq ! ( subpath, None ) ;
210+ }
211+ _ => {
212+ panic ! ( "Unexpected resolve failed" ) ;
213+ }
214+ }
215+ }
165216}
0 commit comments