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): persist pages between runs #28590

Merged
merged 12 commits into from
Apr 22, 2021
Prev Previous commit
Next Next commit
refactor persistance tests a bit to allow for creating different page…
…s per test scenario
  • Loading branch information
pieh committed Apr 13, 2021
commit 3be8d734d99293b9e7ce568080787e511cb8738c
33 changes: 20 additions & 13 deletions packages/gatsby/src/redux/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,36 +93,43 @@ function getFakeNodes() {
describe(`redux db`, () => {
const initialComponentsState = _.cloneDeep(store.getState().components)

beforeEach(() => {
function createPages(pages) {
// mock Date.now so Date.now() doesn't change in between tests
const RealDateNow = Date.now
let DateNowCallCount = 0
// simulate passage of time by increasing call counter (instead of actual time value)
Date.now = jest.fn(() => ++DateNowCallCount)

store.dispatch(
createPage(
{
path: `/my-sweet-new-page/`,
// seems like jest serializer doesn't play nice with Maps on Windows
component: `/Users/username/dev/site/src/templates/my-sweet-new-page.js`,
// The context is passed as props to the component as well
// as into the component's GraphQL query.
context: {
id: `123456`,
},
},
{ name: `default-site-plugin` }
(Array.isArray(pages) ? pages : [pages]).map(page =>
createPage(page, {
name: `default-site-plugin`,
})
)
)

Date.now = RealDateNow
}

const defaultPage = {
path: `/my-sweet-new-page/`,
// seems like jest serializer doesn't play nice with Maps on Windows
component: `/Users/username/dev/site/src/templates/my-sweet-new-page.js`,
// The context is passed as props to the component as well
// as into the component's GraphQL query.
context: {
id: `123456`,
},
}

beforeEach(() => {
writeToCache.mockClear()
mockWrittenContent.clear()
})

it(`should write redux cache to disk`, async () => {
createPages(defaultPage)

expect(initialComponentsState).toEqual(new Map())

store.getState().nodes = getFakeNodes()
Expand Down