|
9 | 9 | shortExtractRef, |
10 | 10 | shortRepo, |
11 | 11 | } from "./output.ts"; |
| 12 | +import type { ReplayOptions } from "./output.ts"; |
12 | 13 | import type { RepoGroup } from "./types.ts"; |
13 | 14 |
|
14 | 15 | const ORG = "myorg"; |
@@ -125,6 +126,62 @@ describe("buildReplayCommand", () => { |
125 | 126 | const count = (cmd.match(/repoA/g) ?? []).length; |
126 | 127 | expect(count).toBe(1); |
127 | 128 | }); |
| 129 | + |
| 130 | + it("includes --format json when format is json", () => { |
| 131 | + const groups = [makeGroup("myorg/repoA", ["a.ts"])]; |
| 132 | + const opts: ReplayOptions = { format: "json" }; |
| 133 | + const cmd = buildReplayCommand(groups, QUERY, ORG, new Set(), new Set(), opts); |
| 134 | + expect(cmd).toContain("--format json"); |
| 135 | + }); |
| 136 | + |
| 137 | + it("does not include --format when format is markdown (default)", () => { |
| 138 | + const groups = [makeGroup("myorg/repoA", ["a.ts"])]; |
| 139 | + const opts: ReplayOptions = { format: "markdown" }; |
| 140 | + const cmd = buildReplayCommand(groups, QUERY, ORG, new Set(), new Set(), opts); |
| 141 | + expect(cmd).not.toContain("--format"); |
| 142 | + }); |
| 143 | + |
| 144 | + it("includes --output-type repo-only when outputType is repo-only", () => { |
| 145 | + const groups = [makeGroup("myorg/repoA", ["a.ts"])]; |
| 146 | + const opts: ReplayOptions = { outputType: "repo-only" }; |
| 147 | + const cmd = buildReplayCommand(groups, QUERY, ORG, new Set(), new Set(), opts); |
| 148 | + expect(cmd).toContain("--output-type repo-only"); |
| 149 | + }); |
| 150 | + |
| 151 | + it("does not include --output-type when outputType is repo-and-matches (default)", () => { |
| 152 | + const groups = [makeGroup("myorg/repoA", ["a.ts"])]; |
| 153 | + const opts: ReplayOptions = { outputType: "repo-and-matches" }; |
| 154 | + const cmd = buildReplayCommand(groups, QUERY, ORG, new Set(), new Set(), opts); |
| 155 | + expect(cmd).not.toContain("--output-type"); |
| 156 | + }); |
| 157 | + |
| 158 | + it("includes --include-archived when includeArchived is true", () => { |
| 159 | + const groups = [makeGroup("myorg/repoA", ["a.ts"])]; |
| 160 | + const opts: ReplayOptions = { includeArchived: true }; |
| 161 | + const cmd = buildReplayCommand(groups, QUERY, ORG, new Set(), new Set(), opts); |
| 162 | + expect(cmd).toContain("--include-archived"); |
| 163 | + }); |
| 164 | + |
| 165 | + it("does not include --include-archived when includeArchived is false (default)", () => { |
| 166 | + const groups = [makeGroup("myorg/repoA", ["a.ts"])]; |
| 167 | + const opts: ReplayOptions = { includeArchived: false }; |
| 168 | + const cmd = buildReplayCommand(groups, QUERY, ORG, new Set(), new Set(), opts); |
| 169 | + expect(cmd).not.toContain("--include-archived"); |
| 170 | + }); |
| 171 | + |
| 172 | + it("includes --group-by-team-prefix when groupByTeamPrefix is set", () => { |
| 173 | + const groups = [makeGroup("myorg/repoA", ["a.ts"])]; |
| 174 | + const opts: ReplayOptions = { groupByTeamPrefix: "squad-,chapter-" }; |
| 175 | + const cmd = buildReplayCommand(groups, QUERY, ORG, new Set(), new Set(), opts); |
| 176 | + expect(cmd).toContain("--group-by-team-prefix squad-,chapter-"); |
| 177 | + }); |
| 178 | + |
| 179 | + it("does not include --group-by-team-prefix when groupByTeamPrefix is empty (default)", () => { |
| 180 | + const groups = [makeGroup("myorg/repoA", ["a.ts"])]; |
| 181 | + const opts: ReplayOptions = { groupByTeamPrefix: "" }; |
| 182 | + const cmd = buildReplayCommand(groups, QUERY, ORG, new Set(), new Set(), opts); |
| 183 | + expect(cmd).not.toContain("--group-by-team-prefix"); |
| 184 | + }); |
128 | 185 | }); |
129 | 186 |
|
130 | 187 | describe("buildReplayDetails", () => { |
@@ -439,4 +496,53 @@ describe("buildOutput", () => { |
439 | 496 | expect(out).not.toContain("[src/foo.ts]"); |
440 | 497 | expect(out).toContain("myorg/repoA"); |
441 | 498 | }); |
| 499 | + |
| 500 | + it("threads --format json into replay command", () => { |
| 501 | + const groups = [makeGroup("myorg/repoA", ["src/foo.ts"])]; |
| 502 | + const out = buildOutput( |
| 503 | + groups, |
| 504 | + QUERY, |
| 505 | + ORG, |
| 506 | + new Set(), |
| 507 | + new Set(), |
| 508 | + "markdown", |
| 509 | + "repo-and-matches", |
| 510 | + { includeArchived: false, groupByTeamPrefix: "" }, |
| 511 | + ); |
| 512 | + expect(out).not.toContain("--format"); |
| 513 | + }); |
| 514 | + |
| 515 | + it("threads --output-type repo-only into markdown replay command", () => { |
| 516 | + const groups = [makeGroup("myorg/repoA", ["src/foo.ts"])]; |
| 517 | + const out = buildOutput(groups, QUERY, ORG, new Set(), new Set(), "markdown", "repo-only", { |
| 518 | + includeArchived: false, |
| 519 | + groupByTeamPrefix: "", |
| 520 | + }); |
| 521 | + expect(out).toContain("--output-type repo-only"); |
| 522 | + }); |
| 523 | + |
| 524 | + it("threads --include-archived into markdown replay command", () => { |
| 525 | + const groups = [makeGroup("myorg/repoA", ["src/foo.ts"])]; |
| 526 | + const out = buildOutput( |
| 527 | + groups, |
| 528 | + QUERY, |
| 529 | + ORG, |
| 530 | + new Set(), |
| 531 | + new Set(), |
| 532 | + "markdown", |
| 533 | + "repo-and-matches", |
| 534 | + { includeArchived: true, groupByTeamPrefix: "" }, |
| 535 | + ); |
| 536 | + expect(out).toContain("--include-archived"); |
| 537 | + }); |
| 538 | + |
| 539 | + it("threads --group-by-team-prefix into json replay command", () => { |
| 540 | + const groups = [makeGroup("myorg/repoA", ["src/foo.ts"])]; |
| 541 | + const out = buildOutput(groups, QUERY, ORG, new Set(), new Set(), "json", "repo-and-matches", { |
| 542 | + includeArchived: false, |
| 543 | + groupByTeamPrefix: "squad-", |
| 544 | + }); |
| 545 | + const parsed = JSON.parse(out); |
| 546 | + expect(parsed.replayCommand).toContain("--group-by-team-prefix squad-"); |
| 547 | + }); |
442 | 548 | }); |
0 commit comments