-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
extract.spec.ts
144 lines (130 loc) · 5.17 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
import is from '@sindresorhus/is';
import { Fixtures } from '../../../../test/fixtures';
import { fs } from '../../../../test/util';
import { isValid } from '../../versioning/ruby';
import { extractPackageFile } from '.';
jest.mock('../../../util/fs');
const railsGemfile = Fixtures.get('Gemfile.rails');
const railsGemfileLock = Fixtures.get('Gemfile.rails.lock');
const sourceGroupGemfile = Fixtures.get('Gemfile.sourceGroup');
const webPackerGemfile = Fixtures.get('Gemfile.webpacker');
const webPackerGemfileLock = Fixtures.get('Gemfile.webpacker.lock');
const mastodonGemfile = Fixtures.get('Gemfile.mastodon');
const mastodonGemfileLock = Fixtures.get('Gemfile.mastodon.lock');
const rubyCIGemfileLock = Fixtures.get('Gemfile.rubyci.lock');
const rubyCIGemfile = Fixtures.get('Gemfile.rubyci');
const gitlabFossGemfileLock = Fixtures.get('Gemfile.gitlab-foss.lock');
const gitlabFossGemfile = Fixtures.get('Gemfile.gitlab-foss');
const sourceBlockGemfile = Fixtures.get('Gemfile.sourceBlock');
const sourceBlockWithNewLinesGemfileLock = Fixtures.get(
'Gemfile.sourceBlockWithNewLines.lock',
);
const sourceBlockWithNewLinesGemfile = Fixtures.get(
'Gemfile.sourceBlockWithNewLines',
);
const sourceBlockWithGroupsGemfile = Fixtures.get(
'Gemfile.sourceBlockWithGroups',
);
describe('modules/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) =>
Object.prototype.hasOwnProperty.call(dep, 'lockedVersion'),
)
.every(
(dep) => is.string(dep.lockedVersion) && isValid(dep.lockedVersion),
),
).toBeTrue();
expect(res?.deps).toHaveLength(68);
});
it('parses sourceGroups', async () => {
const res = await extractPackageFile(sourceGroupGemfile, 'Gemfile');
expect(res).toMatchSnapshot();
expect(res?.deps).toHaveLength(7);
});
it('parse webpacker Gemfile', async () => {
fs.readLocalFile.mockResolvedValueOnce(webPackerGemfileLock);
const res = await extractPackageFile(webPackerGemfile, 'Gemfile');
expect(res).toMatchSnapshot();
expect(
res?.deps.every(
(dep) => is.string(dep.lockedVersion) && isValid(dep.lockedVersion),
),
).toBeTrue();
expect(res?.deps).toHaveLength(5);
});
it('parse mastodon Gemfile', async () => {
fs.readLocalFile.mockResolvedValueOnce(mastodonGemfileLock);
const res = await extractPackageFile(mastodonGemfile, 'Gemfile');
expect(res).toMatchSnapshot();
expect(
res?.deps
.filter((dep) =>
Object.prototype.hasOwnProperty.call(dep, 'lockedVersion'),
)
.every(
(dep) => is.string(dep.lockedVersion) && isValid(dep.lockedVersion),
),
).toBeTrue();
expect(res?.deps).toHaveLength(125);
});
it('parse Ruby CI Gemfile', async () => {
fs.readLocalFile.mockResolvedValueOnce(rubyCIGemfileLock);
const res = await extractPackageFile(rubyCIGemfile, 'Gemfile');
expect(res).toMatchSnapshot();
expect(
res?.deps.every(
(dep) => is.string(dep.lockedVersion) && isValid(dep.lockedVersion),
),
).toBeTrue();
expect(res?.deps).toHaveLength(14);
});
});
it('parse Gitlab Foss Gemfile', async () => {
fs.readLocalFile.mockResolvedValueOnce(gitlabFossGemfileLock);
const res = await extractPackageFile(gitlabFossGemfile, 'Gemfile');
expect(res).toMatchSnapshot();
expect(
res?.deps.every(
(dep) => is.string(dep.lockedVersion) && isValid(dep.lockedVersion),
),
).toBeTrue();
expect(res?.deps).toHaveLength(252);
});
it('parse source blocks in Gemfile', async () => {
fs.readLocalFile.mockResolvedValueOnce(sourceBlockGemfile);
const res = await extractPackageFile(sourceBlockGemfile, 'Gemfile');
expect(res).toMatchSnapshot();
});
it('parse source blocks with spaces in Gemfile', async () => {
fs.readLocalFile.mockResolvedValueOnce(sourceBlockWithNewLinesGemfileLock);
const res = await extractPackageFile(
sourceBlockWithNewLinesGemfile,
'Gemfile',
);
expect(res).toMatchSnapshot();
expect(res?.deps).toHaveLength(2);
});
it('parses source blocks with groups in Gemfile', async () => {
fs.readLocalFile.mockResolvedValueOnce(sourceBlockWithGroupsGemfile);
const res = await extractPackageFile(
sourceBlockWithGroupsGemfile,
'Gemfile',
);
expect(res?.deps).toMatchObject([
{ depName: 'internal_test_gem', currentValue: '"~> 1"' },
{ depName: 'internal_production_gem', currentValue: '"~> 1"' },
{ depName: 'sfn_my_dep1', currentValue: '"~> 1"' },
{ depName: 'sfn_my_dep2', currentValue: '"~> 1"' },
]);
});
});