-
Notifications
You must be signed in to change notification settings - Fork 14
feat: support URL sources upload to portal #1235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
0279e87
512c0fe
6c3dff0
6fe2ae5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,6 @@ import type { | |
| AuditOutputs, | ||
| Issue, | ||
| IssueSeverity, | ||
| SourceUrlLocation, | ||
| } from '@code-pushup/models'; | ||
| import { | ||
| formatIssueSeverities, | ||
|
|
@@ -71,26 +70,35 @@ function formatSelector(selector: axe.CrossTreeSelector): string { | |
| return selector.join(' >> '); | ||
| } | ||
|
|
||
| /** | ||
| * Joins `none`/`all` check messages (each must be fixed). | ||
| * Falls back to first `any` check (OR-ed, one represents the group). | ||
| */ | ||
| function formatNodeMessage(node: axe.NodeResult, fallback: string): string { | ||
| const requiredMessages = [...node.none, ...node.all].map( | ||
| check => check.message, | ||
| ); | ||
| if (requiredMessages.length > 0) { | ||
| return requiredMessages.join('. '); | ||
| } | ||
| return node.any[0]?.message ?? fallback; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible that using only the first message in
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so. The For example, an "Images must have alternative text" audit has only
The first message is a compact, actionable fix, and the other alternatives are already mentioned in the audit docs. Alternatively, a "Links must have discernible text" audit has both
The I also initially thought all the failure messages were useful, but they really aren't.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, the Axe audit title and the docs URL usually provide all the necessary context to describe the failure. The issue source seems much more useful than the message. So, there is no need to clutter issue messages with full failure summaries. |
||
| } | ||
|
|
||
| function toIssue(node: axe.NodeResult, result: axe.Result, url: string): Issue { | ||
| const selector = node.target?.[0] | ||
| ? formatSelector(node.target[0]) | ||
| : undefined; | ||
| const rawMessage = node.failureSummary || result.help; | ||
| const cleanMessage = rawMessage.replace(/\s+/g, ' ').trim(); | ||
|
|
||
| // TODO: Remove selector prefix from message once Portal supports URL sources | ||
| const message = selector ? `[\`${selector}\`] ${cleanMessage}` : cleanMessage; | ||
|
|
||
| const source: SourceUrlLocation = { | ||
| url, | ||
| ...(node.html && { snippet: node.html }), | ||
| ...(selector && { selector }), | ||
| }; | ||
| const message = formatNodeMessage(node, result.help); | ||
|
|
||
| return { | ||
| message: truncateIssueMessage(message), | ||
| severity: impactToSeverity(node.impact), | ||
| source, | ||
| source: { | ||
| url, | ||
| ...(node.html && { snippet: node.html }), | ||
| ...(selector && { selector }), | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The unit tests don't cover a case where there are multiple messages in
allornone. If it's a realistic case, I would test that checks the messages are joined correctly.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a realistic case. Thanks for the pointer!