|
1 | | -import { guessSourceUrlTemplate } from "../lib/converter/utils/repository"; |
2 | | -import { strictEqual as equal } from "assert"; |
| 1 | +import { |
| 2 | + GitRepository, |
| 3 | + guessSourceUrlTemplate, |
| 4 | +} from "../lib/converter/utils/repository"; |
| 5 | +import { strictEqual as equal, ok } from "assert"; |
| 6 | +import { tempdirProject } from "@typestrong/fs-fixture-builder"; |
| 7 | +import { spawnSync } from "child_process"; |
| 8 | +import { TestLogger } from "./TestLogger"; |
| 9 | +import { join } from "path"; |
3 | 10 |
|
4 | 11 | describe("Repository", function () { |
5 | 12 | describe("guessSourceUrlTemplate helper", () => { |
@@ -99,4 +106,56 @@ describe("Repository", function () { |
99 | 106 | equal(guessSourceUrlTemplate(mockRemotes), undefined); |
100 | 107 | }); |
101 | 108 | }); |
| 109 | + |
| 110 | + describe("getURL", () => { |
| 111 | + const project = tempdirProject(); |
| 112 | + function git(...args: string[]) { |
| 113 | + const env = { |
| 114 | + GIT_AUTHOR_NAME: "test", |
| 115 | + GIT_AUTHOR_EMAIL: "test@example.com", |
| 116 | + GIT_AUTHOR_DATE: "2024-03-31T22:04:50.119Z", |
| 117 | + GIT_COMMITTER_NAME: "test", |
| 118 | + GIT_COMMITTER_EMAIL: "test@example.com", |
| 119 | + GIT_COMMITTER_DATE: "2024-03-31T22:04:50.119Z", |
| 120 | + }; |
| 121 | + return spawnSync("git", ["-C", project.cwd, ...args], { |
| 122 | + encoding: "utf-8", |
| 123 | + windowsHide: true, |
| 124 | + env, |
| 125 | + }); |
| 126 | + } |
| 127 | + |
| 128 | + afterEach(() => { |
| 129 | + project.rm(); |
| 130 | + }); |
| 131 | + |
| 132 | + it("Handles replacements", function () { |
| 133 | + project.addFile("test.js", "console.log('hi!')"); |
| 134 | + project.write(); |
| 135 | + |
| 136 | + git("init", "-b", "test"); |
| 137 | + git("add", "."); |
| 138 | + git("commit", "-m", "Test commit"); |
| 139 | + git( |
| 140 | + "remote", |
| 141 | + "add", |
| 142 | + "origin", |
| 143 | + "git@github.com:TypeStrong/typedoc.git", |
| 144 | + ); |
| 145 | + |
| 146 | + const repo = GitRepository.tryCreateRepository( |
| 147 | + project.cwd, |
| 148 | + "{gitRevision}/{gitRevision:short}/{path}/{line}", |
| 149 | + "", // revision, empty to get from repo |
| 150 | + "origin", // remote |
| 151 | + new TestLogger(), |
| 152 | + ); |
| 153 | + |
| 154 | + ok(repo); |
| 155 | + equal( |
| 156 | + repo.getURL(join(project.cwd, "test.js"), 1), |
| 157 | + "b53cc55bcdd9bc5920787a1d4a4a15fa24123b04/b53cc55b/test.js/1", |
| 158 | + ); |
| 159 | + }); |
| 160 | + }); |
102 | 161 | }); |
0 commit comments