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

feat(gatsby): add DANGEROUSLY_DISABLE_OOM #13066

Merged
merged 12 commits into from
Apr 4, 2019
46 changes: 46 additions & 0 deletions packages/gatsby/src/redux/__tests__/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const path = require(`path`)
const fs = require(`fs-extra`)
const { saveState, store } = require(`../index`)
const {
actions: { createPage },
} = require(`../actions`)

jest.mock(`fs-extra`)

describe(`redux db`, () => {
beforeEach(() => {
store.dispatch(
createPage(
{
path: `/my-sweet-new-page/`,
component: path.resolve(`./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` }
)
)

fs.writeFile.mockClear()
})
it(`should write cache to disk`, async () => {
await saveState()

expect(fs.writeFile).toBeCalledWith(
expect.stringContaining(`.cache/redux-state.json`),
expect.stringContaining(`my-sweet-new-page.js`)
)
})

it(`shoudn't write cache to disk when DANGEROUSLY_DISABLE_OOM is set`, async () => {
process.env.DANGEROUSLY_DISABLE_OOM = `1`

await saveState()

expect(fs.writeFile).not.toBeCalled()
delete process.env.DANGEROUSLY_DISABLE_OOM
})
})
4 changes: 4 additions & 0 deletions packages/gatsby/src/redux/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ const store = Redux.createStore(

// Persist state.
function saveState() {
if (process.env.DANGEROUSLY_DISABLE_OOM) {
return Promise.resolve()
}

const state = store.getState()
const pickedState = _.pick(state, [
`nodes`,
Expand Down