Skip to content

Commit

Permalink
fix: JSON stringify failure details for CSV (#613)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored Jul 2, 2024
1 parent 929caa7 commit 13ab5b0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,11 @@ async function main() {
if (format === Format.CSV) {
const showIt = shouldShowResult(link, verbosity);
if (showIt) {
const failureDetails = link.failureDetails
? JSON.stringify(link.failureDetails, null, 2)
: '';
console.log(
`"${link.url}",${link.status},${link.state},"${link.parent || ''}","${
link.failureDetails?.toString() || ''
}"`,
`"${link.url}",${link.status},${link.state},"${link.parent || ''}","${failureDetails}"`,
);
}
}
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/localbroke/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Locally broken

This is a [link](/test) to a page that doesn't exist.
14 changes: 14 additions & 0 deletions test/test.cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,20 @@ describe('cli', function () {
assert.match(response.stdout, /README.md",200,OK,/);
});

it('should serialize errors with CSV and verbose output', async () => {
const response = await execa(node, [
linkinator,
'--format',
'csv',
'--verbosity',
'DEBUG',
'test/fixtures/localbroke/README.md',
]);
// This is a very lazy way of trying to recognize the JSON we expect
// in CSV without using a CSV parser.
assert.match(response.stdout, /statusText": "Not Found"/);
});

it('should provide JSON if asked nicely', async () => {
const response = await execa(node, [
linkinator,
Expand Down

0 comments on commit 13ab5b0

Please sign in to comment.