Skip to content

Commit 90d61c3

Browse files
committed
Add a regression test for generateUrlTokens
1 parent 7a5d035 commit 90d61c3

File tree

1 file changed

+76
-1
lines changed

1 file changed

+76
-1
lines changed

test/suite/generate-url-tokens.test.ts

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ suite("Generate URL Tokens", () => {
452452
});
453453
});
454454

455-
suite("Use genrated URL tokens", () => {
455+
suite("Use generated URL tokens", () => {
456456
const exampleCommit: LineAttachedCommit = {
457457
commit: {
458458
author: {
@@ -555,4 +555,79 @@ suite("Use genrated URL tokens", () => {
555555
"https://git.company.com/project_x/test-repository/commit/60d3fd32a7a9da4c8c93a9f89cfda22a0b4c65ce",
556556
);
557557
});
558+
559+
test("Url with port (#188 regression)", async () => {
560+
const activeEditorStub = stub(getActive, "getActiveTextEditor");
561+
const execcommandStub = stub(execcommand, "execute");
562+
const propertyStub = stub(property, "getProperty");
563+
activeEditorStub.returns({
564+
document: {
565+
isUntitled: false,
566+
fileName: "/fake.file",
567+
uri: Uri.parse("/fake.file"),
568+
lineCount: 1024,
569+
},
570+
selection: {
571+
active: {
572+
line: 9,
573+
},
574+
},
575+
});
576+
execcommandStub
577+
.withArgs(
578+
match.string,
579+
["symbolic-ref", "-q", "--short", "HEAD"],
580+
match.object,
581+
)
582+
.resolves("master");
583+
execcommandStub
584+
.withArgs(match.string, ["config", "branch.master.remote"], match.object)
585+
.resolves("origin");
586+
execcommandStub
587+
.withArgs(match.string, ["config", "remote.origin.url"], match.object)
588+
.resolves("http://git.company.com:8080/project_x/test-repository.git");
589+
execcommandStub
590+
.withArgs(
591+
match.string,
592+
["ls-remote", "--get-url", "origin"],
593+
match.object,
594+
)
595+
.resolves("http://git.company.com:8080/project_x/test-repository.git");
596+
execcommandStub
597+
.withArgs(
598+
match.string,
599+
["ls-files", "--full-name", "--", "/fake.file"],
600+
match.object,
601+
)
602+
.resolves("/fake.file");
603+
execcommandStub
604+
.withArgs(
605+
match.string,
606+
["rev-parse", "--abbrev-ref", "origin/HEAD"],
607+
match.object,
608+
)
609+
.resolves("origin/main");
610+
propertyStub.withArgs("remoteName").returns("origin");
611+
612+
const tokens = await generateUrlTokens(exampleCommit);
613+
614+
activeEditorStub.restore();
615+
execcommandStub.restore();
616+
propertyStub.restore();
617+
618+
if (tokens === undefined) {
619+
assert.notStrictEqual(tokens, undefined);
620+
return;
621+
}
622+
623+
const parsedUrl = parseTokens(
624+
"${tool.protocol}//${gitorigin.hostname}${gitorigin.port}${gitorigin.path}${tool.commitpath}${hash}",
625+
tokens,
626+
);
627+
628+
assert.strictEqual(
629+
parsedUrl,
630+
"http://git.company.com:8080/project_x/test-repository/commit/60d3fd32a7a9da4c8c93a9f89cfda22a0b4c65ce",
631+
);
632+
})
558633
});

0 commit comments

Comments
 (0)