@@ -6,6 +6,7 @@ const { curly } = require("node-libcurl")
66const promiseRetry = require ( "promise-retry" )
77const fs = require ( "fs/promises" )
88const config = require ( "../gatsby-config.js" )
9+ const pendingRetries = require ( "../.cache/page-ssr/routes/render-page" )
910const { port } = require ( "../jest-puppeteer.config" ) . server
1011
1112const pathPrefix = process . env . PATH_PREFIX || ""
@@ -20,6 +21,7 @@ describe("site external links", () => {
2021 await fs . rm ( resultsFile , { force : true } )
2122
2223 const path = `http://localhost:${ port } /${ pathPrefix } `
24+ const pendingRetries = [ ]
2325
2426 // create a new `LinkChecker` that we'll use to run the scan.
2527 const checker = new link . LinkChecker ( )
@@ -35,11 +37,13 @@ describe("site external links", () => {
3537 if ( result . url . includes ( "twitter" ) ) {
3638 // Twitter gives 404s, I think if it feels bombarded, so let's try a retry
3739 retryWorked = await retryUrl ( result . url )
40+ pendingRetries . push ( retryWorked )
3841 }
3942
4043 if ( result . status === status . TOO_MANY_REQUESTS ) {
4144 // Twitter gives 404s, I think if it feels bombarded, so let's try a retry
4245 retryWorked = await retryUrl ( result . url )
46+ pendingRetries . push ( retryWorked )
4347 }
4448
4549 // Some APIs give 429s but no retry-after header, and linkinator will not retry in that case
@@ -67,9 +71,10 @@ describe("site external links", () => {
6771 // Also write out to a file - the a+ flag will create it if it doesn't exist
6872 const content = JSON . stringify ( { url : result . url , owningPage : result . parent } ) + "\n"
6973
70- await fs . writeFile ( resultsFile , content , { flag : "a+" } , err => {
74+ const write = await fs . writeFile ( resultsFile , content , { flag : "a+" } , err => {
7175 console . warn ( "Error writing results:" , err )
7276 } )
77+ pendingRetries . push ( write )
7378 }
7479 }
7580 }
@@ -84,7 +89,7 @@ describe("site external links", () => {
8489 ]
8590
8691 // Go ahead and start the scan! As events occur, we will see them above.
87- return await checker . check ( {
92+ return checker . check ( {
8893 path,
8994 recurse : true ,
9095 linksToSkip,
@@ -101,6 +106,7 @@ describe("site external links", () => {
101106 retryErrorsCount : 12 ,
102107 retryErrorsJitter : 8000 , // Default is 3000
103108 } )
109+ . then ( ( ) => Promise . all ( pendingRetries ) )
104110 } )
105111
106112
0 commit comments