forked from renovatebot/renovate
/
index.spec.ts
220 lines (212 loc) · 7.25 KB
/
index.spec.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
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
import upath from 'upath';
import { getName } from '../../test/util';
import { readFile } from '../util/fs';
import getArgv from './config/__fixtures__/argv';
import { getConfig } from './defaults';
jest.mock('../datasource/npm');
try {
jest.mock('../../config.js');
} catch (err) {
// file does not exist
}
const defaultConfig = getConfig();
describe(getName(), () => {
describe('.parseConfigs(env, defaultArgv)', () => {
let configParser: typeof import('.');
let defaultArgv: string[];
let defaultEnv: NodeJS.ProcessEnv;
beforeEach(async () => {
jest.resetModules();
configParser = await import('./index');
defaultArgv = getArgv();
defaultEnv = { RENOVATE_CONFIG_FILE: 'abc' };
jest.mock('delay', () => Promise.resolve());
});
it('supports token in env', async () => {
const env: NodeJS.ProcessEnv = { ...defaultEnv, RENOVATE_TOKEN: 'abc' };
const parsedConfig = await configParser.parseConfigs(env, defaultArgv);
expect(parsedConfig).toContainEntries([['token', 'abc']]);
});
it('supports token in CLI options', async () => {
defaultArgv = defaultArgv.concat([
'--token=abc',
'--pr-footer=custom',
'--log-context=abc123',
]);
const parsedConfig = await configParser.parseConfigs(
defaultEnv,
defaultArgv
);
expect(parsedConfig).toContainEntries([
['token', 'abc'],
['prFooter', 'custom'],
['logContext', 'abc123'],
]);
});
it('supports forceCli', async () => {
defaultArgv = defaultArgv.concat(['--force-cli=false']);
const env: NodeJS.ProcessEnv = {
...defaultEnv,
RENOVATE_TOKEN: 'abc',
};
const parsedConfig = await configParser.parseConfigs(env, defaultArgv);
expect(parsedConfig).toContainEntries([
['token', 'abc'],
['force', null],
]);
expect(parsedConfig).not.toContainKey('configFile');
});
it('supports config.force', async () => {
const configPath = upath.join(
__dirname,
'config/__fixtures__/with-force.js'
);
const env: NodeJS.ProcessEnv = {
...defaultEnv,
RENOVATE_CONFIG_FILE: configPath,
};
const parsedConfig = await configParser.parseConfigs(env, defaultArgv);
expect(parsedConfig).toContainEntries([
['token', 'abcdefg'],
[
'force',
{
schedule: null,
},
],
]);
});
it('reads private key from file', async () => {
const privateKeyPath = upath.join(
__dirname,
'keys/__fixtures__/private.pem'
);
const env: NodeJS.ProcessEnv = {
...defaultEnv,
RENOVATE_PRIVATE_KEY_PATH: privateKeyPath,
};
const expected = await readFile(privateKeyPath);
const parsedConfig = await configParser.parseConfigs(env, defaultArgv);
expect(parsedConfig).toContainEntries([['privateKey', expected]]);
});
it('supports Bitbucket username/passwod', async () => {
defaultArgv = defaultArgv.concat([
'--platform=bitbucket',
'--username=user',
'--password=pass',
]);
const parsedConfig = await configParser.parseConfigs(
defaultEnv,
defaultArgv
);
expect(parsedConfig).toContainEntries([
['platform', 'bitbucket'],
['username', 'user'],
['password', 'pass'],
]);
});
it('massages trailing slash into endpoint', async () => {
defaultArgv = defaultArgv.concat([
'--endpoint=https://github.renovatebot.com/api/v3',
]);
const parsed = await configParser.parseConfigs(defaultEnv, defaultArgv);
expect(parsed.endpoint).toEqual('https://github.renovatebot.com/api/v3/');
});
});
describe('mergeChildConfig(parentConfig, childConfig)', () => {
it('merges', async () => {
const parentConfig = { ...defaultConfig };
const childConfig = {
foo: 'bar',
rangeStrategy: 'replace',
lockFileMaintenance: {
schedule: ['on monday'],
},
};
const configParser = await import('./index');
const config = configParser.mergeChildConfig(parentConfig, childConfig);
expect(config.foo).toEqual('bar');
expect(config.rangeStrategy).toEqual('replace');
expect(config.lockFileMaintenance.schedule).toEqual(['on monday']);
expect(config.lockFileMaintenance).toMatchSnapshot();
});
it('merges packageRules', async () => {
const parentConfig = { ...defaultConfig };
Object.assign(parentConfig, {
packageRules: [{ a: 1 }, { a: 2 }],
});
const childConfig = {
packageRules: [{ a: 3 }, { a: 4 }],
};
const configParser = await import('./index');
const config = configParser.mergeChildConfig(parentConfig, childConfig);
expect(config.packageRules.map((rule) => rule.a)).toMatchObject([
1,
2,
3,
4,
]);
});
it('merges constraints', async () => {
const parentConfig = { ...defaultConfig };
Object.assign(parentConfig, {
constraints: {
node: '>=12',
npm: '^6.0.0',
},
});
const childConfig = {
constraints: {
node: '<15',
},
};
const configParser = await import('./index');
const config = configParser.mergeChildConfig(parentConfig, childConfig);
expect(config.constraints).toMatchSnapshot();
expect(config.constraints.node).toEqual('<15');
});
it('handles null parent packageRules', async () => {
const parentConfig = { ...defaultConfig };
Object.assign(parentConfig, {
packageRules: null,
});
const childConfig = {
packageRules: [{ a: 3 }, { a: 4 }],
};
const configParser = await import('./index');
const config = configParser.mergeChildConfig(parentConfig, childConfig);
expect(config.packageRules).toHaveLength(2);
});
it('handles null child packageRules', async () => {
const parentConfig = { ...defaultConfig };
parentConfig.packageRules = [{ a: 3 }, { a: 4 }];
const configParser = await import('./index');
const config = configParser.mergeChildConfig(parentConfig, {});
expect(config.packageRules).toHaveLength(2);
});
it('handles undefined childConfig', async () => {
const parentConfig = { ...defaultConfig };
const configParser = await import('./index');
const config = configParser.mergeChildConfig(parentConfig, undefined);
expect(config).toMatchObject(parentConfig);
});
it('getManagerConfig()', async () => {
const parentConfig = { ...defaultConfig };
const configParser = await import('./index');
const config = configParser.getManagerConfig(parentConfig, 'npm');
expect(config).toContainEntries([
['fileMatch', ['(^|/)package.json$']],
['rollbackPrs', true],
]);
expect(
configParser.getManagerConfig(parentConfig, 'html')
).toContainEntries([['fileMatch', ['\\.html?$']]]);
});
it('filterConfig()', async () => {
const parentConfig = { ...defaultConfig };
const configParser = await import('./index');
const config = configParser.filterConfig(parentConfig, 'pr');
expect(config).toBeObject();
});
});
});