renovate/lib/util/common.spec.ts
Michael Kriese 9caf45ed43
fix(git): wrong git url handling (#17380)
Co-authored-by: Rhys Arkins <rhys@arkins.net>
2022-08-24 19:41:43 +00:00

42 lines
1.4 KiB
TypeScript

import { detectPlatform } from './common';
import * as hostRules from './host-rules';
describe('util/common', () => {
beforeEach(() => hostRules.clear());
describe('detectPlatform', () => {
it.each`
url | hostType
${'some-invalid@url:::'} | ${null}
${'https://enterprise.example.com/chalk/chalk'} | ${null}
${'https://github.com/semantic-release/gitlab'} | ${'github'}
${'https://github-enterprise.example.com/chalk/chalk'} | ${'github'}
${'https://gitlab.com/chalk/chalk'} | ${'gitlab'}
${'https://gitlab-enterprise.example.com/chalk/chalk'} | ${'gitlab'}
`('("$url") === $hostType', ({ url, hostType }) => {
expect(detectPlatform(url)).toBe(hostType);
});
it('uses host rules', () => {
hostRules.add({
hostType: 'gitlab-changelog',
matchHost: 'gl.example.com',
});
hostRules.add({
hostType: 'github-changelog',
matchHost: 'gh.example.com',
});
hostRules.add({
hostType: 'gitea',
matchHost: 'gt.example.com',
});
expect(detectPlatform('https://gl.example.com/chalk/chalk')).toBe(
'gitlab'
);
expect(detectPlatform('https://gh.example.com/chalk/chalk')).toBe(
'github'
);
expect(detectPlatform('https://gt.example.com/chalk/chalk')).toBeNull();
});
});
});