-
-
Notifications
You must be signed in to change notification settings - Fork 198
/
Copy pathUse.test.ts
80 lines (66 loc) · 2.62 KB
/
Use.test.ts
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
import {ppath, xfs, npath} from '@yarnpkg/fslib';
import assert from 'node:assert';
import process from 'node:process';
import {describe, beforeEach, it} from 'node:test';
import {runCli} from './_runCli';
function expect(promise: Promise<Record<string, unknown>>) {
return {
resolves: {
async toMatchObject(expected: Record<string, unknown>) {
const result = await promise;
assert.deepStrictEqual(Object.fromEntries(Object.entries(result).filter(e => e[0] in expected)), expected);
},
},
};
}
beforeEach(async () => {
process.env.COREPACK_HOME = npath.fromPortablePath(await xfs.mktempPromise());
process.env.COREPACK_DEFAULT_TO_LATEST = `0`;
});
describe(`UseCommand`, () => {
it(`should set the package manager in the current project`, async () => {
await xfs.mktempPromise(async cwd => {
await xfs.writeJsonPromise(ppath.join(cwd, `package.json`), {
});
exitCode: 0,
});
await expect(xfs.readJsonPromise(ppath.join(cwd, `package.json`))).resolves.toMatchObject({
packageManager: `[email protected]+sha256.bc5316aa110b2f564a71a3d6e235be55b98714660870c5b6b2d2d3f12587fb58`,
});
await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({
exitCode: 0,
stdout: `1.22.4\n`,
});
});
});
it(`should create a package.json if absent`, async () => {
await xfs.mktempPromise(async cwd => {
exitCode: 0,
stderr: `warning package.json: No license field\nwarning No license field\n`,
});
await expect(xfs.readJsonPromise(ppath.join(cwd, `package.json`))).resolves.toMatchObject({
packageManager: `[email protected]+sha256.bc5316aa110b2f564a71a3d6e235be55b98714660870c5b6b2d2d3f12587fb58`,
});
await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({
exitCode: 0,
stdout: `1.22.4\n`,
stderr: ``,
});
// Ensure Corepack is able to detect package.json in parent directory
const subfolder = ppath.join(cwd, `subfolder`);
await xfs.mkdirPromise(subfolder);
exitCode: 0,
stderr: ``,
});
await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({
exitCode: 0,
stdout: `2.2.2\n`,
stderr: ``,
});
});
});
});