-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
index.spec.ts
238 lines (234 loc) · 6.79 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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
import fs from 'fs';
import _got from '../../util/got';
import * as datasource from '..';
import * as _hostRules from '../../util/host-rules';
import * as composerVersioning from '../../versioning/composer';
import { DATASOURCE_PACKAGIST } from '../../constants/data-binary-source';
jest.mock('../../util/got');
jest.mock('../../util/host-rules');
const got: any = _got;
const hostRules = _hostRules;
const includesJson: any = fs.readFileSync(
'lib/datasource/packagist/__fixtures__/includes.json'
);
const beytJson: any = fs.readFileSync(
'lib/datasource/packagist/__fixtures__/1beyt.json'
);
const mailchimpJson: any = fs.readFileSync(
'lib/datasource/packagist/__fixtures__/mailchimp-api.json'
);
describe('datasource/packagist', () => {
describe('getPkgReleases', () => {
let config: datasource.PkgReleaseConfig;
beforeEach(() => {
jest.resetAllMocks();
hostRules.find = jest.fn(input => input);
hostRules.hosts = jest.fn(() => []);
global.repoCache = {};
config = {
versioning: composerVersioning.id,
datasource: DATASOURCE_PACKAGIST,
registryUrls: [
'https://composer.renovatebot.com',
'https://packagist.org',
],
};
return global.renovateCache.rmAll();
});
it('supports custom registries', async () => {
config = {
datasource: DATASOURCE_PACKAGIST,
registryUrls: ['https://composer.renovatebot.com'],
};
const res = await datasource.getPkgReleases({
...config,
lookupName: 'something/one',
});
expect(res).toBeNull();
});
it('supports plain packages', async () => {
const packagesOnly = {
packages: {
'vendor/package-name': {
'dev-master': {},
'1.0.x-dev': {},
'0.0.1': {},
'1.0.0': {},
},
},
};
got.mockReturnValueOnce({
body: packagesOnly,
});
const res = await datasource.getPkgReleases({
...config,
lookupName: 'vendor/package-name',
});
expect(res).toMatchSnapshot();
});
it('handles timeouts', async () => {
got.mockImplementationOnce(() =>
Promise.reject({
code: 'ETIMEDOUT',
})
);
const res = await datasource.getPkgReleases({
...config,
lookupName: 'vendor/package-name2',
});
expect(res).toBeNull();
});
it('handles auth rejections', async () => {
got.mockImplementationOnce(() =>
Promise.reject({
statusCode: 403,
})
);
const res = await datasource.getPkgReleases({
...config,
lookupName: 'vendor/package-name',
});
expect(res).toBeNull();
});
it('handles not found registries', async () => {
got.mockImplementationOnce(() =>
Promise.reject({
statusCode: 404,
url: 'https://some.registry/packages.json',
})
);
const res = await datasource.getPkgReleases({
...config,
lookupName: 'drewm/mailchip-api',
});
expect(res).toBeNull();
});
it('supports includes packages', async () => {
hostRules.find = jest.fn(() => ({
username: 'some-username',
password: 'some-password',
}));
const packagesJson = {
packages: [],
includes: {
'include/all$afbf74d51f31c7cbb5ff10304f9290bfb4f4e68b.json': {
sha1: 'afbf74d51f31c7cbb5ff10304f9290bfb4f4e68b',
},
},
};
got.mockReturnValueOnce({
body: packagesJson,
});
got.mockReturnValueOnce({
body: JSON.parse(includesJson),
});
const res = await datasource.getPkgReleases({
...config,
lookupName: 'guzzlehttp/guzzle',
});
expect(res).toMatchSnapshot();
expect(res).not.toBeNull();
});
it('supports providers packages', async () => {
const packagesJson = {
packages: [],
'providers-url': '/p/%package%$%hash%.json',
'provider-includes': {
'p/providers-2018-09$%hash%.json': {
sha256:
'14346045d7a7261cb3a12a6b7a1a7c4151982530347b115e5e277d879cad1942',
},
},
};
got.mockReturnValueOnce({
body: packagesJson,
});
const fileJson = {
providers: {
'wpackagist-plugin/1337-rss-feed-made-for-sharing': {
sha256:
'e9b6c98c63f99e59440863a044cc80dd9cddbf5c426b05003dba98983b5757de',
},
'wpackagist-plugin/1beyt': {
sha256:
'b574a802b5bf20a58c0f027e73aea2a75d23a6f654afc298a8dc467331be316a',
},
},
};
got.mockReturnValueOnce({
body: fileJson,
});
got.mockReturnValueOnce({
body: JSON.parse(beytJson),
});
const res = await datasource.getPkgReleases({
...config,
lookupName: 'wpackagist-plugin/1beyt',
});
expect(res).toMatchSnapshot();
expect(res).not.toBeNull();
});
it('handles providers packages miss', async () => {
const packagesJson = {
packages: [],
'providers-url': '/p/%package%$%hash%.json',
'provider-includes': {
'p/providers-2018-09$%hash%.json': {
sha256:
'14346045d7a7261cb3a12a6b7a1a7c4151982530347b115e5e277d879cad1942',
},
},
};
got.mockReturnValueOnce({
body: packagesJson,
});
const fileJson = {
providers: {
'wpackagist-plugin/1337-rss-feed-made-for-sharing': {
sha256:
'e9b6c98c63f99e59440863a044cc80dd9cddbf5c426b05003dba98983b5757de',
},
'wpackagist-plugin/1beyt': {
sha256:
'b574a802b5bf20a58c0f027e73aea2a75d23a6f654afc298a8dc467331be316a',
},
},
};
got.mockReturnValueOnce({
body: fileJson,
});
got.mockReturnValueOnce({
body: JSON.parse(beytJson),
});
const res = await datasource.getPkgReleases({
...config,
lookupName: 'some/other',
});
expect(res).toBeNull();
});
it('processes real versioned data', async () => {
got.mockReturnValueOnce({
body: JSON.parse(mailchimpJson),
});
config.registryUrls = ['https://packagist.org'];
expect(
await datasource.getPkgReleases({
...config,
lookupName: 'drewm/mailchimp-api',
})
).toMatchSnapshot();
});
it('adds packagist source implicitly', async () => {
got.mockReturnValueOnce({
body: JSON.parse(mailchimpJson),
});
config.registryUrls = [];
expect(
await datasource.getPkgReleases({
...config,
lookupName: 'drewm/mailchimp-api',
})
).toMatchSnapshot();
});
});
});