Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions e2e/plugin-axe-e2e/tests/__snapshots__/collect.e2e.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,11 @@ exports[`PLUGIN collect report with axe-plugin NPM package > should run plugin o
{
"message": "[\`body > button\`] Fix any of the following: Element does not have inner text that is visible to screen readers aria-label attribute does not exist or is empty aria-labelledby attribute does not exist, references elements that do not exist or references elements that are empty Element has no title attribute Element does not have an implicit (wrapped) <label> Element does not have an explicit <label> Element's default semantics were not overridden with role="none" or role="presentation"",
"severity": "error",
"source": {
"selector": "body > button",
"snippet": "<button></button>",
"url": "file:///<TEST_DIR>/index.html",
},
},
],
},
Expand All @@ -525,6 +530,13 @@ exports[`PLUGIN collect report with axe-plugin NPM package > should run plugin o
{
"message": "[\`.low-contrast\`] Fix any of the following: Element has insufficient color contrast of 1.57 (foreground color: #777777, background color: #999999, font size: 12.0pt (16px), font weight: normal). Expected contrast ratio of 4.5:1",
"severity": "error",
"source": {
"selector": ".low-contrast",
"snippet": "<div class=\"low-contrast\">
This text has poor color contrast and may be hard to read.
</div>",
"url": "file:///<TEST_DIR>/index.html",
},
},
],
},
Expand Down Expand Up @@ -614,6 +626,13 @@ exports[`PLUGIN collect report with axe-plugin NPM package > should run plugin o
{
"message": "[\`div[role="button"]\`] Fix any of the following: Invalid ARIA attribute name: aria-invalid-attribute",
"severity": "error",
"source": {
"selector": "div[role=\"button\"]",
"snippet": "<div role=\"button\" aria-invalid-attribute=\"true\">
Button with invalid ARIA attribute
</div>",
"url": "file:///<TEST_DIR>/index.html",
},
},
],
},
Expand All @@ -631,6 +650,11 @@ exports[`PLUGIN collect report with axe-plugin NPM package > should run plugin o
{
"message": "[\`img\`] Fix any of the following: Element does not have an alt attribute aria-label attribute does not exist or is empty aria-labelledby attribute does not exist, references elements that do not exist or references elements that are empty Element has no title attribute Element's default semantics were not overridden with role="none" or role="presentation"",
"severity": "error",
"source": {
"selector": "img",
"snippet": "<img src=\"test-image.jpg\" width=\"200\" height=\"150\">",
"url": "file:///<TEST_DIR>/index.html",
},
},
],
},
Expand All @@ -648,6 +672,11 @@ exports[`PLUGIN collect report with axe-plugin NPM package > should run plugin o
{
"message": "[\`a\`] Fix all of the following: Element is in tab order and does not have accessible text Fix any of the following: Element does not have text that is visible to screen readers aria-label attribute does not exist or is empty aria-labelledby attribute does not exist, references elements that do not exist or references elements that are empty Element has no title attribute",
"severity": "error",
"source": {
"selector": "a",
"snippet": "<a href=\"#\"></a>",
"url": "file:///<TEST_DIR>/index.html",
},
},
],
},
Expand Down
13 changes: 12 additions & 1 deletion e2e/plugin-axe-e2e/tests/collect.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ import {
} from '@code-pushup/test-utils';
import { executeProcess, readJsonFile } from '@code-pushup/utils';

function sanitizeReportPaths(report: Report): Report {
const reportJson = JSON.stringify(report);
const sanitized = reportJson.replace(
/\/(?:[^/\s"]+\/)+index\.html/g,
'/<TEST_DIR>/index.html',
);
return JSON.parse(sanitized);
}

describe('PLUGIN collect report with axe-plugin NPM package', () => {
const fixturesDir = path.join('e2e', nxTargetProject(), 'mocks', 'fixtures');
const testFileDir = path.join(
Expand Down Expand Up @@ -44,6 +53,8 @@ describe('PLUGIN collect report with axe-plugin NPM package', () => {
);

expect(() => reportSchema.parse(report)).not.toThrow();
expect(omitVariableReportData(report)).toMatchSnapshot();
expect(
omitVariableReportData(sanitizeReportPaths(report)),
).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ A `Issue` with severity `info` is present and names to the given file.
<tr>
<th>Severity</th>
<th>Message</th>
<th>Source file</th>
<th>Line(s)</th>
<th>Source</th>
<th>Location</th>
</tr>
<tr>
<td>ℹ️ <i>info</i></td>
Expand All @@ -45,8 +45,8 @@ The file sizes of the given file, the budget as well as the size difference is m
<tr>
<th>Severity</th>
<th>Message</th>
<th>Source file</th>
<th>Line(s)</th>
<th>Source</th>
<th>Location</th>
</tr>
<tr>
<td>🚨 <i>error</i></td>
Expand Down
12 changes: 6 additions & 6 deletions examples/plugins/src/package-json/docs/dependencies.audit.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ An `Issue` with severity `info` is present and names to the given file.
<tr>
<th>Severity</th>
<th>Message</th>
<th>Source file</th>
<th>Line(s)</th>
<th>Source</th>
<th>Location</th>
</tr>
<tr>
<td>ℹ️ <i>info</i></td>
Expand All @@ -44,8 +44,8 @@ A `Issue` with severity `info` is present and names to the given file.
<tr>
<th>Severity</th>
<th>Message</th>
<th>Source file</th>
<th>Line(s)</th>
<th>Source</th>
<th>Location</th>
</tr>
<tr>
<td>ℹ️ <i>info</i></td>
Expand All @@ -65,8 +65,8 @@ The dependencies of the given file, the target version as well as the given vers
<tr>
<th>Severity</th>
<th>Message</th>
<th>Source file</th>
<th>Line(s)</th>
<th>Source</th>
<th>Location</th>
</tr>
<tr>
<td>🚨 <i>error</i></td>
Expand Down
12 changes: 6 additions & 6 deletions examples/plugins/src/package-json/docs/license.audit.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ A `Issue` with severity `info` is present and names to the given file.
<tr>
<th>Severity</th>
<th>Message</th>
<th>Source file</th>
<th>Line(s)</th>
<th>Source</th>
<th>Location</th>
</tr>
<tr>
<td>ℹ️ <i>info</i></td>
Expand All @@ -44,8 +44,8 @@ A `Issue` with severity `info` is present and names to the given file.
<tr>
<th>Severity</th>
<th>Message</th>
<th>Source file</th>
<th>Line(s)</th>
<th>Source</th>
<th>Location</th>
</tr>
<tr>
<td>ℹ️ <i>info</i></td>
Expand All @@ -65,8 +65,8 @@ The `license` of the given file, the target `license` as well as the given `lice
<tr>
<th>Severity</th>
<th>Message</th>
<th>Source file</th>
<th>Line(s)</th>
<th>Source</th>
<th>Location</th>
</tr>
<tr>
<td>🚨 <i>error</i></td>
Expand Down
12 changes: 6 additions & 6 deletions examples/plugins/src/package-json/docs/type.audit.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ A `Issue` with severity `info` is present and names to the given file.
<tr>
<th>Severity</th>
<th>Message</th>
<th>Source file</th>
<th>Line(s)</th>
<th>Source</th>
<th>Location</th>
</tr>
<tr>
<td>ℹ️ <i>info</i></td>
Expand All @@ -48,8 +48,8 @@ A `Issue` with severity `info` is present and names to the given file.
<tr>
<th>Severity</th>
<th>Message</th>
<th>Source file</th>
<th>Line(s)</th>
<th>Source</th>
<th>Location</th>
</tr>
<tr>
<td>ℹ️ <i>info</i></td>
Expand All @@ -69,8 +69,8 @@ The `type` of the given file, the target `type` as well as the given `type` are
<tr>
<th>Severity</th>
<th>Message</th>
<th>Source file</th>
<th>Line(s)</th>
<th>Source</th>
<th>Location</th>
</tr>
<tr>
<td>🚨 <i>error</i></td>
Expand Down
6 changes: 3 additions & 3 deletions packages/ci/mocks/fixtures/outputs/report-before.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

#### Issues

| Severity | Message | Source file | Line(s) |
| :----------: | :------------------------------------ | :------------------------ | :-----: |
| ⚠️ _warning_ | Use .ts file extension instead of .js | [`index.js`](../index.js) | |
| Severity | Message | Source | Location |
| :----------: | :------------------------------------ | :------------------------ | :------: |
| ⚠️ _warning_ | Use .ts file extension instead of .js | [`index.js`](../index.js) | |

</details>

Expand Down
7 changes: 4 additions & 3 deletions packages/ci/src/lib/issues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@ import type {
Audit,
AuditReport,
CategoryRef,
Issue,
FileIssue,
PluginMeta,
Report,
ReportsDiff,
} from '@code-pushup/models';
import { isFileIssue } from '@code-pushup/utils';
import {
type ChangedFiles,
adjustFileName,
adjustLine,
isFileChanged,
} from './git.js';

export type SourceFileIssue = Required<Issue> & IssueContext;
export type SourceFileIssue = FileIssue & IssueContext;

type IssueContext = {
audit: Pick<Audit, 'slug' | 'title'>;
Expand Down Expand Up @@ -71,7 +72,7 @@ function getAuditIssues(
): SourceFileIssue[] {
return (
audit.details?.issues
?.filter((issue): issue is Required<Issue> => issue.source?.file != null)
?.filter(isFileIssue)
.map(issue => ({ ...issue, audit, plugin })) ?? []
);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/docs/custom-plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,8 @@ The `report.md` file should contain a similar content like the following:
<tr>
<th>Severity</th>
<th>Message</th>
<th>Source file</th>
<th>Line(s)</th>
<th>Source</th>
<th>Location</th>
</tr>
<tr>
<td>🚨 <i>error</i></td>
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/lib/implementation/report-to-gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import type {
TableAlignment,
Tree,
} from '@code-pushup/models';
import { isFileIssue } from '@code-pushup/utils';

export function reportToGQL(
report: Report,
Expand Down Expand Up @@ -106,7 +107,7 @@ export function issueToGQL(issue: Issue): PortalIssue {
return {
message: issue.message,
severity: issueSeverityToGQL(issue.severity),
...(issue.source?.file && {
...(isFileIssue(issue) && {
sourceType: safeEnum<PortalIssueSourceType>('SourceCode'),
sourceFilePath: issue.source.file,
sourceStartLine: issue.source.position?.startLine,
Expand Down
23 changes: 12 additions & 11 deletions packages/core/src/lib/normalize.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import type { AuditOutputs, Issue } from '@code-pushup/models';
import { formatGitPath, getGitRoot } from '@code-pushup/utils';
import { formatGitPath, getGitRoot, isFileIssue } from '@code-pushup/utils';

export function normalizeIssue(issue: Issue, gitRoot: string): Issue {
// Early exit to avoid cloning; only file sources need path normalization
if (!isFileIssue(issue)) {
return issue;
}
const { source, ...issueWithoutSource } = issue;
// early exit to avoid issue object cloning.
return source == null
? issue
: {
...issueWithoutSource,
source: {
...source,
file: formatGitPath(source.file, gitRoot),
},
};
return {
...issueWithoutSource,
source: {
...source,
file: formatGitPath(source.file, gitRoot),
},
};
}

export async function normalizeAuditOutputs(
Expand Down
Loading