Skip to content

Commit

Permalink
Mock Date.now (#1894)
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleAMathews authored Aug 23, 2017
1 parent 9d2774c commit 60d25bc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
14 changes: 7 additions & 7 deletions packages/gatsby/src/redux/__tests__/__snapshots__/pages.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Array [
"path": "/hi/",
"pluginCreatorId": "test",
"pluginCreator___NODE": "test",
"updatedAt": "2017-08-23T02:25:12.551Z",
"updatedAt": 1482363367071,
},
Object {
"component": "/whatever/index.js",
Expand All @@ -22,7 +22,7 @@ Array [
"path": "/hi/pizza/",
"pluginCreatorId": "test",
"pluginCreator___NODE": "test",
"updatedAt": "2017-08-23T02:25:12.552Z",
"updatedAt": 1482363367071,
},
]
`;
Expand All @@ -38,7 +38,7 @@ Object {
"path": "/hi/",
"pluginCreatorId": "test",
"pluginCreator___NODE": "test",
"updatedAt": "2017-08-23T02:25:12.519Z",
"updatedAt": 1482363367071,
},
"plugin": Object {
"id": "test",
Expand All @@ -60,7 +60,7 @@ Array [
"path": "/hi/",
"pluginCreatorId": "test",
"pluginCreator___NODE": "test",
"updatedAt": "2017-08-23T02:25:12.519Z",
"updatedAt": 1482363367071,
},
]
`;
Expand All @@ -78,7 +78,7 @@ Object {
"path": "/hi/",
"pluginCreatorId": "test",
"pluginCreator___NODE": "test",
"updatedAt": "2017-08-23T02:25:12.546Z",
"updatedAt": 1482363367071,
},
"plugin": Object {
"id": "test",
Expand All @@ -102,7 +102,7 @@ Array [
"path": "/hi/",
"pluginCreatorId": "test",
"pluginCreator___NODE": "test",
"updatedAt": "2017-08-23T02:25:12.546Z",
"updatedAt": 1482363367071,
},
]
`;
Expand All @@ -120,7 +120,7 @@ Array [
"path": "/hi/",
"pluginCreatorId": "test",
"pluginCreator___NODE": "test",
"updatedAt": "2017-08-23T02:25:12.557Z",
"updatedAt": 1482363367071,
},
]
`;
6 changes: 6 additions & 0 deletions packages/gatsby/src/redux/__tests__/pages.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
const reducer = require(`../reducers/pages`)
const { actions } = require(`../actions`)

const start = Date.now()
Date.now = jest.fn(() => {
// const diff = new Date().getTime() - start
return 1482363367071 // + diff
})

describe(`Add pages`, () => {
it(`allows you to add pages`, () => {
const action = actions.createPage(
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/redux/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ actions.createPage = (page, plugin = ``, traceId) => {

page.jsonName = jsonName
page.internalComponentName = internalComponentName
page.updatedAt = new Date().toJSON()
page.updatedAt = Date.now()

// Ensure the page has a context object
if (!page.context) {
Expand Down

0 comments on commit 60d25bc

Please sign in to comment.