Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gatsby): Load resources in ProdPageRenderer #26092

Merged
merged 2 commits into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions packages/gatsby/cache-dir/__tests__/public-page-renderer-dev.tsx
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 packages/gatsby/cache-dir/__tests__/public-page-renderer-prod.tsx
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)
4 changes: 3 additions & 1 deletion packages/gatsby/cache-dir/public-page-renderer-prod.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React from "react"
import PropTypes from "prop-types"

import loader from "./loader"
import InternalPageRenderer from "./page-renderer"

const ProdPageRenderer = ({ location, pageResources }) => {
const ProdPageRenderer = ({ location }) => {
pieh marked this conversation as resolved.
Show resolved Hide resolved
const pageResources = loader.loadPageSync(location.pathname)
if (!pageResources) {
return null
}
Expand Down