|
| 1 | +import test from "ava"; |
| 2 | + |
| 3 | +import * as github from "./github"; |
| 4 | +import { setupTests } from "./testing-utils"; |
| 5 | + |
| 6 | +setupTests(test); |
| 7 | + |
| 8 | +test("parseGitHubUrl", (t) => { |
| 9 | + t.deepEqual(github.parseGitHubUrl("github.com"), "https://github.com"); |
| 10 | + t.deepEqual( |
| 11 | + github.parseGitHubUrl("https://github.com"), |
| 12 | + "https://github.com", |
| 13 | + ); |
| 14 | + t.deepEqual( |
| 15 | + github.parseGitHubUrl("https://api.github.com"), |
| 16 | + "https://github.com", |
| 17 | + ); |
| 18 | + t.deepEqual( |
| 19 | + github.parseGitHubUrl("https://github.com/foo/bar"), |
| 20 | + "https://github.com", |
| 21 | + ); |
| 22 | + |
| 23 | + t.deepEqual( |
| 24 | + github.parseGitHubUrl("github.example.com"), |
| 25 | + "https://github.example.com/", |
| 26 | + ); |
| 27 | + t.deepEqual( |
| 28 | + github.parseGitHubUrl("https://github.example.com"), |
| 29 | + "https://github.example.com/", |
| 30 | + ); |
| 31 | + t.deepEqual( |
| 32 | + github.parseGitHubUrl("https://api.github.example.com"), |
| 33 | + "https://github.example.com/", |
| 34 | + ); |
| 35 | + t.deepEqual( |
| 36 | + github.parseGitHubUrl("https://github.example.com/api/v3"), |
| 37 | + "https://github.example.com/", |
| 38 | + ); |
| 39 | + t.deepEqual( |
| 40 | + github.parseGitHubUrl("https://github.example.com:1234"), |
| 41 | + "https://github.example.com:1234/", |
| 42 | + ); |
| 43 | + t.deepEqual( |
| 44 | + github.parseGitHubUrl("https://api.github.example.com:1234"), |
| 45 | + "https://github.example.com:1234/", |
| 46 | + ); |
| 47 | + t.deepEqual( |
| 48 | + github.parseGitHubUrl("https://github.example.com:1234/api/v3"), |
| 49 | + "https://github.example.com:1234/", |
| 50 | + ); |
| 51 | + t.deepEqual( |
| 52 | + github.parseGitHubUrl("https://github.example.com/base/path"), |
| 53 | + "https://github.example.com/base/path/", |
| 54 | + ); |
| 55 | + t.deepEqual( |
| 56 | + github.parseGitHubUrl("https://github.example.com/base/path/api/v3"), |
| 57 | + "https://github.example.com/base/path/", |
| 58 | + ); |
| 59 | + |
| 60 | + t.throws(() => github.parseGitHubUrl(""), { |
| 61 | + message: '"" is not a valid URL', |
| 62 | + }); |
| 63 | + t.throws(() => github.parseGitHubUrl("ssh://github.com"), { |
| 64 | + message: '"ssh://github.com" is not a http or https URL', |
| 65 | + }); |
| 66 | + t.throws(() => github.parseGitHubUrl("http:///::::433"), { |
| 67 | + message: '"http:///::::433" is not a valid URL', |
| 68 | + }); |
| 69 | +}); |
0 commit comments