|
1 | | -import { describe, it, expect, vi } from "vitest"; |
| 1 | +import {describe, it, expect, vi} from 'vitest' |
2 | 2 |
|
3 | 3 | // Mock generateIssueBody so we can inspect what screenshotRepo is passed |
4 | | -vi.mock("../src/generateIssueBody.js", () => ({ |
5 | | - generateIssueBody: vi.fn( |
6 | | - (_finding, screenshotRepo: string) => |
7 | | - `body with screenshotRepo=${screenshotRepo}`, |
8 | | - ), |
9 | | -})); |
| 4 | +vi.mock('../src/generateIssueBody.js', () => ({ |
| 5 | + generateIssueBody: vi.fn((_finding, screenshotRepo: string) => `body with screenshotRepo=${screenshotRepo}`), |
| 6 | +})) |
10 | 7 |
|
11 | | -import { openIssue } from "../src/openIssue.ts"; |
12 | | -import { generateIssueBody } from "../src/generateIssueBody.ts"; |
| 8 | +import {openIssue} from '../src/openIssue.ts' |
| 9 | +import {generateIssueBody} from '../src/generateIssueBody.ts' |
13 | 10 |
|
14 | 11 | const baseFinding = { |
15 | | - scannerType: "axe", |
16 | | - ruleId: "color-contrast", |
17 | | - url: "https://example.com/page", |
18 | | - html: "<span>Low contrast</span>", |
19 | | - problemShort: "elements must meet minimum color contrast ratio thresholds", |
20 | | - problemUrl: |
21 | | - "https://dequeuniversity.com/rules/axe/4.10/color-contrast?application=playwright", |
22 | | - solutionShort: |
23 | | - "ensure the contrast between foreground and background colors meets WCAG thresholds", |
24 | | -}; |
| 12 | + scannerType: 'axe', |
| 13 | + ruleId: 'color-contrast', |
| 14 | + url: 'https://example.com/page', |
| 15 | + html: '<span>Low contrast</span>', |
| 16 | + problemShort: 'elements must meet minimum color contrast ratio thresholds', |
| 17 | + problemUrl: 'https://dequeuniversity.com/rules/axe/4.10/color-contrast?application=playwright', |
| 18 | + solutionShort: 'ensure the contrast between foreground and background colors meets WCAG thresholds', |
| 19 | +} |
25 | 20 |
|
26 | 21 | function mockOctokit() { |
27 | 22 | return { |
28 | | - request: vi.fn().mockResolvedValue({ data: { id: 1, html_url: "https://github.com/org/repo/issues/1" } }), |
29 | | - } as any; |
| 23 | + request: vi.fn().mockResolvedValue({data: {id: 1, html_url: 'https://github.com/org/repo/issues/1'}}), |
| 24 | + // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 25 | + } as any |
30 | 26 | } |
31 | 27 |
|
32 | | -describe("openIssue", () => { |
33 | | - it("passes screenshotRepo to generateIssueBody when provided", async () => { |
34 | | - const octokit = mockOctokit(); |
35 | | - await openIssue(octokit, "org/filing-repo", baseFinding, "org/workflow-repo"); |
| 28 | +describe('openIssue', () => { |
| 29 | + it('passes screenshotRepo to generateIssueBody when provided', async () => { |
| 30 | + const octokit = mockOctokit() |
| 31 | + await openIssue(octokit, 'org/filing-repo', baseFinding, 'org/workflow-repo') |
36 | 32 |
|
37 | | - expect(generateIssueBody).toHaveBeenCalledWith(baseFinding, "org/workflow-repo"); |
38 | | - }); |
| 33 | + expect(generateIssueBody).toHaveBeenCalledWith(baseFinding, 'org/workflow-repo') |
| 34 | + }) |
39 | 35 |
|
40 | | - it("falls back to repoWithOwner when screenshotRepo is not provided", async () => { |
41 | | - const octokit = mockOctokit(); |
42 | | - await openIssue(octokit, "org/filing-repo", baseFinding); |
| 36 | + it('falls back to repoWithOwner when screenshotRepo is not provided', async () => { |
| 37 | + const octokit = mockOctokit() |
| 38 | + await openIssue(octokit, 'org/filing-repo', baseFinding) |
43 | 39 |
|
44 | | - expect(generateIssueBody).toHaveBeenCalledWith(baseFinding, "org/filing-repo"); |
45 | | - }); |
| 40 | + expect(generateIssueBody).toHaveBeenCalledWith(baseFinding, 'org/filing-repo') |
| 41 | + }) |
46 | 42 |
|
47 | | - it("posts to the correct filing repo, not the screenshot repo", async () => { |
48 | | - const octokit = mockOctokit(); |
49 | | - await openIssue(octokit, "org/filing-repo", baseFinding, "org/workflow-repo"); |
| 43 | + it('posts to the correct filing repo, not the screenshot repo', async () => { |
| 44 | + const octokit = mockOctokit() |
| 45 | + await openIssue(octokit, 'org/filing-repo', baseFinding, 'org/workflow-repo') |
50 | 46 |
|
51 | 47 | expect(octokit.request).toHaveBeenCalledWith( |
52 | | - "POST /repos/org/filing-repo/issues", |
| 48 | + 'POST /repos/org/filing-repo/issues', |
53 | 49 | expect.objectContaining({ |
54 | | - owner: "org", |
55 | | - repo: "filing-repo", |
| 50 | + owner: 'org', |
| 51 | + repo: 'filing-repo', |
56 | 52 | }), |
57 | | - ); |
58 | | - }); |
| 53 | + ) |
| 54 | + }) |
59 | 55 |
|
60 | | - it("includes the correct labels based on the finding", async () => { |
61 | | - const octokit = mockOctokit(); |
62 | | - await openIssue(octokit, "org/repo", baseFinding); |
| 56 | + it('includes the correct labels based on the finding', async () => { |
| 57 | + const octokit = mockOctokit() |
| 58 | + await openIssue(octokit, 'org/repo', baseFinding) |
63 | 59 |
|
64 | 60 | expect(octokit.request).toHaveBeenCalledWith( |
65 | 61 | expect.any(String), |
66 | 62 | expect.objectContaining({ |
67 | | - labels: ["axe rule: color-contrast", "axe-scanning-issue"], |
| 63 | + labels: ['axe rule: color-contrast', 'axe-scanning-issue'], |
68 | 64 | }), |
69 | | - ); |
70 | | - }); |
| 65 | + ) |
| 66 | + }) |
71 | 67 |
|
72 | | - it("truncates long titles with ellipsis", async () => { |
73 | | - const octokit = mockOctokit(); |
| 68 | + it('truncates long titles with ellipsis', async () => { |
| 69 | + const octokit = mockOctokit() |
74 | 70 | const longFinding = { |
75 | 71 | ...baseFinding, |
76 | | - problemShort: "a".repeat(300), |
77 | | - }; |
78 | | - await openIssue(octokit, "org/repo", longFinding); |
| 72 | + problemShort: 'a'.repeat(300), |
| 73 | + } |
| 74 | + await openIssue(octokit, 'org/repo', longFinding) |
79 | 75 |
|
80 | | - const callArgs = octokit.request.mock.calls[0][1]; |
81 | | - expect(callArgs.title.length).toBeLessThanOrEqual(256); |
82 | | - expect(callArgs.title).toMatch(/…$/); |
83 | | - }); |
84 | | -}); |
| 76 | + const callArgs = octokit.request.mock.calls[0][1] |
| 77 | + expect(callArgs.title.length).toBeLessThanOrEqual(256) |
| 78 | + expect(callArgs.title).toMatch(/…$/) |
| 79 | + }) |
| 80 | +}) |
0 commit comments