@@ -75,40 +75,38 @@ test('--mutex network', async () => {
7575
7676test ( 'cache folder fallback' , async ( ) => {
7777 const cwd = await makeTemp ( ) ;
78- const cacheFolder = path . join ( cwd , '.cache' ) ;
79-
80- await fs . mkdirp ( cacheFolder ) ;
78+ const cacheFolder = path . join (
79+ process . platform !== 'win32' ? cwd : `${ process . env . SYSTEMDRIVE } /Windows/System32/etc/drivers/clowntown` ,
80+ '.cache' ,
81+ ) ;
8182
8283 const command = path . resolve ( __dirname , '../bin/yarn' ) ;
8384 const args = [ '--preferred-cache-folder' , cacheFolder ] ;
8485
8586 const options = { cwd} ;
8687
87- {
88+ function runCacheDir ( ) : Promise < Array < Buffer >> {
8889 const { stderr, stdout} = execa ( command , [ 'cache' , 'dir' ] . concat ( args ) , options ) ;
8990
9091 const stdoutPromise = misc . consumeStream ( stdout ) ;
9192 const stderrPromise = misc . consumeStream ( stderr ) ;
9293
93- const [ stdoutOutput , stderrOutput ] = await Promise . all ( [ stdoutPromise , stderrPromise ] ) ;
94-
95- expect ( stdoutOutput . toString ( ) . trim ( ) ) . toEqual ( path . join ( cacheFolder , `v${ constants . CACHE_VERSION } ` ) ) ;
96- expect ( stderrOutput . toString ( ) ) . not . toMatch ( / S k i p p i n g p r e f e r r e d c a c h e f o l d e r / ) ;
94+ return Promise . all ( [ stdoutPromise , stderrPromise ] ) ;
9795 }
9896
99- await fs . chmod ( cacheFolder , 0o000 ) ;
97+ const [ stdoutOutput , stderrOutput ] = await runCacheDir ( ) ;
10098
101- {
102- const { stderr , stdout } = execa ( command , [ 'cache' , 'dir' ] . concat ( args ) , options ) ;
99+ expect ( stdoutOutput . toString ( ) . trim ( ) ) . toEqual ( path . join ( cacheFolder , `v ${ constants . CACHE_VERSION } ` ) ) ;
100+ expect ( stderrOutput . toString ( ) ) . not . toMatch ( / S k i p p i n g p r e f e r r e d c a c h e f o l d e r / ) ;
103101
104- const stdoutPromise = misc . consumeStream ( stdout ) ;
105- const stderrPromise = misc . consumeStream ( stderr ) ;
102+ // Note that this shouldn't have any effect on Windows, hence why we try to use the System32 directory instead
103+ // Since System32 is a system file, it shouldn't be writable by the current user, and should Yarn should fallback
104+ await fs . chmod ( cacheFolder , 0o000 ) ;
106105
107- const [ stdoutOutput , stderrOutput ] = await Promise . all ( [ stdoutPromise , stderrPromise ] ) ;
106+ const [ stdoutOutput2 , stderrOutput2 ] = await runCacheDir ( ) ;
108107
109- expect ( stdoutOutput . toString ( ) . trim ( ) ) . toEqual (
110- path . join ( constants . PREFERRED_MODULE_CACHE_DIRECTORIES [ 0 ] , `v${ constants . CACHE_VERSION } ` ) ,
111- ) ;
112- expect ( stderrOutput . toString ( ) ) . toMatch ( / S k i p p i n g p r e f e r r e d c a c h e f o l d e r / ) ;
113- }
108+ expect ( stdoutOutput2 . toString ( ) . trim ( ) ) . toEqual (
109+ path . join ( constants . PREFERRED_MODULE_CACHE_DIRECTORIES [ 0 ] , `v${ constants . CACHE_VERSION } ` ) ,
110+ ) ;
111+ expect ( stderrOutput2 . toString ( ) ) . toMatch ( / S k i p p i n g p r e f e r r e d c a c h e f o l d e r / ) ;
114112} ) ;
0 commit comments