Skip to content

Commit 4ea9964

Browse files
authored
chore(tests): prefer --install-directory over PATH manipulation (#797)
1 parent fdbd751 commit 4ea9964

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

tests/Disable.test.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,10 @@ describe(`DisableCommand`, () => {
8080
const dontRemoveBin = await makeBin(cwd, `dont-remove` as Filename);
8181
binNames.add(ppath.basename(dontRemoveBin));
8282

83-
process.env.PATH = `${npath.fromPortablePath(cwd)}${delimiter}${process.env.PATH}`;
84-
await expect(runCli(cwd, [`disable`, `yarn`])).resolves.toMatchObject({
83+
await expect(runCli(cwd, [`disable`, `--install-directory=${npath.fromPortablePath(cwd)}`, `yarn`])).resolves.toMatchObject({
8584
exitCode: 0,
85+
stdout: ``,
86+
stderr: ``,
8687
});
8788

8889
for (const variant of getBinaryNames(`yarn`))
@@ -103,17 +104,23 @@ describe(`DisableCommand`, () => {
103104
await xfs.mkdirPromise(ppath.join(cwd, `switch/bin`), {recursive: true});
104105
await xfs.writeFilePromise(ppath.join(cwd, `switch/bin/yarn`), `hello`);
105106

106-
await xfs.linkPromise(
107+
await xfs.symlinkPromise(
107108
ppath.join(cwd, `switch/bin/yarn`),
108109
ppath.join(cwd, `yarn`),
109110
);
110111

111-
await expect(runCli(cwd, [`disable`])).resolves.toMatchObject({
112+
const isWindows = process.platform === `win32`; // Yarn Switch support is Posix-only
113+
await expect(runCli(cwd, [`disable`, `--install-directory=${npath.fromPortablePath(cwd)}`])).resolves.toMatchObject({
114+
stdout: ``,
115+
stderr: isWindows ? `` : expect.stringMatching(/^yarn is already installed in .+ and points to a Yarn Switch install - skipping\n$/),
112116
exitCode: 0,
113117
});
114118

115-
const file = await xfs.readFilePromise(ppath.join(cwd, `yarn`), `utf8`);
116-
expect(file).toBe(`hello`);
119+
if (isWindows) {
120+
expect(xfs.existsSync(ppath.join(cwd, `yarn`))).toBe(false);
121+
} else {
122+
await expect(xfs.readFilePromise(ppath.join(cwd, `yarn`), `utf8`)).resolves.toBe(`hello`);
123+
}
117124
});
118125
});
119126
});

tests/Enable.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ describe(`EnableCommand`, () => {
7070
await xfs.mktempPromise(async cwd => {
7171
const corepackBin = await makeBin(cwd, `corepack` as Filename);
7272

73-
process.env.PATH = `${npath.fromPortablePath(cwd)}${delimiter}${process.env.PATH}`;
74-
await expect(runCli(cwd, [`enable`, `yarn`])).resolves.toMatchObject({
73+
await expect(runCli(cwd, [`enable`, `--install-directory=${npath.fromPortablePath(cwd)}`, `yarn`])).resolves.toMatchObject({
7574
stdout: ``,
7675
stderr: ``,
7776
exitCode: 0,

0 commit comments

Comments
 (0)