Skip to content

Commit

Permalink
feat(report): add 404 report (#54)
Browse files Browse the repository at this point in the history
* feat(report): handle 404.json

* fix

* fix

* feat(report): add 404

* fix: tests

* fix 404 summary

* fix: add 404 info to intro + wordings
  • Loading branch information
Julien Bouquillon authored Sep 6, 2021
1 parent d951937 commit 984bc0a
Show file tree
Hide file tree
Showing 20 changed files with 4,412 additions and 877 deletions.
7 changes: 7 additions & 0 deletions report/src/__snapshots__/generateUrlReport.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

exports[`generateUrlReport should allow empty/invalid reports 1`] = `
Object {
"404": null,
"codescan": Object {
"report": "codescanalerts.json",
"totalCount": 42,
Expand Down Expand Up @@ -30,6 +31,11 @@ Object {

exports[`generateUrlReport should generate latest report for a valid url 1`] = `
Object {
"404": Array [
1,
2,
3,
],
"codescan": Object {
"report": "codescanalerts.json",
"totalCount": 42,
Expand Down Expand Up @@ -61,6 +67,7 @@ Object {
"report": "stats.json",
},
"summary": Object {
"404": 3,
"codescanCount": 42,
"codescanGrade": undefined,
},
Expand Down
9 changes: 8 additions & 1 deletion report/src/generateUrlReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ const lhrCleanup = (result) => {
};
};

/**
* Minify wget spider report
*/
const wget404Cleanup = (result) => result && result.broken


//@ts-expect-error
const requireToolData = (filename) => (basePath) =>
requireJson(path.join(basePath, filename));
Expand All @@ -128,7 +134,8 @@ const tools = {
/** @param {string} basePath scan directory */
data: (basePath) => fs.existsSync(path.join(basePath, "screenshot.jpeg")),
},
stats: { data: requireToolData("stats.json") }
stats: { data: requireToolData("stats.json") },
404: { data: requireToolData("404.json"), cleanup: wget404Cleanup },
};

//@ts-expect-error
Expand Down
2 changes: 2 additions & 0 deletions report/src/generateUrlReport.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ describe("generateUrlReport", () => {
mockJson("wappalyzer.json", {report: "wappalyzer.json"});
mockJson("zap.json", {report: "zap.json"});
mockJson("stats.json", {report: "stats.json"});
mockJson("404.json", {broken: [1, 2, 3]});

expect(
generateUrlReport({
Expand All @@ -77,6 +78,7 @@ describe("generateUrlReport", () => {
unMockJson("wappalyzer.json");
unMockJson("zap.json");
unMockJson("stats.json");
unMockJson("404.json");
});
test(`should allow empty/invalid reports`, () => {
fs.existsSync.mockImplementationOnce(() => true); // check url folder
Expand Down
31 changes: 31 additions & 0 deletions report/src/summary/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`should compute summary for some URL report 1`] = `
Object {
"404": 5,
"apdex": 1,
"apdexGrade": "A",
"codescanCount": 0,
"codescanGrade": "A",
"cookiesCount": 2,
"cookiesGrade": "B",
"dependabotCount": 4,
"dependabotGrade": "D",
"httpGrade": "A+",
"lighthouse_accessibility": 0.96,
"lighthouse_accessibilityGrade": "A",
"lighthouse_best-practices": 0.93,
"lighthouse_best-practicesGrade": "A",
"lighthouse_performance": 0.45,
"lighthouse_performanceGrade": "D",
"lighthouse_pwa": 0.42,
"lighthouse_pwaGrade": "D",
"lighthouse_seo": 0.9,
"lighthouse_seoGrade": "A",
"testsslGrade": "A+",
"trackersCount": 0,
"trackersGrade": "A",
"uptime": 99.909,
"uptimeGrade": "A",
}
`;
2 changes: 2 additions & 0 deletions report/src/summary/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const tools = {
updownio: (report) => require("./updownio")(report),
/** @param {StatsReport} report */
stats: (report) => require("./stats")(report),
/** @param {Error404Report} report */
404: report => report && report.length && ({ 404: report.length })
};

/**
Expand Down
Loading

0 comments on commit 984bc0a

Please sign in to comment.