-
Notifications
You must be signed in to change notification settings - Fork 682
Expand file tree
/
Copy pathPnpmOptionsConfiguration.test.ts
More file actions
192 lines (163 loc) · 6.29 KB
/
PnpmOptionsConfiguration.test.ts
File metadata and controls
192 lines (163 loc) · 6.29 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
// 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';
import { EnvironmentConfiguration } from '../../../api/EnvironmentConfiguration';
import type { RushUserConfiguration } from '../../../api/RushUserConfiguration';
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 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'
}
});
});
it('uses default store path when no user configuration is provided', () => {
const pnpmConfiguration: PnpmOptionsConfiguration = PnpmOptionsConfiguration.loadFromJsonObject(
{},
fakeCommonTempFolder
);
expect(pnpmConfiguration.pnpmStorePath).toEqual(`${fakeCommonTempFolder}/pnpm-store`);
});
it('uses user configuration storePath when provided', () => {
const mockUserConfig: Partial<RushUserConfiguration> = {
buildCacheFolder: undefined,
pnpmStorePath: '/custom/pnpm/store'
};
const pnpmConfiguration: PnpmOptionsConfiguration = PnpmOptionsConfiguration.loadFromJsonObject(
{},
fakeCommonTempFolder,
mockUserConfig as RushUserConfiguration
);
expect(pnpmConfiguration.pnpmStorePath).toEqual('/custom/pnpm/store');
});
it('environment variable takes precedence over user configuration', () => {
// Save original value
const originalEnvValue = process.env.RUSH_PNPM_STORE_PATH;
try {
// Set environment variable with a path that will be normalized
// Use an absolute path like the temp folder
const envStorePath: string = path.join(fakeCommonTempFolder, 'env-pnpm-store');
process.env.RUSH_PNPM_STORE_PATH = envStorePath;
// Re-validate environment configuration to pick up the change
EnvironmentConfiguration.reset();
EnvironmentConfiguration.validate();
const mockUserConfig: Partial<RushUserConfiguration> = {
buildCacheFolder: undefined,
pnpmStorePath: '/custom/pnpm/store'
};
const pnpmConfiguration: PnpmOptionsConfiguration = PnpmOptionsConfiguration.loadFromJsonObject(
{},
fakeCommonTempFolder,
mockUserConfig as RushUserConfiguration
);
// The environment variable value should be used (after normalization)
expect(pnpmConfiguration.pnpmStorePath).toContain('env-pnpm-store');
} finally {
// Restore original value
if (originalEnvValue !== undefined) {
process.env.RUSH_PNPM_STORE_PATH = originalEnvValue;
} else {
delete process.env.RUSH_PNPM_STORE_PATH;
}
// Re-validate to restore original state
EnvironmentConfiguration.reset();
EnvironmentConfiguration.validate();
}
});
});