Skip to content

Commit 6b254ef

Browse files
committed
Fix date mismatch
1 parent 3a2a018 commit 6b254ef

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

packages/react-devtools-shared/src/__tests__/dehydratedValueSerializer.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ export function test(maybeDehydratedValue) {
2222
);
2323
}
2424

25+
function serializeDehydratedValuePreview(preview) {
26+
const date = new Date(preview);
27+
const isDatePreview = !Number.isNaN(date.valueOf());
28+
if (isDatePreview) {
29+
// The preview is just `String(date)` which formats the date in the local timezone.
30+
// This results in a snapshot mismatch between tests run in e.g. GMT and ET
31+
// 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').
32+
return date.toISOString();
33+
}
34+
return preview;
35+
}
36+
2537
// print() is part of Jest's serializer API
2638
export function print(dehydratedValue, serialize, indent) {
2739
const {meta} = require('react-devtools-shared/src/hydration');
@@ -31,11 +43,11 @@ export function print(dehydratedValue, serialize, indent) {
3143
'Dehydrated {\n' +
3244
paddingLeft +
3345
' "preview_short": ' +
34-
dehydratedValue[meta.preview_short] +
46+
serializeDehydratedValuePreview(dehydratedValue[meta.preview_short]) +
3547
',\n' +
3648
paddingLeft +
3749
' "preview_long": ' +
38-
dehydratedValue[meta.preview_long] +
50+
serializeDehydratedValuePreview(dehydratedValue[meta.preview_long]) +
3951
',\n' +
4052
paddingLeft +
4153
'}'

packages/react-devtools-shared/src/__tests__/inspectedElement-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,8 @@ describe('InspectedElement', () => {
568568
"preview_long": DataView(3),
569569
},
570570
"date": Dehydrated {
571-
"preview_short": Wed Jan 01 2020 00:42:42 GMT+0100 (Central European Standard Time),
572-
"preview_long": Wed Jan 01 2020 00:42:42 GMT+0100 (Central European Standard Time),
571+
"preview_short": 2019-12-31T23:42:42.000Z,
572+
"preview_long": 2019-12-31T23:42:42.000Z,
573573
},
574574
"fn": Dehydrated {
575575
"preview_short": ƒ exampleFunction() {},

packages/react-devtools-shared/src/__tests__/legacy/inspectElement-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ describe('InspectedElementContext', () => {
236236
"preview_long": DataView(3),
237237
},
238238
"date": Dehydrated {
239-
"preview_short": Thu Jan 01 1970 01:00:00 GMT+0100 (Central European Standard Time),
240-
"preview_long": Thu Jan 01 1970 01:00:00 GMT+0100 (Central European Standard Time),
239+
"preview_short": 1970-01-01T00:00:00.000Z,
240+
"preview_long": 1970-01-01T00:00:00.000Z,
241241
},
242242
"fn": Dehydrated {
243243
"preview_short": ƒ exampleFunction() {},

0 commit comments

Comments
 (0)