File tree Expand file tree Collapse file tree 3 files changed +43
-1
lines changed
packages/gatsby/cache-dir Expand file tree Collapse file tree 3 files changed +43
-1
lines changed Original file line number Diff line number Diff line change
1
+ import React from "react"
2
+ import EnsureResources from "../ensure-resources"
3
+ import { render , getNodeText , cleanup } from "@testing-library/react"
4
+
5
+ jest . mock ( `../loader` , ( ) => {
6
+ return {
7
+ loadPageSync ( path : string ) : { loadPageSync : boolean ; path : string } {
8
+ return { loadPageSync : true , path }
9
+ } ,
10
+ loadPage ( path : string ) : Promise < { loadPage : boolean ; path : string } > {
11
+ return Promise . resolve ( { loadPage : true , path } )
12
+ } ,
13
+ }
14
+ } )
15
+
16
+ afterAll ( cleanup )
17
+
18
+ describe ( `EnsureResources` , ( ) => {
19
+ it ( `loads pages synchronously` , ( ) => {
20
+ const location = {
21
+ pathname : `/` ,
22
+ }
23
+ const { container } = render (
24
+ < EnsureResources location = { location } >
25
+ { ( data : any ) : string => JSON . stringify ( data . pageResources ) }
26
+ </ EnsureResources >
27
+ )
28
+
29
+ expect ( getNodeText ( container ) ) . toMatchInlineSnapshot (
30
+ `"{\\"loadPageSync\\":true,\\"path\\":\\"/\\"}"`
31
+ )
32
+ } )
33
+ } )
Original file line number Diff line number Diff line change @@ -74,6 +74,14 @@ class EnsureResources extends React.Component {
74
74
}
75
75
76
76
render ( ) {
77
+ if ( process . env . NODE_ENV !== `production` && ! this . state . pageResources ) {
78
+ throw new Error (
79
+ `EnsureResources was not able to find resources for path: "${ this . props . location . pathname } "
80
+ This typically means that an issue occurred building components for that path.
81
+ Run \`gatsby clean\` to remove any cached elements.`
82
+ )
83
+ }
84
+
77
85
return this . props . children ( this . state )
78
86
}
79
87
}
Original file line number Diff line number Diff line change 12
12
"strictPropertyInitialization" : true ,
13
13
"noFallthroughCasesInSwitch" : true ,
14
14
"resolveJsonModule" : true ,
15
- "esModuleInterop" : true
15
+ "esModuleInterop" : true ,
16
+ "jsx" : " preserve"
16
17
},
17
18
"exclude" : [" peril/*" , " examples/*" ]
18
19
}
You can’t perform that action at this time.
0 commit comments