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
16 changes: 3 additions & 13 deletions src/formatters/CommentFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import type {CD4ACommentThread, CD4AEditorAnchorSignature} from '../types.js';
import type {CD4ACommentThread} from '../types.js';

export interface CommentFormatterOptions {
resolveBackendNodeId?: (backendNodeId: number) => Promise<string | undefined>;
Expand All @@ -16,7 +16,6 @@ export interface StructuredCommentThread {
text: string;
elementUid?: string;
reqid?: number;
editor?: CD4AEditorAnchorSignature;
}

function formatCommentThread(thread: StructuredCommentThread): string {
Expand All @@ -25,16 +24,10 @@ function formatCommentThread(thread: StructuredCommentThread): string {
`- Comment: ${thread.text}`,
];
if (thread.elementUid) {
lines.push(`- Target element (snapshot UID): ${thread.elementUid}`);
lines.push(`- Related element uid: ${thread.elementUid}`);
}
if (thread.reqid !== undefined) {
lines.push(`- Network request ID (reqid): ${thread.reqid}`);
}
if (thread.editor) {
const location = thread.editor.filePath
? `${thread.editor.filePath}:${thread.editor.lineNumber}`
: `line ${thread.editor.lineNumber}`;
lines.push(`- Editor location: ${location}`);
lines.push(`- Related network reqid: ${thread.reqid}`);
}
return lines.join('\n');
}
Expand Down Expand Up @@ -87,9 +80,6 @@ export class CommentFormatter {
if (reqid !== undefined) {
item.reqid = reqid;
}
if (thread.editor) {
item.editor = thread.editor;
}
structuredThreads.push(item);
}
return new CommentFormatter(structuredThreads);
Expand Down
44 changes: 7 additions & 37 deletions tests/formatters/CommentFormatter.test.js.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ exports[`CommentFormatter > formats comments with targets and editor locations t
"id": "comment-1",
"text": "Fix the color contrast here",
"elementUid": "element-uid-42",
"reqid": 7,
"editor": {
"filePath": "src/style.css",
"lineNumber": 10
}
"reqid": 7
}
]
`;
Expand All @@ -18,29 +14,8 @@ Found 1 DevTools comment thread(s):

### Thread: comment-1
- Comment: Fix the color contrast here
- Target element (snapshot UID): element-uid-42
- Network request ID (reqid): 7
- Editor location: src/style.css:10
`;

exports[`CommentFormatter > formats editor location when filePath is missing toJSON 1`] = `
[
{
"id": "comment-2",
"text": "Review this script line",
"editor": {
"lineNumber": 25
}
}
]
`;

exports[`CommentFormatter > formats editor location when filePath is missing toString 1`] = `
Found 1 DevTools comment thread(s):

### Thread: comment-2
- Comment: Review this script line
- Editor location: line 25
- Related element uid: element-uid-42
- Related network reqid: 7
`;

exports[`CommentFormatter > formats empty comments list toJSON 1`] = `
Expand All @@ -54,7 +29,7 @@ No open DevTools comments found.
exports[`CommentFormatter > formats single thread using static formatThread 1`] = `
### Thread: comment-3
- Comment: Check padding
- Target element (snapshot UID): node-99
- Related element uid: node-99
`;

exports[`CommentFormatter > omits unresolved targets when from() resolves undefined toJSON 1`] = `
Expand All @@ -79,11 +54,7 @@ exports[`CommentFormatter > resolves targets using from() method toJSON 1`] = `
"id": "comment-1",
"text": "Fix the color contrast here",
"elementUid": "element-uid-42",
"reqid": 7,
"editor": {
"filePath": "src/style.css",
"lineNumber": 10
}
"reqid": 7
}
]
`;
Expand All @@ -93,7 +64,6 @@ Found 1 DevTools comment thread(s):

### Thread: comment-1
- Comment: Fix the color contrast here
- Target element (snapshot UID): element-uid-42
- Network request ID (reqid): 7
- Editor location: src/style.css:10
- Related element uid: element-uid-42
- Related network reqid: 7
`;
15 changes: 0 additions & 15 deletions tests/formatters/CommentFormatter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,6 @@ describe('CommentFormatter', () => {
text: 'Fix the color contrast here',
elementUid: 'element-uid-42',
reqid: 7,
editor: {
filePath: 'src/style.css',
lineNumber: 10,
},
};
return new CommentFormatter([thread]);
});

formatterTest('formats editor location when filePath is missing', () => {
const thread: StructuredCommentThread = {
id: 'comment-2',
text: 'Review this script line',
editor: {
lineNumber: 25,
},
};
return new CommentFormatter([thread]);
});
Expand Down
Loading