Skip to content

Commit 634c8b6

Browse files
committed
Try normalizing TZ across environments instead of changing the previewed string
1 parent 21c899f commit 634c8b6

File tree

3 files changed

+10
-14
lines changed

3 files changed

+10
-14
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
'}'

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)