diff options
Diffstat (limited to 'test/utils.ts')
-rw-r--r-- | test/utils.ts | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/test/utils.ts b/test/utils.ts index ec3fe4c5..ff1a21d5 100644 --- a/test/utils.ts +++ b/test/utils.ts @@ -4,6 +4,7 @@ import { getDiscussionNumber, getOwnerAndRepo, getRepoPath, + getRef, parseTag } from '../source/libs/utils'; @@ -152,6 +153,46 @@ test('getOwnerAndRepo', t => { }); }); +test('getRef', t => { + const refs: { + [url: string]: string | undefined; + } = { + 'https://github.com/sindresorhus/refined-github': undefined, + 'https://github.com/sindresorhus/refined-github/': undefined, + + 'https://github.com/sindresorhus/refined-github/tree/master': 'master', + 'https://github.com/sindresorhus/refined-github/tree/62007c8b944808d1b46d42d5e22fa65883d1eaec': '62007c8b944808d1b46d42d5e22fa65883d1eaec', + + 'https://github.com/sindresorhus/refined-github/compare': undefined, + 'https://github.com/sindresorhus/refined-github/compare/master': undefined, + 'https://github.com/sindresorhus/refined-github/compare/62007c8b944808d1b46d42d5e22fa65883d1eaec': undefined, + 'https://github.com/sindresorhus/refined-github/compare/master...test': undefined, + + 'https://github.com/sindresorhus/refined-github/commits': undefined, + 'https://github.com/sindresorhus/refined-github/commits/master': 'master', + 'https://github.com/sindresorhus/refined-github/commits/62007c8b944808d1b46d42d5e22fa65883d1eaec': '62007c8b944808d1b46d42d5e22fa65883d1eaec', + + 'https://github.com/sindresorhus/refined-github/releases/tag/v1.2.3': undefined, + + 'https://github.com/sindresorhus/refined-github/blob/master/readme.md': 'master', + 'https://github.com/sindresorhus/refined-github/blob/62007c8b944808d1b46d42d5e22fa65883d1eaec/readme.md': '62007c8b944808d1b46d42d5e22fa65883d1eaec', + + 'https://github.com/sindresorhus/refined-github/wiki/topic': undefined, + + 'https://github.com/sindresorhus/refined-github/blame/master/readme.md': 'master', + 'https://github.com/sindresorhus/refined-github/blame/62007c8b944808d1b46d42d5e22fa65883d1eaec/readme.md': '62007c8b944808d1b46d42d5e22fa65883d1eaec', + + 'https://github.com/sindresorhus/refined-github/pull/123': undefined, + 'https://github.com/sindresorhus/refined-github/pull/2105/commits/': undefined, + 'https://github.com/sindresorhus/refined-github/pull/2105/commits/9df50080dfddee5f7a2a6a1dc4465166339fedfe': undefined + }; + + Object.keys(refs).forEach(url => { + location.href = url; + t.is(refs[url], getRef(), url); + }); +}); + test('parseTag', t => { t.deepEqual(parseTag(''), {namespace: '', version: ''}); t.deepEqual(parseTag('1.2.3'), {namespace: '', version: '1.2.3'}); |