-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gatsby,gatsby-cli): Slice HTML rendering error handling (#36822)
- Loading branch information
Showing
9 changed files
with
140 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
packages/gatsby/src/utils/__tests__/extract-undefined-global.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { extractUndefinedGlobal } from "../extract-undefined-global" | ||
|
||
const globals = [ | ||
`window`, | ||
`document`, | ||
`localStorage`, | ||
`navigator`, | ||
`alert`, | ||
`location`, | ||
] | ||
|
||
it.each(globals)(`extracts %s`, global => { | ||
const extractedGlobal = extractUndefinedGlobal( | ||
new ReferenceError(`${global} is not defined`) | ||
) | ||
|
||
expect(extractedGlobal).toEqual(global) | ||
}) | ||
|
||
it(`returns an empty string if no known global found`, () => { | ||
const extractedGlobal = extractUndefinedGlobal( | ||
new ReferenceError(`foo is not defined`) | ||
) | ||
|
||
expect(extractedGlobal).toEqual(``) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* Extract undefined global variables used in server context from a reference error. | ||
*/ | ||
export function extractUndefinedGlobal(error: ReferenceError): string { | ||
const match = error.message.match( | ||
/(window|document|localStorage|navigator|alert|location) is not defined/i | ||
) | ||
|
||
if (match && match[1]) { | ||
return match[1] | ||
} | ||
|
||
return `` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters