diff --git a/packages/react-devtools-shared/src/__tests__/dehydratedValueSerializer.js b/packages/react-devtools-shared/src/__tests__/dehydratedValueSerializer.js index d8eac57df035c..4d86a78a35145 100644 --- a/packages/react-devtools-shared/src/__tests__/dehydratedValueSerializer.js +++ b/packages/react-devtools-shared/src/__tests__/dehydratedValueSerializer.js @@ -18,6 +18,18 @@ export function test(maybeDehydratedValue) { ); } +function serializeDehydratedValuePreview(preview) { + const date = new Date(preview); + const isDatePreview = !Number.isNaN(date.valueOf()); + if (isDatePreview) { + // The preview is just `String(date)` which formats the date in the local timezone. + // This results in a snapshot mismatch between tests run in e.g. GMT and ET + // WARNING: This does not guard against dates created with the default timezone i.e. the local timezone e.g. new Date('05 October 2011 14:48'). + return date.toISOString(); + } + return preview; +} + // print() is part of Jest's serializer API export function print(dehydratedValue, serialize, indent) { const {meta} = require('react-devtools-shared/src/hydration'); @@ -27,11 +39,11 @@ export function print(dehydratedValue, serialize, indent) { 'Dehydrated {\n' + paddingLeft + ' "preview_short": ' + - dehydratedValue[meta.preview_short] + + serializeDehydratedValuePreview(dehydratedValue[meta.preview_short]) + ',\n' + paddingLeft + ' "preview_long": ' + - dehydratedValue[meta.preview_long] + + serializeDehydratedValuePreview(dehydratedValue[meta.preview_long]) + ',\n' + paddingLeft + '}' diff --git a/packages/react-devtools-shared/src/__tests__/legacy/inspectElement-test.js b/packages/react-devtools-shared/src/__tests__/legacy/inspectElement-test.js index df168b03ac91e..7f5d254053405 100644 --- a/packages/react-devtools-shared/src/__tests__/legacy/inspectElement-test.js +++ b/packages/react-devtools-shared/src/__tests__/legacy/inspectElement-test.js @@ -241,8 +241,8 @@ describe('InspectedElementContext', () => { "preview_long": DataView(3), }, "date": Dehydrated { - "preview_short": Thu Jan 01 1970 01:00:00 GMT+0100 (Central European Standard Time), - "preview_long": Thu Jan 01 1970 01:00:00 GMT+0100 (Central European Standard Time), + "preview_short": 1970-01-01T00:00:00.000Z, + "preview_long": 1970-01-01T00:00:00.000Z, }, "fn": Dehydrated { "preview_short": ƒ exampleFunction() {},