2019-08-15 04:30:16 +00:00
|
|
|
import * as datasource from '../../lib/datasource';
|
|
|
|
import * as _npm from '../../lib/datasource/npm';
|
2018-06-08 08:49:08 +00:00
|
|
|
|
2018-07-20 07:09:01 +00:00
|
|
|
jest.mock('../../lib/datasource/docker');
|
2018-12-10 05:34:39 +00:00
|
|
|
jest.mock('../../lib/datasource/npm');
|
2018-07-20 07:09:01 +00:00
|
|
|
|
2019-08-15 04:30:16 +00:00
|
|
|
const npmDatasource: any = _npm;
|
|
|
|
|
2018-06-08 08:49:08 +00:00
|
|
|
describe('datasource/index', () => {
|
2019-01-29 17:14:06 +00:00
|
|
|
it('returns if digests are supported', async () => {
|
2019-02-04 08:41:22 +00:00
|
|
|
expect(await datasource.supportsDigests({ datasource: 'github' })).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({
|
|
|
|
depName: 'some/dep',
|
|
|
|
})
|
2019-01-29 17:14:06 +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({
|
|
|
|
datasource: 'docker',
|
|
|
|
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 () => {
|
|
|
|
npmDatasource.getPkgReleases.mockReturnValue({});
|
2019-01-28 05:40:37 +00:00
|
|
|
const res = await datasource.getPkgReleases({
|
2019-02-04 08:41:22 +00:00
|
|
|
datasource: 'npm',
|
|
|
|
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 () => {
|
|
|
|
npmDatasource.getPkgReleases.mockReturnValue({});
|
2019-02-04 08:41:22 +00:00
|
|
|
const res = await datasource.getPkgReleases({
|
|
|
|
datasource: 'npm',
|
|
|
|
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 () => {
|
|
|
|
npmDatasource.getPkgReleases.mockReturnValue({
|
|
|
|
sourceUrl: ' https://abc.com',
|
|
|
|
});
|
|
|
|
const res = await datasource.getPkgReleases({
|
|
|
|
datasource: 'npm',
|
|
|
|
depName: 'abc',
|
|
|
|
});
|
|
|
|
expect(res.sourceUrl).toEqual('https://abc.com');
|
|
|
|
});
|
2019-04-20 08:32:12 +00:00
|
|
|
it('massages sourceUrl', async () => {
|
|
|
|
npmDatasource.getPkgReleases.mockReturnValue({
|
|
|
|
sourceUrl: 'scm:git@github.com:Jasig/cas.git',
|
|
|
|
});
|
|
|
|
const res = await datasource.getPkgReleases({
|
|
|
|
datasource: 'npm',
|
|
|
|
depName: 'cas',
|
|
|
|
});
|
|
|
|
expect(res.sourceUrl).toEqual('https://github.com/Jasig/cas');
|
|
|
|
});
|
2018-06-08 08:49:08 +00:00
|
|
|
});
|