@@ -11,6 +11,10 @@ import {runCli} from './
1111
1212const engine = new Engine ( ) ;
1313
14+ const testNotWindows = process . platform === `win32`
15+ ? it . skip
16+ : it ;
17+
1418beforeEach ( async ( ) => {
1519 // `process.env` is reset after each tests in setupTests.js.
1620 process . env . COREPACK_HOME = npath . fromPortablePath ( await xfs . mktempPromise ( ) ) ;
@@ -87,4 +91,42 @@ describe(`EnableCommand`, () => {
8791 await expect ( sortedEntries ) . resolves . toEqual ( expectedEntries . sort ( ) ) ;
8892 } ) ;
8993 } ) ;
94+
95+ testNotWindows ( `should overwrite existing files` , async ( ) => {
96+ await xfs . mktempPromise ( async cwd => {
97+ await xfs . writeFilePromise ( ppath . join ( cwd , `yarn` ) , `hello` ) ;
98+
99+ process . env . PATH = `${ npath . fromPortablePath ( cwd ) } ${ delimiter } ${ process . env . PATH } ` ;
100+ await expect ( runCli ( cwd , [ `enable` ] ) ) . resolves . toMatchObject ( {
101+ stdout : `` ,
102+ stderr : `` ,
103+ exitCode : 0 ,
104+ } ) ;
105+
106+ const file = await xfs . readFilePromise ( ppath . join ( cwd , `yarn` ) , `utf8` ) ;
107+ expect ( file ) . toBe ( `hello` ) ;
108+ } ) ;
109+ } ) ;
110+
111+ testNotWindows ( `shouldn't overwrite Yarn files if they are in a /switch/ folder` , async ( ) => {
112+ await xfs . mktempPromise ( async cwd => {
113+ await xfs . mkdirPromise ( ppath . join ( cwd , `switch` ) ) ;
114+ await xfs . writeFilePromise ( ppath . join ( cwd , `switch/yarn` ) , `hello` ) ;
115+
116+ await xfs . linkPromise (
117+ ppath . join ( cwd , `switch/yarn` ) ,
118+ ppath . join ( cwd , `yarn` ) ,
119+ ) ;
120+
121+ process . env . PATH = `${ npath . fromPortablePath ( cwd ) } ${ delimiter } ${ process . env . PATH } ` ;
122+ await expect ( runCli ( cwd , [ `enable` ] ) ) . resolves . toMatchObject ( {
123+ stdout : `` ,
124+ stderr : `` ,
125+ exitCode : 0 ,
126+ } ) ;
127+
128+ const file = await xfs . readFilePromise ( ppath . join ( cwd , `yarn` ) , `utf8` ) ;
129+ expect ( file ) . toBe ( `hello` ) ;
130+ } ) ;
131+ } ) ;
90132} ) ;
0 commit comments