UNPKG

sherry-utils

Version:
116 lines (109 loc) 3.28 kB
const gitUrlParser = require('../lib/GitUrlParser')() describe('Repo - http(s)', () => { beforeEach(() => { gitUrlParser.setOptions({ protocol: 'http' }) }) const httpAsserts = [ { name: 'shortcut', input: "sherry/sherry-nm", output: "http://github.com/sherry/sherry-nm/archive/master.zip", }, { name: 'shortcut with checkout branch', input: "sherry/sherry-nm#dev", output: "http://github.com/sherry/sherry-nm/archive/dev.zip", }, { name: 'http path', input: 'https://github.com/sherry/sherry-nm', output: 'http://github.com/sherry/sherry-nm/archive/master.zip' }, { name: 'http path with checkout branch', input: 'https://github.com/sherry/sherry-nm#dev', output: 'http://github.com/sherry/sherry-nm/archive/dev.zip' }, { name: 'full ssh path', input: 'git@github.com:sherry/sherry-nm.git', output: 'http://github.com/sherry/sherry-nm/archive/master.zip' }, { name: 'gitlab http path', input: 'http://gitlab.xxx.com/sherry/sherry-nm', output: 'http://gitlab.xxx.com/sherry/sherry-nm/repository/archive.zip?ref=master' }, { name: 'gitlab ssh path', input: 'git@gitlab.xxx.com:sherry/sherry-nm.git', output: 'http://gitlab.xxx.com/sherry/sherry-nm/repository/archive.zip?ref=master' }, { name: 'bitbucket http path', input: 'https://owner@bitbucket.org/owner/name', output: 'http://owner@bitbucket.org/owner/name/get/master.zip' } ] httpAsserts.forEach(({ input, output, name }) => { test(`http(s) - ${name}`, () => { expect(gitUrlParser.parse(input).downloadUrl).toBe(output) }) }) }) describe('Repo - ssh', () => { beforeEach(() => { gitUrlParser.setOptions({ protocol: 'ssh' }) }) const sshAsserts = [ { name: "shortcut", input: "sherry/sherry-nm", output: "git@github.com:sherry/sherry-nm.git" }, { name: "shortcut with checkout branch", input: "sherry/sherry-nm#dev", output: "git@github.com:sherry/sherry-nm.git" }, { name: "http path", input: "https://github.com/sherry/sherry-nm", output: "git@github.com:sherry/sherry-nm.git" }, { name: "http path with checkout branch", input: "https://github.com/sherry/sherry-nm#dev", output: "git@github.com:sherry/sherry-nm.git" }, { name: "full ssh path", input: "git@github.com:sherry/sherry-nm.git", output: "git@github.com:sherry/sherry-nm.git" }, { name: "gitlab http path", input: "http://gitlab.alipay-inc.com/sherry/sherry-vue-h5", output: "git@gitlab.alipay-inc.com:sherry/sherry-vue-h5.git" }, { name: "gitlab ssh path", input: "git@gitlab.alipay-inc.com:sherry/sherry-vue-h5.git", output: "git@gitlab.alipay-inc.com:sherry/sherry-vue-h5.git" }, { name: "bitbucket http path", input: "https://owner@bitbucket.org/owner/name", output: "owner@bitbucket.org:owner/name.git" } ] sshAsserts.forEach(({ input, output, name }) => { test(`ssh - ${name}`, () => { expect(gitUrlParser.parse(input).downloadUrl).toBe(output) }) }) })