-
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.
fix(gatsby): Load resources in ProdPageRenderer (#26092)
* Load resources in ProdPageRenderer * Add simple unit tests
- Loading branch information
1 parent
47ba295
commit 1b0f7a9
Showing
3 changed files
with
83 additions
and
1 deletion.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
packages/gatsby/cache-dir/__tests__/public-page-renderer-dev.tsx
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,42 @@ | ||
import React from "react" | ||
import { render, cleanup } from "@testing-library/react" | ||
|
||
jest.mock(`../loader`, () => { | ||
return { | ||
loadPageSync: jest.fn((path: string): { | ||
loadPageSync: boolean | ||
path: string | ||
} => { | ||
return { loadPageSync: true, path } | ||
}), | ||
loadPage: function loadPage( | ||
path: string | ||
): Promise<{ loadPage: boolean; path: string }> { | ||
return Promise.resolve({ loadPage: true, path }) | ||
}, | ||
} | ||
}) | ||
|
||
jest.mock(`../query-result-store`, () => { | ||
return { | ||
PageQueryStore: (): string => `PageQueryStore`, | ||
} | ||
}) | ||
|
||
import DevPageRenderer from "../public-page-renderer-dev" | ||
import loader from "../loader" | ||
|
||
describe(`DevPageRenderer`, () => { | ||
it(`loads pages synchronously`, () => { | ||
const location = { | ||
pathname: `/`, | ||
} | ||
render(<DevPageRenderer location={location} />) | ||
|
||
expect(loader.loadPageSync).toHaveBeenCalled() | ||
}) | ||
}) | ||
|
||
afterAll(cleanup) | ||
|
||
afterAll(jest.clearAllMocks) |
38 changes: 38 additions & 0 deletions
38
packages/gatsby/cache-dir/__tests__/public-page-renderer-prod.tsx
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,38 @@ | ||
import React from "react" | ||
import { render, cleanup } from "@testing-library/react" | ||
|
||
jest.mock(`../loader`, () => { | ||
return { | ||
loadPageSync: jest.fn((path: string): { | ||
loadPageSync: boolean | ||
path: string | ||
} => { | ||
return { loadPageSync: true, path } | ||
}), | ||
loadPage: function loadPage( | ||
path: string | ||
): Promise<{ loadPage: boolean; path: string }> { | ||
return Promise.resolve({ loadPage: true, path }) | ||
}, | ||
} | ||
}) | ||
|
||
jest.mock(`../page-renderer`, (): string => `InternalPageRenderer`) | ||
|
||
import ProdPageRenderer from "../public-page-renderer-prod" | ||
import loader from "../loader" | ||
|
||
describe(`ProdPageRenderer`, () => { | ||
it(`loads pages synchronously`, () => { | ||
const location = { | ||
pathname: `/`, | ||
} | ||
render(<ProdPageRenderer location={location} />) | ||
|
||
expect(loader.loadPageSync).toHaveBeenCalled() | ||
}) | ||
}) | ||
|
||
afterAll(cleanup) | ||
|
||
afterAll(jest.clearAllMocks) |
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