Skip to content

Commit d46e80c

Browse files
authored
fix: inconsistent timezones in e2e tests (calcom#11841)
* fix: inconsistent timezones in e2e tests * Update users.ts * Update playwright.config.ts * Update playwright.config.ts * Update users.ts * fix: timezone sensitive tests
1 parent fe364bd commit d46e80c

File tree

4 files changed

+30
-19
lines changed

4 files changed

+30
-19
lines changed

apps/web/playwright/fixtures/bookings.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ import type { Booking, Prisma } from "@prisma/client";
33
import short from "short-uuid";
44
import { v5 as uuidv5 } from "uuid";
55

6-
import dayjs from "@calcom/dayjs";
6+
import _dayjs from "@calcom/dayjs";
77
import { prisma } from "@calcom/prisma";
88

99
const translator = short();
1010

1111
type BookingFixture = ReturnType<typeof createBookingFixture>;
1212

13+
// We default all dayjs calls to use Europe/London timezone
14+
const dayjs = (...args: Parameters<typeof _dayjs>) => _dayjs(...args).tz("Europe/London");
15+
1316
// creates a user fixture instance and stores the collection
1417
export const createBookingsFixture = (page: Page) => {
1518
const store = { bookings: [], page } as { bookings: BookingFixture[]; page: typeof page };

apps/web/playwright/fixtures/users.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ import { Prisma as PrismaType } from "@prisma/client";
44
import { hashSync as hash } from "bcryptjs";
55
import type { API } from "mailhog";
66

7-
import dayjs from "@calcom/dayjs";
87
import stripe from "@calcom/features/ee/payments/server/stripe";
98
import { DEFAULT_SCHEDULE, getAvailabilityFromSchedule } from "@calcom/lib/availability";
109
import { WEBAPP_URL } from "@calcom/lib/constants";
1110
import { prisma } from "@calcom/prisma";
1211
import { MembershipRole, SchedulingType } from "@calcom/prisma/enums";
1312

1413
import { selectFirstAvailableTimeSlotNextMonth, teamEventSlug, teamEventTitle } from "../lib/testUtils";
15-
import type { TimeZoneEnum } from "./types";
14+
import { TimeZoneEnum } from "./types";
1615

1716
// Don't import hashPassword from app as that ends up importing next-auth and initializing it before NEXTAUTH_URL can be updated during tests.
1817
export function hashPassword(password: string) {
@@ -477,13 +476,14 @@ const createUser = (workerInfo: WorkerInfo, opts?: CustomUserOpts | null): Prism
477476
password: hashPassword(uname),
478477
emailVerified: new Date(),
479478
completedOnboarding: opts?.completedOnboarding ?? true,
480-
timeZone: opts?.timeZone ?? dayjs.tz.guess(),
479+
timeZone: opts?.timeZone ?? TimeZoneEnum.UK,
481480
locale: opts?.locale ?? "en",
482481
schedules:
483482
opts?.completedOnboarding ?? true
484483
? {
485484
create: {
486485
name: "Working Hours",
486+
timeZone: opts?.timeZone ?? TimeZoneEnum.UK,
487487
availability: {
488488
createMany: {
489489
data: getAvailabilityFromSchedule(DEFAULT_SCHEDULE),

apps/web/playwright/wipe-my-cal.e2e.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect } from "@playwright/test";
22

3-
import dayjs from "@calcom/dayjs";
3+
import _dayjs from "@calcom/dayjs";
44
import prisma from "@calcom/prisma";
55

66
import { test } from "./lib/fixtures";
@@ -9,6 +9,9 @@ test.describe.configure({ mode: "parallel" });
99

1010
test.afterEach(({ users }) => users.deleteAll());
1111

12+
// We default all dayjs calls to use Europe/London timezone
13+
const dayjs = (...args: Parameters<typeof _dayjs>) => _dayjs(...args).tz("Europe/London");
14+
1215
test.describe("Wipe my Cal App Test", () => {
1316
test("Browse upcoming bookings and validate button shows and triggering wipe my cal button", async ({
1417
page,

playwright.config.ts

+19-14
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ if (IS_EMBED_REACT_TEST) {
5555
});
5656
}
5757

58+
const DEFAULT_CHROMIUM = {
59+
...devices["Desktop Chrome"],
60+
timezoneId: "Europe/London",
61+
locale: "en-US",
62+
/** If navigation takes more than this, then something's wrong, let's fail fast. */
63+
navigationTimeout: DEFAULT_NAVIGATION_TIMEOUT,
64+
};
65+
5866
const config: PlaywrightTestConfig = {
5967
forbidOnly: !!process.env.CI,
6068
retries: process.env.CI ? 2 : 0,
@@ -86,12 +94,7 @@ const config: PlaywrightTestConfig = {
8694
expect: {
8795
timeout: DEFAULT_EXPECT_TIMEOUT,
8896
},
89-
use: {
90-
...devices["Desktop Chrome"],
91-
locale: "en-US",
92-
/** If navigation takes more than this, then something's wrong, let's fail fast. */
93-
navigationTimeout: DEFAULT_NAVIGATION_TIMEOUT,
94-
},
97+
use: DEFAULT_CHROMIUM,
9598
},
9699
{
97100
name: "@calcom/app-store",
@@ -100,12 +103,7 @@ const config: PlaywrightTestConfig = {
100103
expect: {
101104
timeout: DEFAULT_EXPECT_TIMEOUT,
102105
},
103-
use: {
104-
...devices["Desktop Chrome"],
105-
locale: "en-US",
106-
/** If navigation takes more than this, then something's wrong, let's fail fast. */
107-
navigationTimeout: DEFAULT_NAVIGATION_TIMEOUT,
108-
},
106+
use: DEFAULT_CHROMIUM,
109107
},
110108
{
111109
name: "@calcom/embed-core",
@@ -114,7 +112,11 @@ const config: PlaywrightTestConfig = {
114112
expect: {
115113
timeout: DEFAULT_EXPECT_TIMEOUT,
116114
},
117-
use: { ...devices["Desktop Chrome"], locale: "en-US", baseURL: "http://localhost:3100/" },
115+
use: {
116+
...devices["Desktop Chrome"],
117+
locale: "en-US",
118+
baseURL: "http://localhost:3100/",
119+
},
118120
},
119121
{
120122
name: "@calcom/embed-react",
@@ -123,7 +125,10 @@ const config: PlaywrightTestConfig = {
123125
timeout: DEFAULT_EXPECT_TIMEOUT,
124126
},
125127
testMatch: /.*\.e2e\.tsx?/,
126-
use: { ...devices["Desktop Chrome"], locale: "en-US", baseURL: "http://localhost:3101/" },
128+
use: {
129+
...DEFAULT_CHROMIUM,
130+
baseURL: "http://localhost:3101/",
131+
},
127132
},
128133
{
129134
name: "@calcom/embed-core--firefox",

0 commit comments

Comments
 (0)