-
Notifications
You must be signed in to change notification settings - Fork 683
Expand file tree
/
Copy pathPnpmOptionsConfiguration.test.ts
More file actions
141 lines (122 loc) · 4.47 KB
/
PnpmOptionsConfiguration.test.ts
File metadata and controls
141 lines (122 loc) · 4.47 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
import * as path from 'node:path';
import { PnpmOptionsConfiguration } from '../PnpmOptionsConfiguration';
import { TestUtilities } from '@rushstack/heft-config-file';
const fakeCommonTempFolder: string = path.join(__dirname, 'common', 'temp');
describe(PnpmOptionsConfiguration.name, () => {
it('throw error if pnpm-config.json does not exist', () => {
expect(() => {
PnpmOptionsConfiguration.loadFromJsonFileOrThrow(
`${__dirname}/pnpm-config-not-exist.json`,
fakeCommonTempFolder
);
}).toThrow(/does not exist/);
});
it('validates unknown property', () => {
expect(() =>
PnpmOptionsConfiguration.loadFromJsonFileOrThrow(
`${__dirname}/jsonFiles/pnpm-config-unknown.json`,
fakeCommonTempFolder
)
).toThrow(/must NOT have additional properties/);
});
it('loads overrides', () => {
const pnpmConfiguration: PnpmOptionsConfiguration = PnpmOptionsConfiguration.loadFromJsonFileOrThrow(
`${__dirname}/jsonFiles/pnpm-config-overrides.json`,
fakeCommonTempFolder
);
expect(TestUtilities.stripAnnotations(pnpmConfiguration.globalOverrides)).toEqual({
foo: '^1.0.0',
quux: 'npm:@myorg/quux@^1.0.0',
'bar@^2.1.0': '3.0.0',
'qar@1>zoo': '2'
});
expect(TestUtilities.stripAnnotations(pnpmConfiguration.environmentVariables)).toEqual({
NODE_OPTIONS: {
value: '--max-old-space-size=4096',
override: false
}
});
});
it('loads packageExtensions', () => {
const pnpmConfiguration: PnpmOptionsConfiguration = PnpmOptionsConfiguration.loadFromJsonFileOrThrow(
`${__dirname}/jsonFiles/pnpm-config-packageExtensions.json`,
fakeCommonTempFolder
);
expect(TestUtilities.stripAnnotations(pnpmConfiguration.globalPackageExtensions)).toEqual({
'react-redux': {
peerDependencies: {
'react-dom': '*'
}
}
});
});
it('loads neverBuiltDependencies', () => {
const pnpmConfiguration: PnpmOptionsConfiguration = PnpmOptionsConfiguration.loadFromJsonFileOrThrow(
`${__dirname}/jsonFiles/pnpm-config-neverBuiltDependencies.json`,
fakeCommonTempFolder
);
expect(TestUtilities.stripAnnotations(pnpmConfiguration.globalNeverBuiltDependencies)).toEqual([
'fsevents',
'level'
]);
});
it('loads onlyBuiltDependencies', () => {
const pnpmConfiguration: PnpmOptionsConfiguration = PnpmOptionsConfiguration.loadFromJsonFileOrThrow(
`${__dirname}/jsonFiles/pnpm-config-onlyBuiltDependencies.json`,
fakeCommonTempFolder
);
expect(TestUtilities.stripAnnotations(pnpmConfiguration.globalOnlyBuiltDependencies)).toEqual([
'esbuild',
'playwright',
'@swc/core'
]);
});
it('loads minimumReleaseAge', () => {
const pnpmConfiguration: PnpmOptionsConfiguration = PnpmOptionsConfiguration.loadFromJsonFileOrThrow(
`${__dirname}/jsonFiles/pnpm-config-minimumReleaseAge.json`,
fakeCommonTempFolder
);
expect(pnpmConfiguration.minimumReleaseAge).toEqual(1440);
expect(TestUtilities.stripAnnotations(pnpmConfiguration.minimumReleaseAgeExclude)).toEqual([
'webpack',
'@myorg/*'
]);
});
it('loads trustPolicy', () => {
const pnpmConfiguration: PnpmOptionsConfiguration = PnpmOptionsConfiguration.loadFromJsonFileOrThrow(
`${__dirname}/jsonFiles/pnpm-config-trustPolicy.json`,
fakeCommonTempFolder
);
expect(pnpmConfiguration.trustPolicy).toEqual('no-downgrade');
expect(TestUtilities.stripAnnotations(pnpmConfiguration.trustPolicyExclude)).toEqual([
'@myorg/*',
'chokidar@4.0.3',
'webpack@4.47.0 || 5.102.1',
'@babel/core@7.28.5'
]);
expect(pnpmConfiguration.trustPolicyIgnoreAfter).toEqual(20160);
});
it('loads catalog and catalogs', () => {
const pnpmConfiguration: PnpmOptionsConfiguration = PnpmOptionsConfiguration.loadFromJsonFileOrThrow(
`${__dirname}/jsonFiles/pnpm-config-catalog.json`,
fakeCommonTempFolder
);
expect(TestUtilities.stripAnnotations(pnpmConfiguration.globalCatalogs)).toEqual({
default: {
react: '^18.0.0',
'react-dom': '^18.0.0',
typescript: '~5.3.0'
},
frontend: {
vue: '^3.4.0',
'vue-router': '^4.2.0'
},
backend: {
express: '^4.18.0',
fastify: '^4.26.0'
}
});
});
});