/
extract.spec.ts
179 lines (171 loc) · 6.21 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
170
171
172
173
174
175
176
177
178
179
import * as upath from 'upath';
import { loadFixture } from '../../../test/util';
import { setGlobalConfig } from '../../config/global';
import type { RepoGlobalConfig } from '../../config/types';
import type { ExtractConfig } from '../types';
import { extractPackageFile } from './extract';
const config: ExtractConfig = {};
const adminConfig: RepoGlobalConfig = {
localDir: upath.resolve('lib/manager/nuget/__fixtures__'),
};
describe('manager/nuget/extract', () => {
describe('extractPackageFile()', () => {
beforeEach(() => {
setGlobalConfig(adminConfig);
});
afterEach(() => {
setGlobalConfig();
});
it('returns empty for invalid csproj', async () => {
// FIXME: explicit assert condition
expect(
await extractPackageFile('nothing here', 'bogus', config)
).toMatchSnapshot();
});
it('extracts package version dependency', async () => {
const packageFile =
'with-centralized-package-versions/Directory.Packages.props';
const sample = loadFixture(packageFile);
const res = await extractPackageFile(sample, packageFile, config);
expect(res.deps).toMatchSnapshot();
expect(res.deps).toHaveLength(1);
});
it('extracts all dependencies', async () => {
const packageFile = 'sample.csproj';
const sample = loadFixture(packageFile);
const res = await extractPackageFile(sample, packageFile, config);
expect(res.deps).toMatchSnapshot();
expect(res.deps).toHaveLength(17);
});
it('extracts all dependencies from global packages file', async () => {
const packageFile = 'packages.props';
const sample = loadFixture(packageFile);
const res = await extractPackageFile(sample, packageFile, config);
expect(res.deps).toMatchSnapshot();
expect(res.deps).toHaveLength(17);
});
it('considers NuGet.config', async () => {
const packageFile = 'with-config-file/with-config-file.csproj';
const contents = loadFixture(packageFile);
// FIXME: explicit assert condition
expect(
await extractPackageFile(contents, packageFile, config)
).toMatchSnapshot();
});
it('considers lower-case nuget.config', async () => {
const packageFile =
'with-lower-case-config-file/with-lower-case-config-file.csproj';
const contents = loadFixture(packageFile);
// FIXME: explicit assert condition
expect(
await extractPackageFile(contents, packageFile, config)
).toMatchSnapshot();
});
it('considers pascal-case NuGet.Config', async () => {
const packageFile =
'with-pascal-case-config-file/with-pascal-case-config-file.csproj';
const contents = loadFixture(packageFile);
// FIXME: explicit assert condition
expect(
await extractPackageFile(contents, packageFile, config)
).toMatchSnapshot();
});
it('handles malformed NuGet.config', async () => {
const packageFile =
'with-malformed-config-file/with-malformed-config-file.csproj';
const contents = loadFixture(packageFile);
// FIXME: explicit assert condition
expect(
await extractPackageFile(contents, packageFile, config)
).toMatchSnapshot();
});
it('handles NuGet.config without package sources', async () => {
const packageFile =
'without-package-sources/without-package-sources.csproj';
const contents = loadFixture(packageFile);
// FIXME: explicit assert condition
expect(
await extractPackageFile(contents, packageFile, config)
).toMatchSnapshot();
});
it('ignores local feed in NuGet.config', async () => {
const packageFile =
'with-local-feed-in-config-file/with-local-feed-in-config-file.csproj';
const contents = loadFixture(packageFile);
// FIXME: explicit assert condition
expect(
await extractPackageFile(contents, packageFile, config)
).toMatchSnapshot();
});
it('extracts registry URLs independently', async () => {
const packageFile = 'multiple-package-files/one/one.csproj';
const contents = loadFixture(packageFile);
const otherPackageFile = 'multiple-package-files/two/two.csproj';
const otherContents = loadFixture(otherPackageFile);
// FIXME: explicit assert condition
expect(
await extractPackageFile(contents, packageFile, config)
).toMatchSnapshot();
expect(
await extractPackageFile(otherContents, otherPackageFile, config)
).toMatchSnapshot();
});
it('extracts msbuild-sdks from global.json', async () => {
const packageFile = 'msbuild-sdk-files/global.json';
const contents = loadFixture(packageFile);
// FIXME: explicit assert condition
expect(
await extractPackageFile(contents, packageFile, config)
).toMatchSnapshot();
});
it('handles malformed global.json', async () => {
const packageFile = 'msbuild-sdk-files/invalid-json/global.json';
const contents = loadFixture(packageFile);
// FIXME: explicit assert condition
expect(
await extractPackageFile(contents, packageFile, config)
).toMatchSnapshot();
});
describe('.config/dotnet-tools.json', () => {
const packageFile = '.config/dotnet-tools.json';
const contents = `{
"version": 1,
"isRoot": true,
"tools": {
"minver-cli": {
"version": "2.0.0",
"commands": ["minver"]
}
}
}`;
it('works', async () => {
// FIXME: explicit assert condition
expect(
await extractPackageFile(contents, packageFile, config)
).toMatchSnapshot();
});
it('with-config', async () => {
// FIXME: explicit assert condition
expect(
await extractPackageFile(
contents,
`with-config-file/${packageFile}`,
config
)
).toMatchSnapshot();
});
it('wrong version', async () => {
expect(
await extractPackageFile(
contents.replace('"version": 1,', '"version": 2,'),
packageFile,
config
)
).toBeNull();
});
it('does not throw', async () => {
expect(await extractPackageFile('{{', packageFile, config)).toBeNull();
});
});
});
});