-
-
Notifications
You must be signed in to change notification settings - Fork 250
Expand file tree
/
Copy pathDisable.test.ts
More file actions
105 lines (85 loc) · 4.04 KB
/
Disable.test.ts
File metadata and controls
105 lines (85 loc) · 4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import {Filename, ppath, xfs, npath} from '@yarnpkg/fslib';
import assert from 'node:assert';
import {delimiter} from 'node:path';
import process from 'node:process';
import {describe, beforeEach, it} from 'node:test';
import {Engine} from '../sources/Engine';
import {SupportedPackageManagerSetWithoutNpm} from '../sources/types';
import {makeBin, getBinaryNames} from './_binHelpers';
import {runCli} from './_runCli';
const engine = new Engine();
beforeEach(async () => {
process.env.COREPACK_HOME = npath.fromPortablePath(await xfs.mktempPromise());
});
describe(`DisableCommand`, () => {
it(`should remove the binaries from the folder found in the PATH`, async () => {
await xfs.mktempPromise(async cwd => {
const corepackBin = await makeBin(cwd, `corepack` as Filename);
const dontRemoveBin = await makeBin(cwd, `dont-remove` as Filename);
for (const packageManager of SupportedPackageManagerSetWithoutNpm)
for (const binName of engine.getBinariesFor(packageManager))
for (const variant of getBinaryNames(binName))
await makeBin(cwd, variant as Filename, {ignorePlatform: true});
const PATH = process.env.PATH;
try {
process.env.PATH = `${npath.fromPortablePath(cwd)}${delimiter}${PATH}`;
assert.strictEqual((await runCli(cwd, [`disable`])).exitCode, 0);
} finally {
process.env.PATH = PATH;
}
const sortedEntries = xfs.readdirPromise(cwd).then(entries => {
return entries.sort();
});
assert.deepStrictEqual(await sortedEntries, [
ppath.basename(corepackBin),
ppath.basename(dontRemoveBin),
]);
});
});
it(`should remove the binaries from the specified folder when used with --install-directory`, async () => {
await xfs.mktempPromise(async cwd => {
const dontRemoveBin = await makeBin(cwd, `dont-remove` as Filename);
for (const packageManager of SupportedPackageManagerSetWithoutNpm)
for (const binName of engine.getBinariesFor(packageManager))
for (const variant of getBinaryNames(binName))
await makeBin(cwd, variant as Filename, {ignorePlatform: true});
const runResult = await runCli(cwd, [`disable`, `--install-directory`, npath.fromPortablePath(cwd)]);
assert.strictEqual(runResult.exitCode, 0);
const readdirResult = await xfs.readdirPromise(cwd);
assert.deepStrictEqual(readdirResult, [
ppath.basename(dontRemoveBin),
]);
});
});
it(`should remove binaries only for the requested package managers`, async () => {
await xfs.mktempPromise(async cwd => {
const binNames = new Set<string>();
for (const packageManager of SupportedPackageManagerSetWithoutNpm)
for (const binName of engine.getBinariesFor(packageManager))
for (const variant of getBinaryNames(binName))
binNames.add(variant);
for (const binName of binNames)
await makeBin(cwd, binName as Filename, {ignorePlatform: true});
const corepackBin = await makeBin(cwd, `corepack` as Filename);
binNames.add(ppath.basename(corepackBin));
const dontRemoveBin = await makeBin(cwd, `dont-remove` as Filename);
binNames.add(ppath.basename(dontRemoveBin));
const PATH = process.env.PATH;
try {
process.env.PATH = `${npath.fromPortablePath(cwd)}${delimiter}${PATH}`;
const runResult = await runCli(cwd, [`disable`, `yarn`]);
assert.strictEqual(runResult.exitCode, 0);
} finally {
process.env.PATH = PATH;
}
for (const variant of getBinaryNames(`yarn`))
binNames.delete(variant);
for (const variant of getBinaryNames(`yarnpkg`))
binNames.delete(variant);
const sortedEntries = await xfs.readdirPromise(cwd).then(entries => {
return entries.sort();
});
assert.deepStrictEqual(sortedEntries, [...binNames].sort());
});
});
});