|
1 | 1 | import {Filename, ppath, xfs, npath} from '@yarnpkg/fslib'; |
2 | 2 | import {delimiter} from 'node:path'; |
3 | 3 | import process from 'node:process'; |
4 | | -import {describe, beforeEach, it, expect} from 'vitest'; |
| 4 | +import {describe, beforeEach, it, expect, test} from 'vitest'; |
5 | 5 |
|
6 | 6 | import {Engine} from '../sources/Engine'; |
7 | 7 | import {SupportedPackageManagers, SupportedPackageManagerSetWithoutNpm} from '../sources/types'; |
@@ -87,4 +87,42 @@ describe(`EnableCommand`, () => { |
87 | 87 | await expect(sortedEntries).resolves.toEqual(expectedEntries.sort()); |
88 | 88 | }); |
89 | 89 | }); |
| 90 | + |
| 91 | + test.skipIf(process.platform === `win32`)(`should overwrite existing files`, async () => { |
| 92 | + await xfs.mktempPromise(async cwd => { |
| 93 | + await xfs.writeFilePromise(ppath.join(cwd, `yarn`), `hello`); |
| 94 | + |
| 95 | + process.env.PATH = `${npath.fromPortablePath(cwd)}${delimiter}${process.env.PATH}`; |
| 96 | + await expect(runCli(cwd, [`enable`])).resolves.toMatchObject({ |
| 97 | + stdout: ``, |
| 98 | + stderr: ``, |
| 99 | + exitCode: 0, |
| 100 | + }); |
| 101 | + |
| 102 | + const file = await xfs.readFilePromise(ppath.join(cwd, `yarn`), `utf8`); |
| 103 | + expect(file).toBe(`hello`); |
| 104 | + }); |
| 105 | + }); |
| 106 | + |
| 107 | + test.skipIf(process.platform === `win32`)(`shouldn't overwrite Yarn files if they are in a /switch/ folder`, async () => { |
| 108 | + await xfs.mktempPromise(async cwd => { |
| 109 | + await xfs.mkdirPromise(ppath.join(cwd, `switch/bin`), {recursive: true}); |
| 110 | + await xfs.writeFilePromise(ppath.join(cwd, `switch/bin/yarn`), `hello`); |
| 111 | + |
| 112 | + await xfs.linkPromise( |
| 113 | + ppath.join(cwd, `switch/bin/yarn`), |
| 114 | + ppath.join(cwd, `yarn`), |
| 115 | + ); |
| 116 | + |
| 117 | + process.env.PATH = `${npath.fromPortablePath(cwd)}${delimiter}${process.env.PATH}`; |
| 118 | + await expect(runCli(cwd, [`enable`])).resolves.toMatchObject({ |
| 119 | + stdout: ``, |
| 120 | + stderr: ``, |
| 121 | + exitCode: 0, |
| 122 | + }); |
| 123 | + |
| 124 | + const file = await xfs.readFilePromise(ppath.join(cwd, `yarn`), `utf8`); |
| 125 | + expect(file).toBe(`hello`); |
| 126 | + }); |
| 127 | + }); |
90 | 128 | }); |
0 commit comments