forked from renovatebot/renovate
/
extract.spec.ts
169 lines (162 loc) · 5.39 KB
/
extract.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
import { readFileSync } from 'fs';
import { fs } from '../../../test/util';
import { isValid } from '../../versioning/ruby';
import { extractPackageFile } from './extract';
jest.mock('../../util/fs');
const railsGemfile = readFileSync(
'lib/manager/bundler/__fixtures__/Gemfile.rails',
'utf8'
);
const railsGemfileLock = readFileSync(
'lib/manager/bundler/__fixtures__/Gemfile.rails.lock',
'utf8'
);
const sourceGroupGemfile = readFileSync(
'lib/manager/bundler/__fixtures__/Gemfile.sourceGroup',
'utf8'
);
const webPackerGemfile = readFileSync(
'lib/manager/bundler/__fixtures__/Gemfile.webpacker',
'utf8'
);
const webPackerGemfileLock = readFileSync(
'lib/manager/bundler/__fixtures__/Gemfile.webpacker.lock',
'utf8'
);
const mastodonGemfile = readFileSync(
'lib/manager/bundler/__fixtures__/Gemfile.mastodon',
'utf8'
);
const mastodonGemfileLock = readFileSync(
'lib/manager/bundler/__fixtures__/Gemfile.mastodon.lock',
'utf8'
);
const rubyCIGemfileLock = readFileSync(
'lib/manager/bundler/__fixtures__/Gemfile.rubyci.lock',
'utf8'
);
const rubyCIGemfile = readFileSync(
'lib/manager/bundler/__fixtures__/Gemfile.rubyci',
'utf8'
);
const gitlabFossGemfileLock = readFileSync(
'lib/manager/bundler/__fixtures__/Gemfile.gitlab-foss.lock',
'utf8'
);
const gitlabFossGemfile = readFileSync(
'lib/manager/bundler/__fixtures__/Gemfile.gitlab-foss',
'utf8'
);
const sourceBlockWithNewLinesGemfileLock = readFileSync(
'lib/manager/bundler/__fixtures__/Gemfile.sourceBlockWithNewLines.lock',
'utf8'
);
const sourceBlockWithNewLinesGemfile = readFileSync(
'lib/manager/bundler/__fixtures__/Gemfile.sourceBlockWithNewLines',
'utf8'
);
function validateGems(raw, parsed) {
const gemfileGemCount = raw.match(/\n\s*gem\s+/g).length;
const parsedGemCount = parsed.deps.length;
expect(gemfileGemCount).toEqual(parsedGemCount);
}
describe('lib/manager/bundler/extract', () => {
describe('extractPackageFile()', () => {
it('returns null for empty', async () => {
expect(await extractPackageFile('nothing here', 'Gemfile')).toBeNull();
});
it('parses rails Gemfile', async () => {
fs.readLocalFile.mockResolvedValueOnce(railsGemfileLock);
const res = await extractPackageFile(railsGemfile, 'Gemfile');
expect(res).toMatchSnapshot();
// couple of dependency of ruby rails are not present in the lock file. Filter out those before processing
expect(
res.deps
.filter((dep) => {
return Object.prototype.hasOwnProperty.call(dep, 'lockedVersion');
})
.every((dep) => {
return (
Object.prototype.hasOwnProperty.call(dep, 'lockedVersion') &&
isValid(dep.lockedVersion)
);
})
).toBe(true);
validateGems(railsGemfile, res);
});
it('parses sourceGroups', async () => {
const res = await extractPackageFile(sourceGroupGemfile, 'Gemfile');
expect(res).toMatchSnapshot();
validateGems(sourceGroupGemfile, res);
});
it('parse webpacker Gemfile', async () => {
fs.readLocalFile.mockResolvedValueOnce(webPackerGemfileLock);
const res = await extractPackageFile(webPackerGemfile, 'Gemfile');
expect(res).toMatchSnapshot();
expect(
res.deps.every((dep) => {
return (
Object.prototype.hasOwnProperty.call(dep, 'lockedVersion') &&
isValid(dep.lockedVersion)
);
})
).toBe(true);
validateGems(webPackerGemfile, res);
});
it('parse mastodon Gemfile', async () => {
fs.readLocalFile.mockResolvedValueOnce(mastodonGemfileLock);
const res = await extractPackageFile(mastodonGemfile, 'Gemfile');
expect(res).toMatchSnapshot();
expect(
res.deps
.filter((dep) => {
return Object.prototype.hasOwnProperty.call(dep, 'lockedVersion');
})
.every((dep) => {
return (
Object.prototype.hasOwnProperty.call(dep, 'lockedVersion') &&
isValid(dep.lockedVersion)
);
})
).toBe(true);
validateGems(mastodonGemfile, res);
});
it('parse Ruby CI Gemfile', async () => {
fs.readLocalFile.mockResolvedValueOnce(rubyCIGemfileLock);
const res = await extractPackageFile(rubyCIGemfile, 'Gemfile');
expect(res).toMatchSnapshot();
expect(
res.deps.every((dep) => {
return (
Object.prototype.hasOwnProperty.call(dep, 'lockedVersion') &&
isValid(dep.lockedVersion)
);
})
).toBe(true);
validateGems(rubyCIGemfile, res);
});
});
it('parse Gitlab Foss Gemfile', async () => {
fs.readLocalFile.mockResolvedValueOnce(gitlabFossGemfileLock);
const res = await extractPackageFile(gitlabFossGemfile, 'Gemfile');
expect(res).toMatchSnapshot();
expect(
res.deps.every((dep) => {
return (
Object.prototype.hasOwnProperty.call(dep, 'lockedVersion') &&
isValid(dep.lockedVersion)
);
})
).toBe(true);
validateGems(gitlabFossGemfile, res);
});
it('parse source blocks with spaces in Gemfile', async () => {
fs.readLocalFile.mockResolvedValueOnce(sourceBlockWithNewLinesGemfileLock);
const res = await extractPackageFile(
sourceBlockWithNewLinesGemfile,
'Gemfile'
);
expect(res).toMatchSnapshot();
validateGems(sourceBlockWithNewLinesGemfile, res);
});
});