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 688431d commit bb557cd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 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 @@ -34,6 +34,8 @@ describe('InspectedElement', () => {

let testRendererInstance;

let originalTimezone;

beforeEach(() => {
utils = require('./utils');
utils.beforeEachProfiling();
Expand Down Expand Up @@ -65,10 +67,16 @@ describe('InspectedElement', () => {
testRendererInstance = TestRenderer.create(null, {
unstable_isConcurrent: true,
});

originalTimezone = process.env.TZ;
// Ensure that `String(new Date())` is equal in CI and locally
process.env.TZ = 'UTC';
});

afterEach(() => {
jest.restoreAllMocks();

process.env.TZ = originalTimezone;
});

const Contexts = ({
Expand Down

0 comments on commit bb557cd

Please sign in to comment.