@@ -75,40 +75,38 @@ test('--mutex network', async () => {
75
75
76
76
test ( 'cache folder fallback' , async ( ) => {
77
77
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
+ ) ;
81
82
82
83
const command = path . resolve ( __dirname , '../bin/yarn' ) ;
83
84
const args = [ '--preferred-cache-folder' , cacheFolder ] ;
84
85
85
86
const options = { cwd} ;
86
87
87
- {
88
+ function runCacheDir ( ) : Promise < Array < Buffer >> {
88
89
const { stderr, stdout} = execa ( command , [ 'cache' , 'dir' ] . concat ( args ) , options ) ;
89
90
90
91
const stdoutPromise = misc . consumeStream ( stdout ) ;
91
92
const stderrPromise = misc . consumeStream ( stderr ) ;
92
93
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 ] ) ;
97
95
}
98
96
99
- await fs . chmod ( cacheFolder , 0o000 ) ;
97
+ const [ stdoutOutput , stderrOutput ] = await runCacheDir ( ) ;
100
98
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 / ) ;
103
101
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 ) ;
106
105
107
- const [ stdoutOutput , stderrOutput ] = await Promise . all ( [ stdoutPromise , stderrPromise ] ) ;
106
+ const [ stdoutOutput2 , stderrOutput2 ] = await runCacheDir ( ) ;
108
107
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 / ) ;
114
112
} ) ;
0 commit comments