@trailmark/core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/baseline.d.ts +21 -0
- package/dist/baseline.d.ts.map +1 -0
- package/dist/baseline.js +187 -0
- package/dist/baseline.js.map +1 -0
- package/dist/diff.d.ts +3 -0
- package/dist/diff.d.ts.map +1 -0
- package/dist/diff.js +120 -0
- package/dist/diff.js.map +1 -0
- package/dist/fingerprint.d.ts +8 -0
- package/dist/fingerprint.d.ts.map +1 -0
- package/dist/fingerprint.js +85 -0
- package/dist/fingerprint.js.map +1 -0
- package/dist/hash.d.ts +4 -0
- package/dist/hash.d.ts.map +1 -0
- package/dist/hash.js +29 -0
- package/dist/hash.js.map +1 -0
- package/dist/impact.d.ts +5 -0
- package/dist/impact.d.ts.map +1 -0
- package/dist/impact.js +27 -0
- package/dist/impact.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/issue.d.ts +10 -0
- package/dist/issue.d.ts.map +1 -0
- package/dist/issue.js +40 -0
- package/dist/issue.js.map +1 -0
- package/dist/normalize.d.ts +3 -0
- package/dist/normalize.d.ts.map +1 -0
- package/dist/normalize.js +59 -0
- package/dist/normalize.js.map +1 -0
- package/dist/report/buildReport.d.ts +3 -0
- package/dist/report/buildReport.d.ts.map +1 -0
- package/dist/report/buildReport.js +223 -0
- package/dist/report/buildReport.js.map +1 -0
- package/dist/report/formatConsole.d.ts +3 -0
- package/dist/report/formatConsole.d.ts.map +1 -0
- package/dist/report/formatConsole.js +112 -0
- package/dist/report/formatConsole.js.map +1 -0
- package/dist/report/index.d.ts +4 -0
- package/dist/report/index.d.ts.map +1 -0
- package/dist/report/index.js +20 -0
- package/dist/report/index.js.map +1 -0
- package/dist/report/sort.d.ts +9 -0
- package/dist/report/sort.d.ts.map +1 -0
- package/dist/report/sort.js +20 -0
- package/dist/report/sort.js.map +1 -0
- package/dist/report/types.d.ts +85 -0
- package/dist/report/types.d.ts.map +1 -0
- package/dist/report/types.js +3 -0
- package/dist/report/types.js.map +1 -0
- package/dist/run.d.ts +8 -0
- package/dist/run.d.ts.map +1 -0
- package/dist/run.js +20 -0
- package/dist/run.js.map +1 -0
- package/dist/scope.d.ts +5 -0
- package/dist/scope.d.ts.map +1 -0
- package/dist/scope.js +23 -0
- package/dist/scope.js.map +1 -0
- package/dist/types.d.ts +150 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/url.d.ts +3 -0
- package/dist/url.d.ts.map +1 -0
- package/dist/url.js +82 -0
- package/dist/url.js.map +1 -0
- package/package.json +23 -0
- package/src/baseline.ts +217 -0
- package/src/diff.ts +150 -0
- package/src/fingerprint.ts +107 -0
- package/src/hash.ts +29 -0
- package/src/impact.ts +27 -0
- package/src/index.ts +11 -0
- package/src/issue.ts +49 -0
- package/src/normalize.ts +66 -0
- package/src/report/buildReport.ts +276 -0
- package/src/report/formatConsole.ts +137 -0
- package/src/report/index.ts +3 -0
- package/src/report/sort.ts +28 -0
- package/src/report/types.ts +101 -0
- package/src/run.ts +22 -0
- package/src/scope.ts +25 -0
- package/src/types.ts +167 -0
- package/src/url.ts +102 -0
- package/test/baseline.test.ts +151 -0
- package/test/diff.test.ts +113 -0
- package/test/fingerprint.test.ts +41 -0
- package/test/issue.test.ts +79 -0
- package/test/report.build.test.ts +191 -0
- package/test/report.console.test.ts +102 -0
- package/test/url.test.ts +25 -0
- package/tsconfig.json +8 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest"
|
|
2
|
+
import { buildBaselineFromRun } from "../src/baseline"
|
|
3
|
+
import { diffRuns } from "../src/diff"
|
|
4
|
+
import { buildReport } from "../src/report/buildReport"
|
|
5
|
+
import { TrailmarkFinding, TrailmarkRun } from "../src/types"
|
|
6
|
+
|
|
7
|
+
function makeFinding(overrides: Partial<TrailmarkFinding>): TrailmarkFinding {
|
|
8
|
+
return {
|
|
9
|
+
issueId: "issue-a",
|
|
10
|
+
relaxedIssueId: "relaxed-a",
|
|
11
|
+
ruleId: "image-alt",
|
|
12
|
+
impact: "serious",
|
|
13
|
+
tags: ["wcag2a"],
|
|
14
|
+
pageUrl: "https://example.com/checkout",
|
|
15
|
+
pageKey: "example.com/checkout",
|
|
16
|
+
target: ["img.hero"],
|
|
17
|
+
targetHash: "target-a",
|
|
18
|
+
selectorHint: "img.hero",
|
|
19
|
+
failureSummary: "Element does not have an alt attribute",
|
|
20
|
+
...overrides,
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function makeRun(findings: TrailmarkFinding[]): TrailmarkRun {
|
|
25
|
+
return {
|
|
26
|
+
version: 1,
|
|
27
|
+
startedAt: "2026-01-01T00:00:00.000Z",
|
|
28
|
+
finishedAt: "2026-01-01T00:00:20.000Z",
|
|
29
|
+
tool: { name: "trailmark", version: "0.1.0", scanner: "@axe-core/playwright" },
|
|
30
|
+
findings,
|
|
31
|
+
scanErrors: [],
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
describe("buildReport", () => {
|
|
36
|
+
it("builds deterministic summary and issue/occurrence grouping", () => {
|
|
37
|
+
const baselineRun = makeRun([
|
|
38
|
+
makeFinding({
|
|
39
|
+
issueId: "issue-a",
|
|
40
|
+
relaxedIssueId: "relaxed-a",
|
|
41
|
+
impact: "serious",
|
|
42
|
+
}),
|
|
43
|
+
])
|
|
44
|
+
const baseline = buildBaselineFromRun(baselineRun, { configHash: "cfg" })
|
|
45
|
+
|
|
46
|
+
const currentRun = makeRun([
|
|
47
|
+
makeFinding({
|
|
48
|
+
issueId: "issue-c",
|
|
49
|
+
relaxedIssueId: "relaxed-c",
|
|
50
|
+
ruleId: "color-contrast",
|
|
51
|
+
impact: "critical",
|
|
52
|
+
pageUrl: "https://example.com/cart",
|
|
53
|
+
pageKey: "example.com/cart",
|
|
54
|
+
target: ["button.checkout"],
|
|
55
|
+
targetHash: "target-c",
|
|
56
|
+
selectorHint: "button.checkout",
|
|
57
|
+
occurredAt: "2026-01-01T00:00:10.000Z",
|
|
58
|
+
meta: {
|
|
59
|
+
testId: "t-2",
|
|
60
|
+
projectName: "chromium",
|
|
61
|
+
},
|
|
62
|
+
}),
|
|
63
|
+
makeFinding({
|
|
64
|
+
issueId: "issue-b",
|
|
65
|
+
relaxedIssueId: "relaxed-b",
|
|
66
|
+
ruleId: "label",
|
|
67
|
+
impact: "moderate",
|
|
68
|
+
pageUrl: "https://example.com/checkout",
|
|
69
|
+
pageKey: "example.com/checkout",
|
|
70
|
+
target: ["input#email"],
|
|
71
|
+
targetHash: "target-b",
|
|
72
|
+
selectorHint: "input#email",
|
|
73
|
+
occurredAt: "2026-01-01T00:00:11.000Z",
|
|
74
|
+
meta: {
|
|
75
|
+
testId: "t-3",
|
|
76
|
+
projectName: "chromium",
|
|
77
|
+
},
|
|
78
|
+
attachments: [
|
|
79
|
+
{
|
|
80
|
+
kind: "viewport",
|
|
81
|
+
path: ".trailmark/artifacts/run-1/moderate__label__example_com_checkout__issue-b__viewport.png",
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
}),
|
|
85
|
+
makeFinding({
|
|
86
|
+
issueId: "issue-b",
|
|
87
|
+
relaxedIssueId: "relaxed-b",
|
|
88
|
+
ruleId: "label",
|
|
89
|
+
impact: "moderate",
|
|
90
|
+
pageUrl: "https://example.com/checkout",
|
|
91
|
+
pageKey: "example.com/checkout",
|
|
92
|
+
target: ["input#email"],
|
|
93
|
+
targetHash: "target-b",
|
|
94
|
+
selectorHint: "input#email",
|
|
95
|
+
occurredAt: "2026-01-01T00:00:12.000Z",
|
|
96
|
+
meta: {
|
|
97
|
+
testId: "t-3",
|
|
98
|
+
projectName: "chromium",
|
|
99
|
+
},
|
|
100
|
+
}),
|
|
101
|
+
makeFinding({
|
|
102
|
+
issueId: "issue-b",
|
|
103
|
+
relaxedIssueId: "relaxed-b",
|
|
104
|
+
ruleId: "label",
|
|
105
|
+
impact: "moderate",
|
|
106
|
+
pageUrl: "https://example.com/checkout",
|
|
107
|
+
pageKey: "example.com/checkout",
|
|
108
|
+
target: ["input#email"],
|
|
109
|
+
targetHash: "target-b",
|
|
110
|
+
selectorHint: "input#email",
|
|
111
|
+
occurredAt: "2026-01-01T00:00:13.000Z",
|
|
112
|
+
meta: {
|
|
113
|
+
testId: "t-4",
|
|
114
|
+
projectName: "webkit",
|
|
115
|
+
},
|
|
116
|
+
}),
|
|
117
|
+
makeFinding({
|
|
118
|
+
issueId: "issue-a",
|
|
119
|
+
relaxedIssueId: "relaxed-a",
|
|
120
|
+
impact: "serious",
|
|
121
|
+
occurredAt: "2026-01-01T00:00:14.000Z",
|
|
122
|
+
}),
|
|
123
|
+
])
|
|
124
|
+
|
|
125
|
+
const diff = diffRuns(baseline, currentRun, { failOnImpact: ["serious", "critical"] })
|
|
126
|
+
const report = buildReport({
|
|
127
|
+
run: currentRun,
|
|
128
|
+
mode: "check",
|
|
129
|
+
configHash: "cfg",
|
|
130
|
+
diff,
|
|
131
|
+
createdAt: "2026-01-01T00:01:00.000Z",
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
expect(report.run.reportVersion).toBe(2)
|
|
135
|
+
expect(report.run.createdAt).toBe("2026-01-01T00:01:00.000Z")
|
|
136
|
+
|
|
137
|
+
expect(report.summary).toEqual({
|
|
138
|
+
scannedPages: 2,
|
|
139
|
+
totalIssues: 3,
|
|
140
|
+
totalOccurrences: 5,
|
|
141
|
+
scanErrors: 0,
|
|
142
|
+
newIssues: 2,
|
|
143
|
+
existingIssues: 1,
|
|
144
|
+
resolvedIssues: 0,
|
|
145
|
+
byImpact: {
|
|
146
|
+
critical: 1,
|
|
147
|
+
moderate: 1,
|
|
148
|
+
serious: 1,
|
|
149
|
+
},
|
|
150
|
+
byRuleId: {
|
|
151
|
+
"color-contrast": 1,
|
|
152
|
+
"image-alt": 1,
|
|
153
|
+
label: 1,
|
|
154
|
+
},
|
|
155
|
+
byPageKey: {
|
|
156
|
+
"example.com/cart": 1,
|
|
157
|
+
"example.com/checkout": 2,
|
|
158
|
+
},
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
expect(report.issues.map((issue) => issue.issueId)).toEqual(["issue-c", "issue-a", "issue-b"])
|
|
162
|
+
|
|
163
|
+
const issueB = report.issues.find((issue) => issue.issueId === "issue-b")
|
|
164
|
+
expect(issueB?.occurrences).toHaveLength(2)
|
|
165
|
+
expect(issueB?.occurrences[0].attachments[0].path).toContain("moderate__label")
|
|
166
|
+
|
|
167
|
+
expect(report.diff).toEqual({
|
|
168
|
+
newIssueIds: ["issue-b", "issue-c"],
|
|
169
|
+
existingIssueIds: ["issue-a"],
|
|
170
|
+
resolvedIssueIds: [],
|
|
171
|
+
newIssues: [
|
|
172
|
+
{
|
|
173
|
+
issueId: "issue-c",
|
|
174
|
+
ruleId: "color-contrast",
|
|
175
|
+
impact: "critical",
|
|
176
|
+
pageKey: "example.com/cart",
|
|
177
|
+
selectorHint: "button.checkout",
|
|
178
|
+
occurrenceCount: 1,
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
issueId: "issue-b",
|
|
182
|
+
ruleId: "label",
|
|
183
|
+
impact: "moderate",
|
|
184
|
+
pageKey: "example.com/checkout",
|
|
185
|
+
selectorHint: "input#email",
|
|
186
|
+
occurrenceCount: 2,
|
|
187
|
+
},
|
|
188
|
+
],
|
|
189
|
+
})
|
|
190
|
+
})
|
|
191
|
+
})
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest"
|
|
2
|
+
import { buildBaselineFromRun } from "../src/baseline"
|
|
3
|
+
import { diffRuns } from "../src/diff"
|
|
4
|
+
import { buildReport } from "../src/report/buildReport"
|
|
5
|
+
import { formatConsoleReport } from "../src/report/formatConsole"
|
|
6
|
+
import { TrailmarkFinding, TrailmarkRun } from "../src/types"
|
|
7
|
+
|
|
8
|
+
function makeFinding(overrides: Partial<TrailmarkFinding>): TrailmarkFinding {
|
|
9
|
+
return {
|
|
10
|
+
issueId: "issue-a",
|
|
11
|
+
relaxedIssueId: "relaxed-a",
|
|
12
|
+
ruleId: "image-alt",
|
|
13
|
+
impact: "serious",
|
|
14
|
+
tags: ["wcag2a"],
|
|
15
|
+
pageUrl: "https://example.com/checkout",
|
|
16
|
+
pageKey: "example.com/checkout",
|
|
17
|
+
target: ["img.hero"],
|
|
18
|
+
targetHash: "target-a",
|
|
19
|
+
selectorHint: "img.hero",
|
|
20
|
+
failureSummary: "Element does not have an alt attribute",
|
|
21
|
+
...overrides,
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function makeRun(findings: TrailmarkFinding[]): TrailmarkRun {
|
|
26
|
+
return {
|
|
27
|
+
version: 1,
|
|
28
|
+
startedAt: "2026-01-01T00:00:00.000Z",
|
|
29
|
+
finishedAt: "2026-01-01T00:00:20.000Z",
|
|
30
|
+
tool: { name: "trailmark", version: "0.1.0", scanner: "@axe-core/playwright" },
|
|
31
|
+
findings,
|
|
32
|
+
scanErrors: [],
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
describe("formatConsoleReport", () => {
|
|
37
|
+
it("formats grouped NEW issue output with artifacts and reproduce hint", () => {
|
|
38
|
+
const baselineRun = makeRun([
|
|
39
|
+
makeFinding({
|
|
40
|
+
issueId: "issue-a",
|
|
41
|
+
relaxedIssueId: "relaxed-a",
|
|
42
|
+
}),
|
|
43
|
+
])
|
|
44
|
+
const baseline = buildBaselineFromRun(baselineRun, { configHash: "cfg" })
|
|
45
|
+
|
|
46
|
+
const currentRun = makeRun([
|
|
47
|
+
makeFinding({ issueId: "issue-a", relaxedIssueId: "relaxed-a" }),
|
|
48
|
+
makeFinding({
|
|
49
|
+
issueId: "issue-b",
|
|
50
|
+
relaxedIssueId: "relaxed-b",
|
|
51
|
+
ruleId: "label",
|
|
52
|
+
impact: "moderate",
|
|
53
|
+
target: ["input#email"],
|
|
54
|
+
targetHash: "target-b",
|
|
55
|
+
selectorHint: "input#email",
|
|
56
|
+
meta: {
|
|
57
|
+
testId: "checkout-a11y",
|
|
58
|
+
projectName: "chromium",
|
|
59
|
+
},
|
|
60
|
+
attachments: [
|
|
61
|
+
{
|
|
62
|
+
kind: "viewport",
|
|
63
|
+
path: ".trailmark/artifacts/20260101/moderate__label__example_com_checkout__issue-b__viewport.png",
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
}),
|
|
67
|
+
])
|
|
68
|
+
|
|
69
|
+
const diff = diffRuns(baseline, currentRun, { failOnImpact: ["serious", "critical"] })
|
|
70
|
+
const report = buildReport({ run: currentRun, mode: "check", configHash: "cfg", diff })
|
|
71
|
+
|
|
72
|
+
expect(
|
|
73
|
+
formatConsoleReport(report, { failOnImpact: ["serious", "critical"], topPagesPerRule: 2 }),
|
|
74
|
+
).toEqual(
|
|
75
|
+
`trailmark: scanned pages=1 | total issues=2 | NEW=1 | fail on=serious, critical\ntrailmark: [moderate] 1 NEW issue(s)\n rule label (1) top pages: example.com/checkout\n - moderate | label | example.com/checkout | input#email\n artifact: .trailmark/artifacts/20260101/moderate__label__example_com_checkout__issue-b__viewport.png\n reproduce: testId=checkout-a11y url=https://example.com/checkout`,
|
|
76
|
+
)
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
it("prints a concise message when no new issues are present", () => {
|
|
80
|
+
const baselineRun = makeRun([
|
|
81
|
+
makeFinding({
|
|
82
|
+
issueId: "issue-a",
|
|
83
|
+
relaxedIssueId: "relaxed-a",
|
|
84
|
+
}),
|
|
85
|
+
])
|
|
86
|
+
const baseline = buildBaselineFromRun(baselineRun, { configHash: "cfg" })
|
|
87
|
+
|
|
88
|
+
const currentRun = makeRun([
|
|
89
|
+
makeFinding({
|
|
90
|
+
issueId: "issue-a",
|
|
91
|
+
relaxedIssueId: "relaxed-a",
|
|
92
|
+
}),
|
|
93
|
+
])
|
|
94
|
+
|
|
95
|
+
const diff = diffRuns(baseline, currentRun, { failOnImpact: ["serious", "critical"] })
|
|
96
|
+
const report = buildReport({ run: currentRun, mode: "check", configHash: "cfg", diff })
|
|
97
|
+
|
|
98
|
+
expect(formatConsoleReport(report)).toContain(
|
|
99
|
+
"trailmark: no new accessibility violations compared to baseline.",
|
|
100
|
+
)
|
|
101
|
+
})
|
|
102
|
+
})
|
package/test/url.test.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest"
|
|
2
|
+
import { normalizeUrlToPageKey } from "../src/url"
|
|
3
|
+
|
|
4
|
+
describe("normalizeUrlToPageKey", () => {
|
|
5
|
+
it("lowercases host and strips hash/query by default", () => {
|
|
6
|
+
const key = normalizeUrlToPageKey("https://EXAMPLE.com/Checkout?order=123#summary")
|
|
7
|
+
expect(key).toBe("example.com/Checkout")
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
it("keeps allowed query parameters only", () => {
|
|
11
|
+
const key = normalizeUrlToPageKey("https://shop.example.com/p?sku=abc&utm=1&lang=en", {
|
|
12
|
+
stripQuery: { allow: ["sku", "lang"] },
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
expect(key).toBe("shop.example.com/p?lang=en&sku=abc")
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
it("applies route replacements in order", () => {
|
|
19
|
+
const key = normalizeUrlToPageKey("https://example.com/products/12345", {
|
|
20
|
+
routePatterns: [{ match: "products/\\d+", replace: "products/:id" }],
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
expect(key).toBe("example.com/products/:id")
|
|
24
|
+
})
|
|
25
|
+
})
|