Skip to content

Scheduling infrastructure for absolutely everyone.

test: Remove mockdate and replate with vitest system time (#9750)

sean-brydon0b704b9ed4b5
diff --git a/apps/web/package.json b/apps/web/package.json
index 2ffb44d66ee..6387efec752 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -162,7 +162,6 @@
"copy-webpack-plugin": "^11.0.0",
"detect-port": "^1.3.0",
"env-cmd": "^10.1.0",
- "mockdate": "^3.0.5",
"module-alias": "^2.2.2",
"msw": "^0.42.3",
"postcss": "^8.4.18",
diff --git a/apps/web/test/lib/getAggregateWorkingHours.test.ts b/apps/web/test/lib/getAggregateWorkingHours.test.ts
index f7c96ffb6f9..afedcd0e9de 100644
--- a/apps/web/test/lib/getAggregateWorkingHours.test.ts
+++ b/apps/web/test/lib/getAggregateWorkingHours.test.ts
@@ -1,9 +1,11 @@
-import MockDate from "mockdate";
-import { expect, it } from "vitest";
+import { expect, it, beforeAll, vi } from "vitest";
import { getAggregateWorkingHours } from "@calcom/core/getAggregateWorkingHours";
-MockDate.set("2021-06-20T11:59:59Z");
+
+beforeAll(() => {
+ vi.setSystemTime(new Date("2021-06-20T11:59:59Z"));
+})
const HAWAII_AND_NEWYORK_TEAM = [
{
diff --git a/apps/web/test/lib/getAvailabilityFromSchedule.test.ts b/apps/web/test/lib/getAvailabilityFromSchedule.test.ts
index c4a26cc8b2c..8bfcbfad3d3 100644
--- a/apps/web/test/lib/getAvailabilityFromSchedule.test.ts
+++ b/apps/web/test/lib/getAvailabilityFromSchedule.test.ts
@@ -1,11 +1,13 @@
import type { Availability } from "@prisma/client";
-import MockDate from "mockdate";
-import { expect, it } from "vitest";
+import { expect, it, beforeAll, vi } from "vitest";
import dayjs from "@calcom/dayjs";
import { getAvailabilityFromSchedule } from "@calcom/lib/availability";
-MockDate.set("2021-06-20T11:59:59Z");
+
+beforeAll(() => {
+ vi.setSystemTime(new Date("2021-06-20T11:59:59Z"));
+})
//parse "hh:mm-hh:mm" into <Availability> object
const parseWorkingHours = (workingHours: string) => {
diff --git a/apps/web/test/lib/getWorkingHours.test.ts b/apps/web/test/lib/getWorkingHours.test.ts
index 26346aa188b..5d8ca1696fe 100644
--- a/apps/web/test/lib/getWorkingHours.test.ts
+++ b/apps/web/test/lib/getWorkingHours.test.ts
@@ -1,10 +1,11 @@
-import MockDate from "mockdate";
-import { expect, it } from "vitest";
+import { expect, it, vi, beforeAll } from "vitest";
import dayjs from "@calcom/dayjs";
import { getWorkingHours } from "@calcom/lib/availability";
-MockDate.set("2021-06-20T11:59:59Z");
+beforeAll(() => {
+ vi.setSystemTime(new Date("2021-06-20T11:59:59Z"));
+})
it("correctly translates Availability (UTC+0) to UTC workingHours", async () => {
expect(
diff --git a/apps/web/test/lib/slots.test.ts b/apps/web/test/lib/slots.test.ts
index df07104ae98..63834a8cc2e 100644
--- a/apps/web/test/lib/slots.test.ts
+++ b/apps/web/test/lib/slots.test.ts
@@ -1,11 +1,13 @@
-import MockDate from "mockdate";
-import { describe, expect, it } from "vitest";
+import { describe, expect, it, beforeAll, vi } from "vitest";
import dayjs from "@calcom/dayjs";
import { MINUTES_DAY_END, MINUTES_DAY_START } from "@calcom/lib/availability";
import getSlots from "@calcom/lib/slots";
-MockDate.set("2021-06-20T11:59:59Z");
+
+beforeAll(() => {
+ vi.setSystemTime(new Date("2021-06-20T11:59:59Z"));
+})
describe("Tests the slot logic", () => {
it("can fit 24 hourly slots for an empty day", async () => {
diff --git a/packages/features/package.json b/packages/features/package.json
index d2972f7c634..3d83161fc9a 100644
--- a/packages/features/package.json
+++ b/packages/features/package.json
@@ -20,7 +20,6 @@
"zustand": "^4.3.2"
},
"devDependencies": {
- "@testing-library/react-hooks": "^8.0.1",
- "mockdate": "^3.0.5"
+ "@testing-library/react-hooks": "^8.0.1"
}
}
diff --git a/yarn.lock b/yarn.lock
index eafc7dc11eb..1acd30a1211 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -4186,7 +4186,6 @@ __metadata:
dompurify: ^2.4.1
framer-motion: ^10.12.8
lexical: ^0.9.0
- mockdate: ^3.0.5
react-select: ^5.7.0
react-sticky-box: ^2.0.4
zustand: ^4.3.2
@@ -4788,7 +4787,6 @@ __metadata:
memory-cache: ^0.2.0
micro: ^10.0.1
mime-types: ^2.1.35
- mockdate: ^3.0.5
module-alias: ^2.2.2
msw: ^0.42.3
next: ^13.4.6
@@ -26477,13 +26475,6 @@ __metadata:
languageName: node
linkType: hard
-"mockdate@npm:^3.0.5":
- version: 3.0.5
- resolution: "mockdate@npm:3.0.5"
- checksum: 72b66786d9e072379693f80bf9fb82eb5153c9741030a4294184e3ccaf952d0713fae8966f77780580cf902f8ec7ccc95577b0ad47980d255e2ffb71fc7ca49c
- languageName: node
- linkType: hard
-
"module-alias@npm:^2.2.2":
version: 2.2.2
resolution: "module-alias@npm:2.2.2"