Skip to content

Commit

Permalink
Try normalizing TZ across environments instead of changing the previe…
Browse files Browse the repository at this point in the history
…wed string
  • Loading branch information
eps1lon committed Apr 8, 2021
1 parent 9c0650b commit ee699c0
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,6 @@ 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');
Expand All @@ -43,11 +31,11 @@ export function print(dehydratedValue, serialize, indent) {
'Dehydrated {\n' +
paddingLeft +
' "preview_short": ' +
serializeDehydratedValuePreview(dehydratedValue[meta.preview_short]) +
dehydratedValue[meta.preview_short] +
',\n' +
paddingLeft +
' "preview_long": ' +
serializeDehydratedValuePreview(dehydratedValue[meta.preview_long]) +
dehydratedValue[meta.preview_long] +
',\n' +
paddingLeft +
'}'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,8 +568,8 @@ describe('InspectedElement', () => {
"preview_long": DataView(3),
},
"date": Dehydrated {
"preview_short": 2019-12-31T23:42:42.000Z,
"preview_long": 2019-12-31T23:42:42.000Z,
"preview_short": Tue Dec 31 2019 23:42:42 GMT+0000 (Coordinated Universal Time),
"preview_long": Tue Dec 31 2019 23:42:42 GMT+0000 (Coordinated Universal Time),
},
"fn": Dehydrated {
"preview_short": ƒ exampleFunction() {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ describe('InspectedElementContext', () => {
"preview_long": DataView(3),
},
"date": Dehydrated {
"preview_short": 1970-01-01T00:00:00.000Z,
"preview_long": 1970-01-01T00:00:00.000Z,
"preview_short": Thu Jan 01 1970 00:00:00 GMT+0000 (Coordinated Universal Time),
"preview_long": Thu Jan 01 1970 00:00:00 GMT+0000 (Coordinated Universal Time),
},
"fn": Dehydrated {
"preview_short": ƒ exampleFunction() {},
Expand Down
1 change: 1 addition & 0 deletions scripts/jest/config.base.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

module.exports = {
globalSetup: require.resolve('./setupGlobal.js'),
haste: {
hasteImplModulePath: require.resolve('./noHaste.js'),
},
Expand Down
7 changes: 7 additions & 0 deletions scripts/jest/setupGlobal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* eslint-disable */

module.exports = () => {
// can use beforeEach/afterEach or setupEnvironment.js in node >= 13: https://github.com/nodejs/node/pull/20026
// jest's `setupFiles` is too late: https://stackoverflow.com/a/56482581/3406963
process.env.TZ = 'UTC';
};

0 comments on commit ee699c0

Please sign in to comment.