2020-11-12 20:46:08 +00:00
|
|
|
import * as upath from 'upath';
|
2021-05-17 13:21:28 +00:00
|
|
|
import { getName, loadFixture } from '../../../test/util';
|
|
|
|
import { setAdminConfig } from '../../config/admin';
|
|
|
|
import type { RepoAdminConfig } from '../../config/types';
|
2021-03-02 20:44:55 +00:00
|
|
|
import type { ExtractConfig } from '../types';
|
2020-02-05 00:14:31 +00:00
|
|
|
import { extractPackageFile } from './extract';
|
2018-06-14 09:15:52 +00:00
|
|
|
|
2021-05-17 13:21:28 +00:00
|
|
|
const config: ExtractConfig = {};
|
|
|
|
|
|
|
|
const adminConfig: RepoAdminConfig = {
|
2021-05-26 11:22:16 +00:00
|
|
|
localDir: upath.resolve('lib/manager/nuget/__fixtures__'),
|
2021-05-17 13:21:28 +00:00
|
|
|
};
|
|
|
|
|
2021-04-26 14:15:03 +00:00
|
|
|
describe(getName(), () => {
|
2018-11-04 17:51:23 +00:00
|
|
|
describe('extractPackageFile()', () => {
|
2018-06-14 09:15:52 +00:00
|
|
|
beforeEach(() => {
|
2021-05-17 13:21:28 +00:00
|
|
|
setAdminConfig(adminConfig);
|
|
|
|
});
|
|
|
|
afterEach(() => {
|
|
|
|
setAdminConfig();
|
2020-04-07 05:27:05 +00:00
|
|
|
});
|
|
|
|
it('returns empty for invalid csproj', async () => {
|
2021-08-07 23:43:34 +00:00
|
|
|
// FIXME: explicit assert condition
|
2020-04-07 05:27:05 +00:00
|
|
|
expect(
|
|
|
|
await extractPackageFile('nothing here', 'bogus', config)
|
|
|
|
).toMatchSnapshot();
|
2018-06-14 09:15:52 +00:00
|
|
|
});
|
2020-11-01 13:53:12 +00:00
|
|
|
it('extracts package version dependency', async () => {
|
|
|
|
const packageFile =
|
|
|
|
'with-centralized-package-versions/Directory.Packages.props';
|
2021-05-17 13:21:28 +00:00
|
|
|
const sample = loadFixture(packageFile);
|
2020-11-01 13:53:12 +00:00
|
|
|
const res = await extractPackageFile(sample, packageFile, config);
|
|
|
|
expect(res.deps).toMatchSnapshot();
|
2021-03-08 12:36:42 +00:00
|
|
|
expect(res.deps).toHaveLength(1);
|
2020-11-01 13:53:12 +00:00
|
|
|
});
|
2020-04-07 05:27:05 +00:00
|
|
|
it('extracts all dependencies', async () => {
|
|
|
|
const packageFile = 'sample.csproj';
|
2021-05-17 13:21:28 +00:00
|
|
|
const sample = loadFixture(packageFile);
|
2020-04-07 05:27:05 +00:00
|
|
|
const res = await extractPackageFile(sample, packageFile, config);
|
|
|
|
expect(res.deps).toMatchSnapshot();
|
2021-03-08 12:36:42 +00:00
|
|
|
expect(res.deps).toHaveLength(17);
|
2020-04-07 05:27:05 +00:00
|
|
|
});
|
2020-07-11 09:19:37 +00:00
|
|
|
it('extracts all dependencies from global packages file', async () => {
|
|
|
|
const packageFile = 'packages.props';
|
2021-05-17 13:21:28 +00:00
|
|
|
const sample = loadFixture(packageFile);
|
2020-07-11 09:19:37 +00:00
|
|
|
const res = await extractPackageFile(sample, packageFile, config);
|
|
|
|
expect(res.deps).toMatchSnapshot();
|
2021-03-08 12:36:42 +00:00
|
|
|
expect(res.deps).toHaveLength(17);
|
2020-07-11 09:19:37 +00:00
|
|
|
});
|
2020-04-07 05:27:05 +00:00
|
|
|
it('considers NuGet.config', async () => {
|
|
|
|
const packageFile = 'with-config-file/with-config-file.csproj';
|
2021-05-17 13:21:28 +00:00
|
|
|
const contents = loadFixture(packageFile);
|
2021-08-07 23:43:34 +00:00
|
|
|
// FIXME: explicit assert condition
|
2020-04-07 05:27:05 +00:00
|
|
|
expect(
|
|
|
|
await extractPackageFile(contents, packageFile, config)
|
|
|
|
).toMatchSnapshot();
|
2018-06-14 09:15:52 +00:00
|
|
|
});
|
2020-04-08 19:31:44 +00:00
|
|
|
it('considers lower-case nuget.config', async () => {
|
|
|
|
const packageFile =
|
|
|
|
'with-lower-case-config-file/with-lower-case-config-file.csproj';
|
2021-05-17 13:21:28 +00:00
|
|
|
const contents = loadFixture(packageFile);
|
2021-08-07 23:43:34 +00:00
|
|
|
// FIXME: explicit assert condition
|
2020-04-08 19:31:44 +00:00
|
|
|
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';
|
2021-05-17 13:21:28 +00:00
|
|
|
const contents = loadFixture(packageFile);
|
2021-08-07 23:43:34 +00:00
|
|
|
// FIXME: explicit assert condition
|
2020-04-08 19:31:44 +00:00
|
|
|
expect(
|
|
|
|
await extractPackageFile(contents, packageFile, config)
|
|
|
|
).toMatchSnapshot();
|
|
|
|
});
|
2020-04-07 05:27:05 +00:00
|
|
|
it('handles malformed NuGet.config', async () => {
|
|
|
|
const packageFile =
|
|
|
|
'with-malformed-config-file/with-malformed-config-file.csproj';
|
2021-05-17 13:21:28 +00:00
|
|
|
const contents = loadFixture(packageFile);
|
2021-08-07 23:43:34 +00:00
|
|
|
// FIXME: explicit assert condition
|
2020-04-07 05:27:05 +00:00
|
|
|
expect(
|
|
|
|
await extractPackageFile(contents, packageFile, config)
|
|
|
|
).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
it('handles NuGet.config without package sources', async () => {
|
|
|
|
const packageFile =
|
|
|
|
'without-package-sources/without-package-sources.csproj';
|
2021-05-17 13:21:28 +00:00
|
|
|
const contents = loadFixture(packageFile);
|
2021-08-07 23:43:34 +00:00
|
|
|
// FIXME: explicit assert condition
|
2020-04-07 05:27:05 +00:00
|
|
|
expect(
|
|
|
|
await extractPackageFile(contents, packageFile, config)
|
|
|
|
).toMatchSnapshot();
|
2018-06-14 09:15:52 +00:00
|
|
|
});
|
2020-05-28 08:33:57 +00:00
|
|
|
it('ignores local feed in NuGet.config', async () => {
|
|
|
|
const packageFile =
|
|
|
|
'with-local-feed-in-config-file/with-local-feed-in-config-file.csproj';
|
2021-05-17 13:21:28 +00:00
|
|
|
const contents = loadFixture(packageFile);
|
2021-08-07 23:43:34 +00:00
|
|
|
// FIXME: explicit assert condition
|
2020-05-28 08:33:57 +00:00
|
|
|
expect(
|
|
|
|
await extractPackageFile(contents, packageFile, config)
|
|
|
|
).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
it('extracts registry URLs independently', async () => {
|
|
|
|
const packageFile = 'multiple-package-files/one/one.csproj';
|
2021-05-17 13:21:28 +00:00
|
|
|
const contents = loadFixture(packageFile);
|
2020-05-28 08:33:57 +00:00
|
|
|
const otherPackageFile = 'multiple-package-files/two/two.csproj';
|
2021-05-17 13:21:28 +00:00
|
|
|
const otherContents = loadFixture(otherPackageFile);
|
2021-08-07 23:43:34 +00:00
|
|
|
// FIXME: explicit assert condition
|
2020-05-28 08:33:57 +00:00
|
|
|
expect(
|
|
|
|
await extractPackageFile(contents, packageFile, config)
|
|
|
|
).toMatchSnapshot();
|
|
|
|
expect(
|
|
|
|
await extractPackageFile(otherContents, otherPackageFile, config)
|
|
|
|
).toMatchSnapshot();
|
|
|
|
});
|
2020-05-28 04:01:05 +00:00
|
|
|
|
|
|
|
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 () => {
|
2021-08-07 23:43:34 +00:00
|
|
|
// FIXME: explicit assert condition
|
2020-05-28 04:01:05 +00:00
|
|
|
expect(
|
|
|
|
await extractPackageFile(contents, packageFile, config)
|
|
|
|
).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('with-config', async () => {
|
2021-08-07 23:43:34 +00:00
|
|
|
// FIXME: explicit assert condition
|
2020-05-28 04:01:05 +00:00
|
|
|
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();
|
|
|
|
});
|
|
|
|
});
|
2018-06-14 09:15:52 +00:00
|
|
|
});
|
|
|
|
});
|