From ff6add01d1869d823e6638a3fc23ab60114aff95 Mon Sep 17 00:00:00 2001 From: Dannon Baker Date: Mon, 9 Dec 2024 14:26:04 -0500 Subject: [PATCH] Use timezone-mock for handling test timezones in jest --- client/package.json | 1 + client/src/utils/dates.test.ts | 6 ++++-- client/yarn.lock | 5 +++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/client/package.json b/client/package.json index de12b9f71852..a5ccfd526d6f 100644 --- a/client/package.json +++ b/client/package.json @@ -200,6 +200,7 @@ "sass-loader": "^13.3.2", "store": "^2.0.12", "style-loader": "^3.3.3", + "timezone-mock": "^1.3.6", "ts-jest": "^29.2.3", "ts-loader": "^9.5.0", "tsconfig-paths-webpack-plugin": "^4.1.0", diff --git a/client/src/utils/dates.test.ts b/client/src/utils/dates.test.ts index 2792bea0efec..9a1c690929f3 100644 --- a/client/src/utils/dates.test.ts +++ b/client/src/utils/dates.test.ts @@ -1,12 +1,14 @@ +import MockDate from "timezone-mock"; + import { formatGalaxyPrettyDateString, galaxyTimeToDate, localizeUTCPretty } from "./dates"; describe("dates.ts", () => { beforeEach(() => { - process.env.TZ = "America/New_York"; + MockDate.register("Etc/GMT+4"); }); afterEach(() => { - delete process.env.TZ; + MockDate.unregister(); }); describe("galaxyTimeToDate", () => { diff --git a/client/yarn.lock b/client/yarn.lock index cd6c4bf5f55a..25b9a38cd7be 100644 --- a/client/yarn.lock +++ b/client/yarn.lock @@ -11381,6 +11381,11 @@ timers-browserify@^2.0.12: dependencies: setimmediate "^1.0.4" +timezone-mock@^1.3.6: + version "1.3.6" + resolved "https://registry.yarnpkg.com/timezone-mock/-/timezone-mock-1.3.6.tgz#44e4c5aeb57e6c07ae630a05c528fc4d9aab86f4" + integrity sha512-YcloWmZfLD9Li5m2VcobkCDNVaLMx8ohAb/97l/wYS3m+0TIEK5PFNMZZfRcusc6sFjIfxu8qcJT0CNnOdpqmg== + tmpl@1.0.5: version "1.0.5" resolved "https://registry.npmjs.org/tmpl/-/tmpl-1.0.5.tgz"