From 1a3f7ddd02bfd9a2d97cdc86fcdd2f9dd3ee7d9a Mon Sep 17 00:00:00 2001 From: Alex Andreev Date: Tue, 31 May 2022 10:38:05 +0300 Subject: [PATCH] Setting global UTC timezone for tests Signed-off-by: Alex Andreev --- package.json | 3 ++- src/common/__tests__/timezones.test.ts | 12 ++++++++++++ src/jest.timezone.ts | 11 +++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/common/__tests__/timezones.test.ts create mode 100644 src/jest.timezone.ts diff --git a/package.json b/package.json index a2b4408cfe..0521858a95 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,8 @@ "ts-jest": { "isolatedModules": true } - } + }, + "globalSetup": "/src/jest.timezone.ts" }, "build": { "generateUpdatesFilesForAllChannels": true, diff --git a/src/common/__tests__/timezones.test.ts b/src/common/__tests__/timezones.test.ts new file mode 100644 index 0000000000..6d66803a04 --- /dev/null +++ b/src/common/__tests__/timezones.test.ts @@ -0,0 +1,12 @@ +/** + * Copyright (c) OpenLens Authors. All rights reserved. + * Licensed under MIT License. See LICENSE in root directory for more information. + */ + +describe("Timezones", () => { + it("should always be UTC", () => { + expect(new Date().getTimezoneOffset()).toBe(0); + }); +}); + +export {}; \ No newline at end of file diff --git a/src/jest.timezone.ts b/src/jest.timezone.ts new file mode 100644 index 0000000000..3aa7fef0c0 --- /dev/null +++ b/src/jest.timezone.ts @@ -0,0 +1,11 @@ +/** + * Copyright (c) OpenLens Authors. All rights reserved. + * Licensed under MIT License. See LICENSE in root directory for more information. + */ + +// Setting the timezone to UTC to ensure same timezone for CI and local environments +module.exports = async () => { + process.env.TZ = "UTC"; +}; + +export {}; \ No newline at end of file