2020-02-11 05:08:10 +00:00
|
|
|
import * as datasource from '.';
|
2020-03-01 07:01:12 +00:00
|
|
|
|
|
|
|
import * as datasourceDocker from './docker';
|
|
|
|
import * as datasourceGithubTags from './github-tags';
|
|
|
|
import * as datasourceNpm from './npm';
|
|
|
|
import { mocked } from '../../test/util';
|
2020-03-24 06:17:59 +00:00
|
|
|
import { loadModules } from '../util/modules';
|
2018-06-08 08:49:08 +00:00
|
|
|
|
2020-02-11 05:08:10 +00:00
|
|
|
jest.mock('./docker');
|
|
|
|
jest.mock('./npm');
|
2018-07-20 07:09:01 +00:00
|
|
|
|
2020-03-01 07:01:12 +00:00
|
|
|
const npmDatasource = mocked(datasourceNpm);
|
2019-08-15 04:30:16 +00:00
|
|
|
|
2018-06-08 08:49:08 +00:00
|
|
|
describe('datasource/index', () => {
|
2020-02-18 20:41:00 +00:00
|
|
|
it('returns datasources', () => {
|
|
|
|
expect(datasource.getDatasources()).toBeDefined();
|
|
|
|
expect(datasource.getDatasourceList()).toBeDefined();
|
|
|
|
});
|
2020-03-24 06:17:59 +00:00
|
|
|
it('validates dataource', async () => {
|
|
|
|
function validateDatasource(
|
|
|
|
module: datasource.Datasource,
|
|
|
|
name: string
|
|
|
|
): boolean {
|
2020-04-04 06:53:52 +00:00
|
|
|
if (!module.getReleases) {
|
2020-03-24 06:17:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (module.id !== name) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
const dss = datasource.getDatasources();
|
|
|
|
|
|
|
|
const loadedDs = loadModules(__dirname, validateDatasource);
|
|
|
|
expect(Array.from(dss.keys())).toEqual(Object.keys(loadedDs));
|
|
|
|
|
|
|
|
for (const dsName of dss.keys()) {
|
|
|
|
const ds = await dss.get(dsName);
|
|
|
|
expect(validateDatasource(ds, dsName)).toBe(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
it('returns if digests are supported', async () => {
|
2020-02-27 20:36:31 +00:00
|
|
|
expect(
|
2020-03-24 06:17:59 +00:00
|
|
|
await datasource.supportsDigests({ datasource: datasourceGithubTags.id })
|
2020-02-27 20:36:31 +00:00
|
|
|
).toBe(true);
|
2019-01-29 17:14:06 +00:00
|
|
|
});
|
2019-02-04 08:41:22 +00:00
|
|
|
it('returns null for no datasource', async () => {
|
2019-01-29 17:14:06 +00:00
|
|
|
expect(
|
2019-02-04 08:41:22 +00:00
|
|
|
await datasource.getPkgReleases({
|
2020-04-04 06:53:52 +00:00
|
|
|
datasource: null,
|
2019-02-04 08:41:22 +00:00
|
|
|
depName: 'some/dep',
|
|
|
|
})
|
2019-01-29 17:14:06 +00:00
|
|
|
).toBeNull();
|
|
|
|
});
|
2020-03-07 09:19:47 +00:00
|
|
|
it('returns null for no lookupName', async () => {
|
|
|
|
expect(
|
|
|
|
await datasource.getPkgReleases({
|
|
|
|
datasource: 'npm',
|
2020-04-04 06:53:52 +00:00
|
|
|
depName: null,
|
2020-03-07 09:19:47 +00:00
|
|
|
})
|
|
|
|
).toBeNull();
|
|
|
|
});
|
2019-02-04 08:41:22 +00:00
|
|
|
it('returns null for unknown datasource', async () => {
|
2019-01-28 05:40:37 +00:00
|
|
|
expect(
|
2019-02-04 08:41:22 +00:00
|
|
|
await datasource.getPkgReleases({
|
|
|
|
datasource: 'gitbucket',
|
|
|
|
depName: 'some/dep',
|
|
|
|
})
|
2019-01-28 05:40:37 +00:00
|
|
|
).toBeNull();
|
2018-06-08 08:49:08 +00:00
|
|
|
});
|
2018-07-20 07:09:01 +00:00
|
|
|
it('returns getDigest', async () => {
|
2018-07-21 08:47:29 +00:00
|
|
|
expect(
|
2019-02-04 08:41:22 +00:00
|
|
|
await datasource.getDigest({
|
2020-03-01 07:01:12 +00:00
|
|
|
datasource: datasourceDocker.id,
|
2019-02-04 08:41:22 +00:00
|
|
|
depName: 'docker/node',
|
|
|
|
})
|
2018-07-21 08:47:29 +00:00
|
|
|
).toBeUndefined();
|
2018-07-20 07:09:01 +00:00
|
|
|
});
|
2018-12-10 05:34:39 +00:00
|
|
|
it('adds changelogUrl', async () => {
|
2020-04-04 06:53:52 +00:00
|
|
|
npmDatasource.getReleases.mockResolvedValue({ releases: [] });
|
2019-01-28 05:40:37 +00:00
|
|
|
const res = await datasource.getPkgReleases({
|
2020-03-01 07:01:12 +00:00
|
|
|
datasource: datasourceNpm.id,
|
2019-02-04 08:41:22 +00:00
|
|
|
depName: 'react-native',
|
2019-01-28 05:40:37 +00:00
|
|
|
});
|
2018-12-10 05:34:39 +00:00
|
|
|
expect(res).toMatchSnapshot();
|
|
|
|
expect(res.changelogUrl).toBeDefined();
|
|
|
|
expect(res.sourceUrl).toBeDefined();
|
|
|
|
});
|
2018-12-10 05:49:15 +00:00
|
|
|
it('adds sourceUrl', async () => {
|
2020-04-04 06:53:52 +00:00
|
|
|
npmDatasource.getReleases.mockResolvedValue({ releases: [] });
|
2019-02-04 08:41:22 +00:00
|
|
|
const res = await datasource.getPkgReleases({
|
2020-03-01 07:01:12 +00:00
|
|
|
datasource: datasourceNpm.id,
|
2019-02-04 08:41:22 +00:00
|
|
|
depName: 'node',
|
|
|
|
});
|
2018-12-10 05:49:15 +00:00
|
|
|
expect(res).toMatchSnapshot();
|
|
|
|
expect(res.sourceUrl).toBeDefined();
|
|
|
|
});
|
2019-02-04 20:49:49 +00:00
|
|
|
it('trims sourceUrl', async () => {
|
2020-04-04 06:53:52 +00:00
|
|
|
npmDatasource.getReleases.mockResolvedValue({
|
2019-02-04 20:49:49 +00:00
|
|
|
sourceUrl: ' https://abc.com',
|
2020-03-12 11:48:57 +00:00
|
|
|
releases: [],
|
2019-02-04 20:49:49 +00:00
|
|
|
});
|
|
|
|
const res = await datasource.getPkgReleases({
|
2020-03-01 07:01:12 +00:00
|
|
|
datasource: datasourceNpm.id,
|
2019-02-04 20:49:49 +00:00
|
|
|
depName: 'abc',
|
|
|
|
});
|
|
|
|
expect(res.sourceUrl).toEqual('https://abc.com');
|
|
|
|
});
|
2019-04-20 08:32:12 +00:00
|
|
|
it('massages sourceUrl', async () => {
|
2020-04-04 06:53:52 +00:00
|
|
|
npmDatasource.getReleases.mockResolvedValue({
|
2019-04-20 08:32:12 +00:00
|
|
|
sourceUrl: 'scm:git@github.com:Jasig/cas.git',
|
2020-03-01 07:01:12 +00:00
|
|
|
releases: [],
|
2019-04-20 08:32:12 +00:00
|
|
|
});
|
|
|
|
const res = await datasource.getPkgReleases({
|
2020-03-01 07:01:12 +00:00
|
|
|
datasource: datasourceNpm.id,
|
2019-04-20 08:32:12 +00:00
|
|
|
depName: 'cas',
|
|
|
|
});
|
|
|
|
expect(res.sourceUrl).toEqual('https://github.com/Jasig/cas');
|
|
|
|
});
|
2018-06-08 08:49:08 +00:00
|
|
|
});
|