Skip to content

Commit fcbecfa

Browse files
committed
chore: integrate issues and fix up checks
1 parent 0b12688 commit fcbecfa

File tree

5 files changed

+17
-44
lines changed

5 files changed

+17
-44
lines changed

src/formatters/consoleFormatter.ts

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,7 @@ function formatArgs(consoleData: ConsoleMessageData): string {
6969

7070
return result.join('\n');
7171
}
72-
interface IssueDetailsWithResources {
73-
violatingNodeId?: number;
74-
nodeId?: number;
75-
documentNodeId?: number;
76-
request?: {
77-
requestId?: string;
78-
url: string;
79-
};
80-
}
72+
8173
export function formatIssue(
8274
issue: AggregatedIssue,
8375
description?: string,
@@ -100,45 +92,29 @@ export function formatIssue(
10092
}
10193
}
10294

103-
const issues: Array<{
104-
details?: () => IssueDetailsWithResources;
105-
getDetails?: () => IssueDetailsWithResources;
106-
}> = [
107-
...issue.getCorsIssues(),
108-
...issue.getMixedContentIssues(),
109-
...issue.getGenericIssues(),
110-
...issue.getLowContrastIssues(),
111-
...issue.getElementAccessibilityIssues(),
112-
...issue.getQuirksModeIssues(),
113-
];
95+
const issues = issue.getAllIssues();
11496
const affectedResources: Array<{
11597
uid?: string;
11698
data?: object;
11799
request?: string | number;
118100
}> = [];
119101
for (const singleIssue of issues) {
120-
if (!singleIssue.details && !singleIssue.getDetails) continue;
121-
122-
let details =
123-
singleIssue.details?.() as unknown as IssueDetailsWithResources;
124-
if (!details)
125-
details =
126-
singleIssue.getDetails?.() as unknown as IssueDetailsWithResources;
102+
const details = singleIssue.details();
127103
if (!details) continue;
128104

129105
let uid;
130106
let request: number | string | undefined;
131-
if (details.violatingNodeId && context) {
107+
if ('violatingNodeId' in details && details.violatingNodeId && context) {
132108
uid = context.resolveCdpElementId(details.violatingNodeId);
133109
}
134-
if (details.nodeId && context) {
110+
if ('nodeId' in details && details.nodeId && context) {
135111
uid = context.resolveCdpElementId(details.nodeId);
136112
}
137-
if (details.documentNodeId && context) {
113+
if ('documentNodeId' in details && details.documentNodeId && context) {
138114
uid = context.resolveCdpElementId(details.documentNodeId);
139115
}
140116

141-
if (details.request) {
117+
if ('request' in details && details.request) {
142118
request = details.request.url;
143119
if (details.request.requestId && context) {
144120
const resolvedId = context.resolveCdpRequestId(
@@ -150,14 +126,18 @@ export function formatIssue(
150126
}
151127
}
152128

129+
// We send the remaining details as untyped JSON because the DevTools
130+
// frontend code is currently not re-usable.
153131
// eslint-disable-next-line
154132
const data = structuredClone(details) as any;
155133
delete data.violatingNodeId;
156134
delete data.nodeId;
157135
delete data.documentNodeId;
158136
delete data.errorType;
159137
delete data.frameId;
160-
delete data.request;
138+
if (data.request) {
139+
delete data.request.requestId;
140+
}
161141
affectedResources.push({
162142
uid,
163143
data: data,
@@ -180,7 +160,6 @@ export function formatIssue(
180160
return details.join(' ');
181161
}),
182162
);
183-
if (result.length === 0)
184-
return 'No details provided for the issue ' + issue.code();
163+
if (result.length === 0) return 'No affected resources found';
185164
return result.join('\n');
186165
}

tests/formatters/consoleFormatter.test.js.snapshot

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,4 @@ This is a mock issue description
4343
Learn more:
4444
[Learn more](http://example.com/learnmore)
4545
[Learn more 2](http://example.com/another-learnmore)
46-
### Affected resources
47-
data={"violatingNodeAttribute":"test"}
4846
`;

tests/tools/console.test.js.snapshot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ Note that if an opaque response is sufficient, the request's mode can be set to
2525
Learn more:
2626
[Cross-Origin Resource Sharing (\`CORS\`)](https://web.dev/cross-origin-resource-sharing)
2727
### Affected resources
28-
reqid=<reqid> data={"corsErrorStatus":{"corsError":"PreflightMissingAllowOriginHeader","failedParameter":""},"isWarning":false,"initiatorOrigin":"","clientSecurityState":{"initiatorIsSecureContext":false,"initiatorIPAddressSpace":"Loopback","privateNetworkRequestPolicy":"BlockFromInsecureToMorePrivate"}}
28+
reqid=<reqid> data={"corsErrorStatus":{"corsError":"PreflightMissingAllowOriginHeader","failedParameter":""},"isWarning":false,"request":{"url":"http://localhost:19281/data.json"},"initiatorOrigin":"","clientSecurityState":{"initiatorIsSecureContext":false,"initiatorIPAddressSpace":"Loopback","privateNetworkRequestPolicy":"BlockFromInsecureToMorePrivate"}}
2929
`;

tests/tools/console.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ describe('console', () => {
239239
const rawText = formattedResponse[0].text as string;
240240
const sanitizedText = rawText
241241
.replaceAll(/ID: \d+/g, 'ID: <ID>')
242-
.replaceAll(/reqid=\d+/g, 'reqid=<reqid>');
242+
.replaceAll(/reqid=\d+/g, 'reqid=<reqid>')
243+
.replaceAll(/localhost:d+/g, 'hostname:port');
243244
t.assert.snapshot?.(sanitizedText);
244245
});
245246
});

tests/utils.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,7 @@ export function stabilizeResponseOutput(text: unknown) {
196196

197197
export function getMockAggregatedIssue(): sinon.SinonStubbedInstance<AggregatedIssue> {
198198
const mockAggregatedIssue = sinon.createStubInstance(AggregatedIssue);
199-
mockAggregatedIssue.getGenericIssues.returns(new Set());
200-
mockAggregatedIssue.getLowContrastIssues.returns(new Set());
201-
mockAggregatedIssue.getElementAccessibilityIssues.returns(new Set());
202-
mockAggregatedIssue.getQuirksModeIssues.returns(new Set());
203-
mockAggregatedIssue.getCorsIssues.returns(new Set());
204-
mockAggregatedIssue.getMixedContentIssues.returns(new Set());
199+
mockAggregatedIssue.getAllIssues.returns([]);
205200
return mockAggregatedIssue;
206201
}
207202

0 commit comments

Comments
 (0)