Skip to content

Commit 493ec2b

Browse files
fix: show per-page rollup on failures (#76)
* fix: show per-page rollup on failures * npm run build Co-authored-by: BeckwithRobot <justin.beckwith+beckwithrobot@gmail.com>
1 parent 66aa9fa commit 493ec2b

4 files changed

Lines changed: 41 additions & 21 deletions

File tree

dist/index.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30019,13 +30019,23 @@ async function main () {
3001930019
if (!result.passed) {
3002030020
const brokenLinks = result.links.filter(x => x.state === 'BROKEN');
3002130021
let failureOutput = `Detected ${brokenLinks.length} broken links.`;
30022-
for (const link of brokenLinks) {
30023-
// Only show the rollup of failures if verbosity is hiding ok links.
30024-
// If all you see is erros, getting a list of errors twice don't look right.
30025-
if (verbosity < LogLevel.ERROR) {
30026-
failureOutput += `\n [${link.status}] ${link.url}`;
30022+
30023+
// build a map of failed links by the parent document
30024+
const parents = brokenLinks.reduce((acc, curr) => {
30025+
const parent = curr.parent || '';
30026+
if (!acc[parent]) {
30027+
acc[parent] = [];
30028+
}
30029+
acc[parent].push(curr);
30030+
return acc;
30031+
}, {});
30032+
30033+
for (const parent of Object.keys(parents)) {
30034+
failureOutput += `\n ${parent}`;
30035+
for (const link of parents[parent]) {
30036+
failureOutput += `\n [${link.status}] ${link.url}`;
30037+
logger.debug(JSON.stringify(link.failureDetails, null, 2));
3002730038
}
30028-
logger.debug(JSON.stringify(link.failureDetails, null, 2));
3002930039
}
3003030040
core.setFailed(failureOutput);
3003130041
}

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,23 @@ async function main () {
7777
if (!result.passed) {
7878
const brokenLinks = result.links.filter(x => x.state === 'BROKEN');
7979
let failureOutput = `Detected ${brokenLinks.length} broken links.`;
80-
for (const link of brokenLinks) {
81-
// Only show the rollup of failures if verbosity is hiding ok links.
82-
// If all you see is erros, getting a list of errors twice don't look right.
83-
if (verbosity < LogLevel.ERROR) {
84-
failureOutput += `\n [${link.status}] ${link.url}`;
80+
81+
// build a map of failed links by the parent document
82+
const parents = brokenLinks.reduce((acc, curr) => {
83+
const parent = curr.parent || '';
84+
if (!acc[parent]) {
85+
acc[parent] = [];
86+
}
87+
acc[parent].push(curr);
88+
return acc;
89+
}, {});
90+
91+
for (const parent of Object.keys(parents)) {
92+
failureOutput += `\n ${parent}`;
93+
for (const link of parents[parent]) {
94+
failureOutput += `\n [${link.status}] ${link.url}`;
95+
logger.debug(JSON.stringify(link.failureDetails, null, 2));
8596
}
86-
logger.debug(JSON.stringify(link.failureDetails, null, 2));
8797
}
8898
core.setFailed(failureOutput);
8999
}

test/test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ describe('linkinator action', () => {
125125
.head('/fake').reply(500);
126126
await action();
127127
assert.ok(inputStub.called);
128-
assert.ok(setOutputStub.calledOnce);
129-
assert.ok(setFailedStub.calledOnce);
128+
assert.strictEqual(setOutputStub.callCount, 1);
129+
assert.strictEqual(setFailedStub.callCount, 1);
130130

131131
// ensure `Scanning ...` is always shown
132132
assert.strictEqual(infoStub.getCalls().filter(x => {
@@ -135,11 +135,11 @@ describe('linkinator action', () => {
135135

136136
// Ensure total count is always shown
137137
assert.strictEqual(setFailedStub.getCalls().filter(x => {
138-
return x.args[0] === 'Detected 1 broken links.';
138+
return x.args[0] === 'Detected 1 broken links.\n test/fixtures/test.md\n [500] http://fake.local/fake';
139139
}).length, 1);
140140

141141
// Ensure `core.error` is called for each failure
142-
assert.ok(errorStub.calledOnce);
142+
assert.strictEqual(errorStub.callCount, 1);
143143
const expected = '[500] http://fake.local/fake';
144144
assert.strictEqual(errorStub.getCalls()[0].args[0], expected);
145145

@@ -159,7 +159,7 @@ describe('linkinator action', () => {
159159
const scope = nock('http://fake.local').head('/').reply(200);
160160
await action();
161161
assert.ok(inputStub.called);
162-
assert.ok(setOutputStub.calledOnce);
162+
assert.strictEqual(setOutputStub.callCount, 1);
163163
assert.ok(setFailedStub.notCalled);
164164
assert.ok(errorStub.notCalled);
165165
assert.strictEqual(infoStub.getCalls().length, 5);
@@ -183,9 +183,9 @@ describe('linkinator action', () => {
183183
await action();
184184
assert.ok(inputStub.called);
185185
assert.ok(infoStub.called);
186-
assert.ok(setOutputStub.calledOnce);
187-
assert.ok(setFailedStub.calledOnce);
188-
assert.ok(errorStub.calledOnce);
186+
assert.strictEqual(setOutputStub.callCount, 1);
187+
assert.strictEqual(setFailedStub.callCount, 1);
188+
assert.strictEqual(errorStub.callCount, 1);
189189
const expected = /No match for request/;
190190
assert.ok(infoStub.getCalls().find(x => expected.test(x.args[0])));
191191
scope.done();

0 commit comments

Comments
 (0)