forked from renovatebot/renovate
/
package-tree.spec.ts
186 lines (164 loc) · 6.28 KB
/
package-tree.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
import { fs as memfs } from 'memfs';
import upath from 'upath';
import { Fixtures } from '../../../../test/fixtures';
import { scm } from '../../../../test/util';
import { GlobalConfig } from '../../../config/global';
import type { RepoGlobalConfig } from '../../../config/types';
import { getDependentPackageFiles } from './package-tree';
jest.mock('fs', () => memfs);
jest.mock('fs-extra', () => Fixtures.fsExtra());
jest.mock('../../../util/git');
const adminConfig: RepoGlobalConfig = {
localDir: upath.resolve('/tmp/repo'),
};
describe('modules/manager/nuget/package-tree', () => {
describe('getDependentPackageFiles()', () => {
beforeEach(() => {
GlobalConfig.set(adminConfig);
Fixtures.reset();
});
afterEach(() => {
GlobalConfig.reset();
Fixtures.reset();
});
it('returns self for single project', async () => {
scm.getFileList.mockResolvedValue(['single.csproj']);
Fixtures.mock({
'/tmp/repo/single.csproj': Fixtures.get(
'single-project-file/single.csproj'
),
});
expect(await getDependentPackageFiles('single.csproj')).toEqual([
{ isLeaf: true, name: 'single.csproj' },
]);
});
it('returns self for two projects with no references', async () => {
scm.getFileList.mockResolvedValue(['one.csproj', 'two.csproj']);
Fixtures.mock({
'/tmp/repo/one.csproj': Fixtures.get('two-no-reference/one.csproj'),
'/tmp/repo/two.csproj': Fixtures.get('two-no-reference/two.csproj'),
});
expect(await getDependentPackageFiles('one.csproj')).toEqual([
{ isLeaf: true, name: 'one.csproj' },
]);
expect(await getDependentPackageFiles('two.csproj')).toEqual([
{ isLeaf: true, name: 'two.csproj' },
]);
});
it('returns projects for two projects with one reference', async () => {
scm.getFileList.mockResolvedValue(['one/one.csproj', 'two/two.csproj']);
Fixtures.mock({
'/tmp/repo/one/one.csproj': Fixtures.get(
'two-one-reference/one/one.csproj'
),
'/tmp/repo/two/two.csproj': Fixtures.get(
'two-one-reference/two/two.csproj'
),
});
expect(await getDependentPackageFiles('one/one.csproj')).toEqual([
{ isLeaf: false, name: 'one/one.csproj' },
{ isLeaf: true, name: 'two/two.csproj' },
]);
});
it('returns project for two projects with one reference and central versions', async () => {
scm.getFileList.mockResolvedValue(['one/one.csproj', 'two/two.csproj']);
Fixtures.mock({
'/tmp/repo/one/one.csproj': Fixtures.get(
'two-one-reference-with-central-versions/one/one.csproj'
),
'/tmp/repo/two/two.csproj': Fixtures.get(
'two-one-reference-with-central-versions/two/two.csproj'
),
'/tmp/repo/Directory.Packages.props': Fixtures.get(
'two-one-reference-with-central-versions/Directory.Packages.props'
),
});
expect(
await getDependentPackageFiles('Directory.Packages.props', true)
).toEqual([
{ isLeaf: false, name: 'one/one.csproj' },
{ isLeaf: true, name: 'two/two.csproj' },
]);
});
it('returns projects for three projects with two linear references', async () => {
scm.getFileList.mockResolvedValue([
'one/one.csproj',
'two/two.csproj',
'three/three.csproj',
]);
Fixtures.mock({
'/tmp/repo/one/one.csproj': Fixtures.get(
'three-two-linear-references/one/one.csproj'
),
'/tmp/repo/two/two.csproj': Fixtures.get(
'three-two-linear-references/two/two.csproj'
),
'/tmp/repo/three/three.csproj': Fixtures.get(
'three-two-linear-references/three/three.csproj'
),
});
expect(await getDependentPackageFiles('one/one.csproj')).toEqual([
{ isLeaf: false, name: 'one/one.csproj' },
{ isLeaf: false, name: 'two/two.csproj' },
{ isLeaf: true, name: 'three/three.csproj' },
]);
expect(await getDependentPackageFiles('two/two.csproj')).toEqual([
{ isLeaf: false, name: 'two/two.csproj' },
{ isLeaf: true, name: 'three/three.csproj' },
]);
expect(await getDependentPackageFiles('three/three.csproj')).toEqual([
{ isLeaf: true, name: 'three/three.csproj' },
]);
});
it('returns projects for three projects with two tree-like references', async () => {
scm.getFileList.mockResolvedValue([
'one/one.csproj',
'two/two.csproj',
'three/three.csproj',
]);
Fixtures.mock({
'/tmp/repo/one/one.csproj': Fixtures.get(
'three-two-treelike-references/one/one.csproj'
),
'/tmp/repo/two/two.csproj': Fixtures.get(
'three-two-treelike-references/two/two.csproj'
),
'/tmp/repo/three/three.csproj': Fixtures.get(
'three-two-treelike-references/three/three.csproj'
),
});
expect(await getDependentPackageFiles('one/one.csproj')).toEqual([
{ isLeaf: false, name: 'one/one.csproj' },
{ isLeaf: true, name: 'two/two.csproj' },
{ isLeaf: true, name: 'three/three.csproj' },
]);
expect(await getDependentPackageFiles('two/two.csproj')).toEqual([
{ isLeaf: true, name: 'two/two.csproj' },
]);
expect(await getDependentPackageFiles('three/three.csproj')).toEqual([
{ isLeaf: true, name: 'three/three.csproj' },
]);
});
it('throws error on circular reference', async () => {
scm.getFileList.mockResolvedValue(['one/one.csproj', 'two/two.csproj']);
Fixtures.mock({
'/tmp/repo/one/one.csproj': Fixtures.get(
'circular-reference/one/one.csproj'
),
'/tmp/repo/two/two.csproj': Fixtures.get(
'circular-reference/two/two.csproj'
),
});
await expect(getDependentPackageFiles('one/one.csproj')).rejects.toThrow(
'Circular reference detected in NuGet package files'
);
});
it('skips on invalid xml file', async () => {
scm.getFileList.mockResolvedValue(['foo/bar.csproj']);
Fixtures.mock({ '/tmp/repo/foo/bar.csproj': '<invalid' });
expect(await getDependentPackageFiles('foo/bar.csproj')).toEqual([
{ isLeaf: true, name: 'foo/bar.csproj' },
]);
});
});
});