renovate/test/datasource/index.spec.ts

78 lines
2.2 KiB
TypeScript
Raw Normal View History

import * as datasource from '../../lib/datasource';
import * as _npm from '../../lib/datasource/npm';
jest.mock('../../lib/datasource/docker');
jest.mock('../../lib/datasource/npm');
const npmDatasource: any = _npm;
describe('datasource/index', () => {
2019-01-29 17:14:06 +00:00
it('returns if digests are supported', async () => {
expect(await datasource.supportsDigests({ datasource: 'github' })).toBe(
true
);
2019-01-29 17:14:06 +00:00
});
it('returns null for no datasource', async () => {
2019-01-29 17:14:06 +00:00
expect(
await datasource.getPkgReleases({
depName: 'some/dep',
})
2019-01-29 17:14:06 +00:00
).toBeNull();
});
it('returns null for unknown datasource', async () => {
2019-01-28 05:40:37 +00:00
expect(
await datasource.getPkgReleases({
datasource: 'gitbucket',
depName: 'some/dep',
})
2019-01-28 05:40:37 +00:00
).toBeNull();
});
it('returns getDigest', async () => {
expect(
await datasource.getDigest({
datasource: 'docker',
depName: 'docker/node',
})
).toBeUndefined();
});
it('adds changelogUrl', async () => {
npmDatasource.getPkgReleases.mockReturnValue({});
2019-01-28 05:40:37 +00:00
const res = await datasource.getPkgReleases({
datasource: 'npm',
depName: 'react-native',
2019-01-28 05:40:37 +00:00
});
expect(res).toMatchSnapshot();
expect(res.changelogUrl).toBeDefined();
expect(res.sourceUrl).toBeDefined();
});
it('adds sourceUrl', async () => {
npmDatasource.getPkgReleases.mockReturnValue({});
const res = await datasource.getPkgReleases({
datasource: 'npm',
depName: 'node',
});
expect(res).toMatchSnapshot();
expect(res.sourceUrl).toBeDefined();
});
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');
});
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');
});
});