fix: inconsistent timezones in e2e tests (#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
pull/11502/head
Omar López 2023-10-16 19:53:54 -07:00 committed by GitHub
parent fe364bd2da
commit d46e80c2ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 19 deletions

View File

@ -3,13 +3,16 @@ import type { Booking, Prisma } from "@prisma/client";
import short from "short-uuid"; import short from "short-uuid";
import { v5 as uuidv5 } from "uuid"; import { v5 as uuidv5 } from "uuid";
import dayjs from "@calcom/dayjs"; import _dayjs from "@calcom/dayjs";
import { prisma } from "@calcom/prisma"; import { prisma } from "@calcom/prisma";
const translator = short(); const translator = short();
type BookingFixture = ReturnType<typeof createBookingFixture>; type BookingFixture = ReturnType<typeof createBookingFixture>;
// We default all dayjs calls to use Europe/London timezone
const dayjs = (...args: Parameters<typeof _dayjs>) => _dayjs(...args).tz("Europe/London");
// creates a user fixture instance and stores the collection // creates a user fixture instance and stores the collection
export const createBookingsFixture = (page: Page) => { export const createBookingsFixture = (page: Page) => {
const store = { bookings: [], page } as { bookings: BookingFixture[]; page: typeof page }; const store = { bookings: [], page } as { bookings: BookingFixture[]; page: typeof page };

View File

@ -4,7 +4,6 @@ import { Prisma as PrismaType } from "@prisma/client";
import { hashSync as hash } from "bcryptjs"; import { hashSync as hash } from "bcryptjs";
import type { API } from "mailhog"; import type { API } from "mailhog";
import dayjs from "@calcom/dayjs";
import stripe from "@calcom/features/ee/payments/server/stripe"; import stripe from "@calcom/features/ee/payments/server/stripe";
import { DEFAULT_SCHEDULE, getAvailabilityFromSchedule } from "@calcom/lib/availability"; import { DEFAULT_SCHEDULE, getAvailabilityFromSchedule } from "@calcom/lib/availability";
import { WEBAPP_URL } from "@calcom/lib/constants"; import { WEBAPP_URL } from "@calcom/lib/constants";
@ -12,7 +11,7 @@ import { prisma } from "@calcom/prisma";
import { MembershipRole, SchedulingType } from "@calcom/prisma/enums"; import { MembershipRole, SchedulingType } from "@calcom/prisma/enums";
import { selectFirstAvailableTimeSlotNextMonth, teamEventSlug, teamEventTitle } from "../lib/testUtils"; import { selectFirstAvailableTimeSlotNextMonth, teamEventSlug, teamEventTitle } from "../lib/testUtils";
import type { TimeZoneEnum } from "./types"; import { TimeZoneEnum } from "./types";
// Don't import hashPassword from app as that ends up importing next-auth and initializing it before NEXTAUTH_URL can be updated during tests. // Don't import hashPassword from app as that ends up importing next-auth and initializing it before NEXTAUTH_URL can be updated during tests.
export function hashPassword(password: string) { export function hashPassword(password: string) {
@ -477,13 +476,14 @@ const createUser = (workerInfo: WorkerInfo, opts?: CustomUserOpts | null): Prism
password: hashPassword(uname), password: hashPassword(uname),
emailVerified: new Date(), emailVerified: new Date(),
completedOnboarding: opts?.completedOnboarding ?? true, completedOnboarding: opts?.completedOnboarding ?? true,
timeZone: opts?.timeZone ?? dayjs.tz.guess(), timeZone: opts?.timeZone ?? TimeZoneEnum.UK,
locale: opts?.locale ?? "en", locale: opts?.locale ?? "en",
schedules: schedules:
opts?.completedOnboarding ?? true opts?.completedOnboarding ?? true
? { ? {
create: { create: {
name: "Working Hours", name: "Working Hours",
timeZone: opts?.timeZone ?? TimeZoneEnum.UK,
availability: { availability: {
createMany: { createMany: {
data: getAvailabilityFromSchedule(DEFAULT_SCHEDULE), data: getAvailabilityFromSchedule(DEFAULT_SCHEDULE),

View File

@ -1,6 +1,6 @@
import { expect } from "@playwright/test"; import { expect } from "@playwright/test";
import dayjs from "@calcom/dayjs"; import _dayjs from "@calcom/dayjs";
import prisma from "@calcom/prisma"; import prisma from "@calcom/prisma";
import { test } from "./lib/fixtures"; import { test } from "./lib/fixtures";
@ -9,6 +9,9 @@ test.describe.configure({ mode: "parallel" });
test.afterEach(({ users }) => users.deleteAll()); test.afterEach(({ users }) => users.deleteAll());
// We default all dayjs calls to use Europe/London timezone
const dayjs = (...args: Parameters<typeof _dayjs>) => _dayjs(...args).tz("Europe/London");
test.describe("Wipe my Cal App Test", () => { test.describe("Wipe my Cal App Test", () => {
test("Browse upcoming bookings and validate button shows and triggering wipe my cal button", async ({ test("Browse upcoming bookings and validate button shows and triggering wipe my cal button", async ({
page, page,

View File

@ -55,6 +55,14 @@ if (IS_EMBED_REACT_TEST) {
}); });
} }
const DEFAULT_CHROMIUM = {
...devices["Desktop Chrome"],
timezoneId: "Europe/London",
locale: "en-US",
/** If navigation takes more than this, then something's wrong, let's fail fast. */
navigationTimeout: DEFAULT_NAVIGATION_TIMEOUT,
};
const config: PlaywrightTestConfig = { const config: PlaywrightTestConfig = {
forbidOnly: !!process.env.CI, forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0, retries: process.env.CI ? 2 : 0,
@ -86,12 +94,7 @@ const config: PlaywrightTestConfig = {
expect: { expect: {
timeout: DEFAULT_EXPECT_TIMEOUT, timeout: DEFAULT_EXPECT_TIMEOUT,
}, },
use: { use: DEFAULT_CHROMIUM,
...devices["Desktop Chrome"],
locale: "en-US",
/** If navigation takes more than this, then something's wrong, let's fail fast. */
navigationTimeout: DEFAULT_NAVIGATION_TIMEOUT,
},
}, },
{ {
name: "@calcom/app-store", name: "@calcom/app-store",
@ -100,12 +103,7 @@ const config: PlaywrightTestConfig = {
expect: { expect: {
timeout: DEFAULT_EXPECT_TIMEOUT, timeout: DEFAULT_EXPECT_TIMEOUT,
}, },
use: { use: DEFAULT_CHROMIUM,
...devices["Desktop Chrome"],
locale: "en-US",
/** If navigation takes more than this, then something's wrong, let's fail fast. */
navigationTimeout: DEFAULT_NAVIGATION_TIMEOUT,
},
}, },
{ {
name: "@calcom/embed-core", name: "@calcom/embed-core",
@ -114,7 +112,11 @@ const config: PlaywrightTestConfig = {
expect: { expect: {
timeout: DEFAULT_EXPECT_TIMEOUT, timeout: DEFAULT_EXPECT_TIMEOUT,
}, },
use: { ...devices["Desktop Chrome"], locale: "en-US", baseURL: "http://localhost:3100/" }, use: {
...devices["Desktop Chrome"],
locale: "en-US",
baseURL: "http://localhost:3100/",
},
}, },
{ {
name: "@calcom/embed-react", name: "@calcom/embed-react",
@ -123,7 +125,10 @@ const config: PlaywrightTestConfig = {
timeout: DEFAULT_EXPECT_TIMEOUT, timeout: DEFAULT_EXPECT_TIMEOUT,
}, },
testMatch: /.*\.e2e\.tsx?/, testMatch: /.*\.e2e\.tsx?/,
use: { ...devices["Desktop Chrome"], locale: "en-US", baseURL: "http://localhost:3101/" }, use: {
...DEFAULT_CHROMIUM,
baseURL: "http://localhost:3101/",
},
}, },
{ {
name: "@calcom/embed-core--firefox", name: "@calcom/embed-core--firefox",