Skip to content

Commit ee699c0

Browse files
committed
Try normalizing TZ across environments instead of changing the previewed string
1 parent 9c0650b commit ee699c0

File tree

5 files changed

+14
-18
lines changed

5 files changed

+14
-18
lines changed

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

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,6 @@ 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-
3725
// print() is part of Jest's serializer API
3826
export function print(dehydratedValue, serialize, indent) {
3927
const {meta} = require('react-devtools-shared/src/hydration');
@@ -43,11 +31,11 @@ export function print(dehydratedValue, serialize, indent) {
4331
'Dehydrated {\n' +
4432
paddingLeft +
4533
' "preview_short": ' +
46-
serializeDehydratedValuePreview(dehydratedValue[meta.preview_short]) +
34+
dehydratedValue[meta.preview_short] +
4735
',\n' +
4836
paddingLeft +
4937
' "preview_long": ' +
50-
serializeDehydratedValuePreview(dehydratedValue[meta.preview_long]) +
38+
dehydratedValue[meta.preview_long] +
5139
',\n' +
5240
paddingLeft +
5341
'}'

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": 2019-12-31T23:42:42.000Z,
572-
"preview_long": 2019-12-31T23:42:42.000Z,
571+
"preview_short": Tue Dec 31 2019 23:42:42 GMT+0000 (Coordinated Universal Time),
572+
"preview_long": Tue Dec 31 2019 23:42:42 GMT+0000 (Coordinated Universal Time),
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": 1970-01-01T00:00:00.000Z,
240-
"preview_long": 1970-01-01T00:00:00.000Z,
239+
"preview_short": Thu Jan 01 1970 00:00:00 GMT+0000 (Coordinated Universal Time),
240+
"preview_long": Thu Jan 01 1970 00:00:00 GMT+0000 (Coordinated Universal Time),
241241
},
242242
"fn": Dehydrated {
243243
"preview_short": ƒ exampleFunction() {},

scripts/jest/config.base.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
module.exports = {
4+
globalSetup: require.resolve('./setupGlobal.js'),
45
haste: {
56
hasteImplModulePath: require.resolve('./noHaste.js'),
67
},

scripts/jest/setupGlobal.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* eslint-disable */
2+
3+
module.exports = () => {
4+
// can use beforeEach/afterEach or setupEnvironment.js in node >= 13: https://github.com/nodejs/node/pull/20026
5+
// jest's `setupFiles` is too late: https://stackoverflow.com/a/56482581/3406963
6+
process.env.TZ = 'UTC';
7+
};

0 commit comments

Comments
 (0)