refactor: Moving from jest to vitest (#9035)

* Moving to vitest

* Rearranging test

* Fixing prettier linting

* Reverting launch.json

* Adjustments

* Merged with main and regenerated lockfile

* Fixing tests for API

* Yarn updated, docs is gone

---------

Co-authored-by: Peer Richelsen <peeroke@gmail.com>
Co-authored-by: zomars <zomars@me.com>
Co-authored-by: Alex van Andel <me@alexvanandel.com>
This commit is contained in:
Leo Giovanetti 2023-05-24 20:35:44 -03:00 committed by GitHub
parent ae471ce86a
commit 734382b5b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
37 changed files with 1446 additions and 2095 deletions

View File

@ -7,6 +7,7 @@ public
*.lock
*.log
*.test.ts
.gitignore
.npmignore

View File

@ -1 +1,2 @@
public/embed
*.test.ts

View File

@ -156,7 +156,6 @@
"@types/stripe": "^8.0.417",
"@types/uuid": "8.3.1",
"autoprefixer": "^10.4.12",
"babel-jest": "^28.1.0",
"copy-webpack-plugin": "^11.0.0",
"detect-port": "^1.3.0",
"env-cmd": "^10.1.0",
@ -165,7 +164,6 @@
"msw": "^0.42.3",
"postcss": "^8.4.18",
"tailwindcss": "^3.3.1",
"ts-jest": "^28.0.8",
"ts-node": "^10.9.1",
"typescript": "^4.9.4"
},

View File

@ -103,7 +103,7 @@ export default function User(props: inferSSRProps<typeof getServerSideProps> & E
delete query.user; // So it doesn't display in the Link (and make tests fail)
const nameOrUsername = user.name || user.username || "";
/*
/*
const telemetry = useTelemetry();
useEffect(() => {
if (top !== window) {

View File

@ -1,10 +1,11 @@
import { describe, expect, it } from "vitest";
import prismaMock from "../../../../tests/libs/__mocks__/prisma";
import dayjs from "@calcom/dayjs";
import { validateIntervalLimitOrder } from "@calcom/lib";
import { checkBookingLimits, checkBookingLimit } from "@calcom/lib/server";
import type { IntervalLimit } from "@calcom/types/Calendar";
import { prismaMock } from "../../../../tests/config/singleton";
type Mockdata = {
id: number;
startDate: Date;

View File

@ -1,8 +1,10 @@
import { describe, expect, it } from "vitest";
import prismaMock from "../../../../tests/libs/__mocks__/prisma";
import dayjs from "@calcom/dayjs";
import { validateIntervalLimitOrder } from "@calcom/lib";
import { checkDurationLimit, checkDurationLimits } from "@calcom/lib/server";
import { prismaMock } from "../../../../tests/config/singleton";
type MockData = {
id: number;

View File

@ -1,5 +1,5 @@
import { expect, it } from "@jest/globals";
import MockDate from "mockdate";
import { expect, it } from "vitest";
import { getAggregateWorkingHours } from "@calcom/core/getAggregateWorkingHours";
@ -28,9 +28,9 @@ const HAWAII_AND_NEWYORK_TEAM = [
/* TODO: Make this test more "professional" */
it("Sydney and Shiraz can live in harmony 🙏", async () => {
expect(getAggregateWorkingHours(HAWAII_AND_NEWYORK_TEAM, "COLLECTIVE")).toMatchInlineSnapshot(`
Array [
Object {
"days": Array [
[
{
"days": [
3,
4,
5,
@ -38,16 +38,16 @@ it("Sydney and Shiraz can live in harmony 🙏", async () => {
"endTime": 360,
"startTime": 780,
},
Object {
"days": Array [
{
"days": [
6,
],
"endTime": 180,
"startTime": 0,
"userId": 2,
},
Object {
"days": Array [
{
"days": [
2,
3,
4,
@ -55,8 +55,8 @@ it("Sydney and Shiraz can live in harmony 🙏", async () => {
"endTime": 1260,
"startTime": 780,
},
Object {
"days": Array [
{
"days": [
5,
],
"endTime": 1260,
@ -66,9 +66,9 @@ it("Sydney and Shiraz can live in harmony 🙏", async () => {
`);
expect(getAggregateWorkingHours(HAWAII_AND_NEWYORK_TEAM, "ROUND_ROBIN")).toMatchInlineSnapshot(`
Array [
Object {
"days": Array [
[
{
"days": [
1,
2,
3,
@ -79,8 +79,8 @@ it("Sydney and Shiraz can live in harmony 🙏", async () => {
"startTime": 780,
"userId": 1,
},
Object {
"days": Array [
{
"days": [
3,
4,
5,
@ -89,16 +89,16 @@ it("Sydney and Shiraz can live in harmony 🙏", async () => {
"startTime": 0,
"userId": 1,
},
Object {
"days": Array [
{
"days": [
6,
],
"endTime": 180,
"startTime": 0,
"userId": 2,
},
Object {
"days": Array [
{
"days": [
2,
3,
4,
@ -107,8 +107,8 @@ it("Sydney and Shiraz can live in harmony 🙏", async () => {
"startTime": 780,
"userId": 3,
},
Object {
"days": Array [
{
"days": [
5,
],
"endTime": 1439,

View File

@ -1,6 +1,6 @@
import { expect, it } from "@jest/globals";
import type { Availability } from "@prisma/client";
import MockDate from "mockdate";
import { expect, it } from "vitest";
import dayjs from "@calcom/dayjs";
import { getAvailabilityFromSchedule } from "@calcom/lib/availability";

View File

@ -1,15 +1,16 @@
/**
* !: Stops the `jose` dependency from bundling the browser version and breaking tests
* @jest-environment node
*/
import type {
EventType as PrismaEventType,
User as PrismaUser,
Booking as PrismaBooking,
App as PrismaApp,
} from "@prisma/client";
import CalendarManagerMock from "../../../../tests/libs/__mocks__/CalendarManager";
import prismaMock from "../../../../tests/libs/__mocks__/prisma";
import { diff } from "jest-diff";
import { v4 as uuidv4 } from "uuid";
import { describe, expect, vi, beforeEach, afterEach, test } from "vitest";
import logger from "@calcom/lib/logger";
import prisma from "@calcom/prisma";
@ -18,14 +19,13 @@ import type { BookingStatus } from "@calcom/prisma/enums";
import type { Slot } from "@calcom/trpc/server/routers/viewer/slots/types";
import { getSchedule } from "@calcom/trpc/server/routers/viewer/slots/util";
import { prismaMock, CalendarManagerMock } from "../../../../tests/config/singleton";
// TODO: Mock properly
prismaMock.eventType.findUnique.mockResolvedValue(null);
prismaMock.user.findMany.mockResolvedValue([]);
jest.mock("@calcom/lib/constants", () => ({
vi.mock("@calcom/lib/constants", () => ({
IS_PRODUCTION: true,
WEBAPP_URL: "http://localhost:3000"
}));
declare global {
@ -233,6 +233,13 @@ describe("getSchedule", () => {
const { dateString: plus1DateString } = getDate({ dateIncrement: 1 });
const { dateString: plus2DateString } = getDate({ dateIncrement: 2 });
CalendarManagerMock.getBusyCalendarTimes.mockResolvedValue([
{
start: `${plus2DateString}T04:45:00.000Z`,
end: `${plus2DateString}T23:00:00.000Z`,
},
]);
const scenarioData = {
hosts: [],
eventTypes: [
@ -261,12 +268,6 @@ describe("getSchedule", () => {
// An event with one accepted booking
createBookingScenario(scenarioData);
addBusyTimesInGoogleCalendar([
{
start: `${plus2DateString}T04:45:00.000Z`,
end: `${plus2DateString}T23:00:00.000Z`,
},
]);
const scheduleForDayWithAGoogleCalendarBooking = await getSchedule({
eventTypeId: 1,
eventTypeSlug: "",
@ -492,7 +493,7 @@ describe("getSchedule", () => {
// FIXME: Fix minimumBookingNotice is respected test
test.skip("minimumBookingNotice is respected", async () => {
jest.useFakeTimers().setSystemTime(
vi.useFakeTimers().setSystemTime(
(() => {
const today = new Date();
// Beginning of the day in current timezone of the system
@ -571,13 +572,20 @@ describe("getSchedule", () => {
dateString: todayDateString,
}
);
jest.useRealTimers();
vi.useRealTimers();
});
test("afterBuffer and beforeBuffer tests - Non Cal Busy Time", async () => {
const { dateString: plus2DateString } = getDate({ dateIncrement: 2 });
const { dateString: plus3DateString } = getDate({ dateIncrement: 3 });
CalendarManagerMock.getBusyCalendarTimes.mockResolvedValue([
{
start: `${plus3DateString}T04:00:00.000Z`,
end: `${plus3DateString}T05:59:59.000Z`,
},
]);
const scenarioData = {
eventTypes: [
{
@ -607,13 +615,6 @@ describe("getSchedule", () => {
createBookingScenario(scenarioData);
addBusyTimesInGoogleCalendar([
{
start: `${plus3DateString}T04:00:00.000Z`,
end: `${plus3DateString}T05:59:59.000Z`,
},
]);
const scheduleForEventOnADayWithNonCalBooking = await getSchedule({
eventTypeId: 1,
eventTypeSlug: "",
@ -641,6 +642,13 @@ describe("getSchedule", () => {
const { dateString: plus2DateString } = getDate({ dateIncrement: 2 });
const { dateString: plus3DateString } = getDate({ dateIncrement: 3 });
CalendarManagerMock.getBusyCalendarTimes.mockResolvedValue([
{
start: `${plus3DateString}T04:00:00.000Z`,
end: `${plus3DateString}T05:59:59.000Z`,
},
]);
const scenarioData = {
eventTypes: [
{
@ -679,13 +687,6 @@ describe("getSchedule", () => {
createBookingScenario(scenarioData);
addBusyTimesInGoogleCalendar([
{
start: `${plus3DateString}T04:00:00.000Z`,
end: `${plus3DateString}T05:59:59.000Z`,
},
]);
const scheduleForEventOnADayWithCalBooking = await getSchedule({
eventTypeId: 1,
eventTypeSlug: "",
@ -712,6 +713,8 @@ describe("getSchedule", () => {
const { dateString: plus1DateString } = getDate({ dateIncrement: 1 });
const { dateString: plus2DateString } = getDate({ dateIncrement: 2 });
CalendarManagerMock.getBusyCalendarTimes.mockResolvedValue([]);
const scenarioData = {
eventTypes: [
{
@ -1380,15 +1383,3 @@ const getDate = (param: { dateIncrement?: number; monthIncrement?: number; yearI
dateString: `${year}-${month}-${date}`,
};
};
/**
* TODO: Improve this to validate the arguments passed to getBusyCalendarTimes if they are valid or not.
*/
function addBusyTimesInGoogleCalendar(
busy: {
start: string;
end: string;
}[]
) {
CalendarManagerMock.getBusyCalendarTimes.mockResolvedValue(busy);
}

View File

@ -1,4 +1,4 @@
import { expect, it } from "@jest/globals";
import { expect, it } from "vitest";
import { filterByCities, addCitiesToDropdown, handleOptionLabel } from "@calcom/lib/timezone";
@ -34,25 +34,25 @@ const option = {
};
it("should return empty array for an empty string", () => {
expect(filterByCities("", cityData)).toMatchInlineSnapshot(`Array []`);
expect(filterByCities("", cityData)).toMatchInlineSnapshot(`[]`);
});
it("should filter cities for a valid city name", () => {
expect(filterByCities("San Francisco", cityData)).toMatchInlineSnapshot(`
Array [
Object {
[
{
"city": "San Francisco",
"timezone": "America/Argentina/Cordoba",
},
Object {
{
"city": "San Francisco de Macoris",
"timezone": "America/Santo_Domingo",
},
Object {
{
"city": "San Francisco Gotera",
"timezone": "America/El_Salvador",
},
Object {
{
"city": "San Francisco",
"timezone": "America/Los_Angeles",
},
@ -62,7 +62,7 @@ it("should filter cities for a valid city name", () => {
it("should return appropriate timezone(s) for a given city name array", () => {
expect(addCitiesToDropdown(cityData)).toMatchInlineSnapshot(`
Object {
{
"America/Argentina/Cordoba": "San Francisco",
"America/El_Salvador": "San Francisco Gotera",
"America/Los_Angeles": "San Francisco",

View File

@ -1,5 +1,5 @@
import { expect, it } from "@jest/globals";
import MockDate from "mockdate";
import { expect, it } from "vitest";
import dayjs from "@calcom/dayjs";
import { getWorkingHours } from "@calcom/lib/availability";

View File

@ -1,11 +1,12 @@
import type { EventType } from "@prisma/client";
import type { Prisma } from "@prisma/client";
import { describe, expect, it, vi } from "vitest";
import updateChildrenEventTypes from "@calcom/features/ee/managed-event-types/lib/handleChildrenEventTypes";
import { buildEventType } from "@calcom/lib/test/builder";
import type { Prisma } from "@calcom/prisma/client";
import type { CompleteEventType, CompleteWorkflowsOnEventTypes } from "@calcom/prisma/zod";
import { prismaMock } from "../../../../tests/config/singleton";
import prismaMock from "../../../../tests/libs/__mocks__/prisma";
const mockFindFirstEventType = (data?: Partial<CompleteEventType>) => {
const eventType = buildEventType(data as Partial<EventType>);
@ -13,13 +14,13 @@ const mockFindFirstEventType = (data?: Partial<CompleteEventType>) => {
return eventType;
};
jest.mock("@calcom/emails/email-manager", () => {
vi.mock("@calcom/emails/email-manager", () => {
return {
sendSlugReplacementEmail: () => ({}),
};
});
jest.mock("@calcom/lib/server/i18n", () => {
vi.mock("@calcom/lib/server/i18n", () => {
return {
getTranslation: (key: string) => key,
};

View File

@ -1,3 +1,5 @@
import { expect, it } from "vitest";
import { parseZone } from "@calcom/lib/parse-zone";
const EXPECTED_DATE_STRING = "2021-06-20T11:59:59+02:00";

View File

@ -1,5 +1,5 @@
import { expect, it } from "@jest/globals";
import MockDate from "mockdate";
import { describe, expect, it } from "vitest";
import dayjs from "@calcom/dayjs";
import { MINUTES_DAY_END, MINUTES_DAY_START } from "@calcom/lib/availability";

View File

@ -1,8 +1,10 @@
import { expect, it } from "vitest";
import prismaMock from "../../../../tests/libs/__mocks__/prisma";
import { getLuckyUser } from "@calcom/lib/server";
import { buildUser } from "@calcom/lib/test/builder";
import { prismaMock } from "../../../../tests/config/singleton";
it("can find lucky user with maximize availability", async () => {
const user1 = buildUser({
id: 1,

View File

@ -1,119 +0,0 @@
import type { Config } from "jest";
// Added +2 to ensure we need to do some conversions in our tests
process.env.TZ = "GMT+2";
const config: Config = {
preset: "ts-jest",
verbose: true,
projects: [
{
displayName: "@calcom/web",
roots: ["<rootDir>/apps/web"],
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
modulePathIgnorePatterns: [
//
"<rootDir>/apps/web/test/__fixtures__",
"<rootDir>/apps/web/node_modules",
"<rootDir>/apps/web/dist",
],
clearMocks: true,
setupFilesAfterEnv: ["<rootDir>/tests/config/singleton.ts"],
setupFiles: ["<rootDir>/apps/web/test/jest-setup.js"],
testMatch: ["**/test/lib/**/*.(spec|test).(ts|tsx|js)", "**/__tests__/**/*.(spec|test).(ts|tsx|js)"],
testPathIgnorePatterns: ["<rootDir>/apps/web/.next", "<rootDir>/apps/web/playwright/"],
transform: {
"^.+\\.(js|jsx|ts|tsx)$": ["babel-jest", { presets: ["next/babel"] }],
},
transformIgnorePatterns: ["/node_modules/", "^.+\\.module\\.(css|sass|scss)$"],
testEnvironment: "jsdom",
resolver: `<rootDir>/apps/web/test/jest-resolver.js`,
moduleNameMapper: {
"^@components(.*)$": "<rootDir>/apps/web/components$1",
"^@lib(.*)$": "<rootDir>/apps/web/lib$1",
"^@server(.*)$": "<rootDir>/apps/web/server$1",
},
},
{
displayName: "@calcom/lib",
roots: ["<rootDir>/packages/lib"],
testEnvironment: "node",
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
transform: {
"^.+\\.tsx?$": "ts-jest",
},
globals: {
"ts-jest": {
tsconfig: "<rootDir>/packages/lib/tsconfig.test.json",
},
},
},
{
displayName: "@calcom/closecom",
roots: ["<rootDir>/packages/app-store/closecom"],
testMatch: ["**/test/lib/**/*.(spec|test).(ts|tsx|js)"],
transform: {
"^.+\\.ts?$": "ts-jest",
},
transformIgnorePatterns: ["/node_modules/", "^.+\\.module\\.(css|sass|scss)$"],
testEnvironment: "jsdom",
setupFiles: ["<rootDir>/packages/app-store/closecom/test/globals.ts"],
},
{
displayName: "@calcom/routing-forms",
roots: ["<rootDir>/packages/app-store/routing-forms"],
testMatch: ["**/test/lib/**/*.(spec|test).(ts|tsx|js)"],
transform: {
"^.+\\.ts?$": "ts-jest",
},
transformIgnorePatterns: ["/node_modules/", "^.+\\.module\\.(css|sass|scss)$"],
testEnvironment: "jsdom",
},
{
displayName: "@calcom/features",
roots: ["<rootDir>/packages/features"],
testMatch: ["**/*.(spec|test).(ts|tsx|js)"],
transform: {
"^.+\\.ts?$": "ts-jest",
},
transformIgnorePatterns: ["/node_modules/", "^.+\\.module\\.(css|sass|scss)$"],
testEnvironment: "jsdom",
moduleDirectories: ["node_modules", "<rootDir>"],
globals: {
"ts-jest": {
tsconfig: "<rootDir>/packages/features/tsconfig.json",
},
},
},
// FIXME: Prevent this breaking Jest when API module is missing
// {
// displayName: "@calcom/api",
// roots: ["<rootDir>/apps/api"],
// testMatch: ["**/test/lib/**/*.(spec|test).(ts|tsx|js)"],
// setupFilesAfterEnv: ["<rootDir>/tests/config/singleton.ts"],
// transform: {
// "^.+\\.ts?$": "ts-jest",
// },
// globals: {
// "ts-jest": {
// tsconfig: "<rootDir>/apps/api/tsconfig.json",
// },
// },
// transformIgnorePatterns: ["/node_modules/", "^.+\\.module\\.(css|sass|scss)$"],
// testEnvironment: "node",
// clearMocks: true,
// moduleNameMapper: {
// "^@lib/(.*)$": "<rootDir>/apps/api/lib/$1",
// "^@api/(.*)$": "<rootDir>/apps/api/pages/api/$1",
// },
// // setupFilesAfterEnv: ["<rootDir>/apps/api/jest.setup.ts"], // Uncomment when API becomes public
// },
],
watchPlugins: [
"jest-watch-typeahead/filename",
"jest-watch-typeahead/testname",
"jest-watch-select-projects",
],
};
export default config;

View File

@ -56,7 +56,7 @@
"prepare": "husky install",
"prisma": "yarn workspace @calcom/prisma prisma",
"start": "turbo run start --scope=\"@calcom/web\"",
"tdd": "jest --watch",
"tdd": "vitest watch",
"e2e": "NEXT_PUBLIC_IS_E2E=1 yarn playwright test --project=@calcom/web",
"e2e:app-store": "QUICK=true yarn playwright test --project=@calcom/app-store",
"e2e:embed": "QUICK=true yarn playwright test --project=@calcom/embed-core",
@ -66,7 +66,7 @@
"test-e2e:embed": "yarn db-seed && yarn e2e:embed",
"test-e2e:embed-react": "yarn db-seed && yarn e2e:embed-react",
"test-playwright": "yarn playwright test --config=playwright.config.ts",
"test": "jest",
"test": "vitest run",
"type-check": "turbo run type-check",
"type-check:ci": "turbo run type-check:ci --log-prefix=none",
"web": "yarn workspace @calcom/web"
@ -77,19 +77,17 @@
"@playwright/test": "^1.31.2",
"@snaplet/copycat": "^0.3.0",
"@types/dompurify": "^2.4.0",
"@types/jest": "^28.1.7",
"c8": "^7.13.0",
"dotenv-checker": "^1.1.5",
"husky": "^8.0.1",
"jest": "^28.1.0",
"jest-environment-jsdom": "^28.1.3",
"jest-mock-extended": "^2.0.7",
"jest-watch-select-projects": "^2.0.0",
"jest-watch-typeahead": "^2.0.0",
"husky": "^8.0.0",
"jest-diff": "^29.5.0",
"jsdom": "^22.0.0",
"lint-staged": "^12.5.0",
"prettier": "^2.8.6",
"ts-jest": "^28.0.8",
"tsc-absolute": "^1.0.0",
"typescript": "^4.9.4"
"typescript": "^4.9.4",
"vitest": "^0.31.1",
"vitest-mock-extended": "^1.1.3"
},
"dependencies": {
"city-timezones": "^1.2.1",

View File

@ -6,8 +6,8 @@
"main": "./index.ts",
"description": "Close is the inside sales CRM of choice for startups and SMBs. Make more calls, send more emails and close more deals starting today.",
"scripts": {
"test": "jest",
"test:coverage": "jest --coverage"
"test": "vitest",
"test:coverage": "vitest run --coverage"
},
"dependencies": {
"@calcom/lib": "*",

View File

@ -1,14 +1,16 @@
jest.mock("@calcom/lib/logger", () => ({
import { vi } from "vitest";
vi.mock("@calcom/lib/logger", () => ({
default: {
getChildLogger: () => ({
debug: jest.fn(),
error: jest.fn(),
log: jest.fn(),
debug: vi.fn(),
error: vi.fn(),
log: vi.fn(),
}),
},
}));
jest.mock("@calcom/lib/crypto", () => ({
vi.mock("@calcom/lib/crypto", () => ({
symmetricDecrypt: () => `{
"userApiKey": "test"
}`,

View File

@ -1,3 +1,5 @@
import { expect, vi, afterEach, test } from "vitest";
import CloseCom from "@calcom/lib/CloseCom";
import {
getCloseComContactIds,
@ -7,7 +9,7 @@ import {
} from "@calcom/lib/CloseComeUtils";
import type { CalendarEvent } from "@calcom/types/Calendar";
jest.mock("@calcom/lib/CloseCom", () => ({
vi.mock("@calcom/lib/CloseCom", () => ({
default: class {
constructor() {
/* Mock */
@ -16,7 +18,7 @@ jest.mock("@calcom/lib/CloseCom", () => ({
}));
afterEach(() => {
jest.resetAllMocks();
vi.resetAllMocks();
});
// getCloseComLeadId

View File

@ -1,9 +1,9 @@
import { expect, it, describe } from "@jest/globals";
import { describe, expect, it, afterEach, vi } from "vitest";
import { jsonLogicToPrisma } from "../../jsonLogicToPrisma";
afterEach(() => {
jest.resetAllMocks();
vi.resetAllMocks();
});
describe("jsonLogicToPrisma - Single Query", () => {

View File

@ -304,11 +304,11 @@ const getEventTypesFromDB = async (eventTypeId: number) => {
return {
...eventType,
metadata: EventTypeMetaDataSchema.parse(eventType.metadata),
recurringEvent: parseRecurringEvent(eventType.recurringEvent),
customInputs: customInputSchema.array().parse(eventType.customInputs || []),
locations: (eventType.locations ?? []) as LocationObject[],
bookingFields: getBookingFieldsWithSystemFields(eventType),
metadata: EventTypeMetaDataSchema.parse(eventType?.metadata || {}),
recurringEvent: parseRecurringEvent(eventType?.recurringEvent),
customInputs: customInputSchema.array().parse(eventType?.customInputs || []),
locations: (eventType?.locations ?? []) as LocationObject[],
bookingFields: getBookingFieldsWithSystemFields(eventType || {}),
};
};
@ -488,7 +488,7 @@ function getBookingData({
}
}
});
debugger;
const reqBody = bookingDataSchema.parse(req.body);
if ("customInputs" in reqBody) {
if (reqBody.customInputs) {
@ -584,7 +584,7 @@ async function handler(
...eventType,
bookingFields: getBookingFieldsWithSystemFields(eventType),
};
debugger;
const {
recurringCount,
allRecurringDates,
@ -673,7 +673,7 @@ async function handler(
...user,
isFixed,
}))
: eventType.users;
: eventType.users || [];
// loadUsers allows type inferring
let users: (Awaited<ReturnType<typeof loadUsers>>[number] & {
isFixed?: boolean;

View File

@ -1,3 +1,5 @@
import { describe, expect, it } from "vitest";
import { applyStyleToMultipleVariants } from "./cva";
describe("CVA Utils", () => {

View File

@ -1,3 +1,5 @@
import { describe, expect, it } from "vitest";
import { defaultAvatarSrc, getPlaceholderAvatar } from "./defaultAvatarImage";
describe("Default Avatar Image tests", () => {

View File

@ -1,3 +1,5 @@
import { describe, expect, it } from "vitest";
import { createColorMap } from "./getBrandColours";
describe("useGetBrandingColours", () => {

View File

@ -1,3 +1,5 @@
import { describe, expect, it } from "vitest";
import { randomString } from "./random";
describe("Random util tests", () => {

View File

@ -1,4 +1,5 @@
import { faker } from "@faker-js/faker";
import { describe, expect, it, vi } from "vitest";
import {
getLocation,
@ -8,11 +9,11 @@ import {
} from "../CalEventParser";
import { buildCalendarEvent, buildVideoCallData } from "./builder";
jest.mock("@calcom/lib/constants", () => ({
vi.mock("@calcom/lib/constants", () => ({
WEBAPP_URL: "http://localhost:3000",
}));
jest.mock("short-uuid", () => ({
vi.mock("short-uuid", () => ({
__esModule: true,
default: () => ({ fromUUID: () => "FAKE_UUID" }),
}));

View File

@ -1,3 +1,5 @@
import { describe, expect, it } from "vitest";
import { truncate } from "./text";
describe("Text util tests", () => {

View File

@ -1,3 +1,5 @@
import { describe, expect, it } from "vitest";
import { nameOfDay, weekdayNames } from "./weekday";
describe("Weekday tests", () => {

View File

@ -1,20 +0,0 @@
import type { PrismaClient } from "@prisma/client";
import type { DeepMockProxy } from "jest-mock-extended";
import { mockDeep, mockReset } from "jest-mock-extended";
import * as CalendarManager from "@calcom/core/CalendarManager";
import prisma from "@calcom/prisma";
jest.mock("@calcom/core/CalendarManager");
jest.mock("@calcom/prisma", () => ({
__esModule: true,
default: mockDeep<PrismaClient>(),
}));
beforeEach(() => {
mockReset(prismaMock);
});
export const prismaMock = prisma as unknown as DeepMockProxy<PrismaClient>;
export const CalendarManagerMock = CalendarManager as unknown as DeepMockProxy<typeof CalendarManager>;

View File

@ -0,0 +1,13 @@
import { beforeEach, vi } from "vitest";
import { mockReset, mockDeep } from "vitest-mock-extended";
import type * as CalendarManager from "@calcom/core/CalendarManager";
vi.mock("@calcom/core/CalendarManager", () => CalendarManagerMock);
beforeEach(() => {
mockReset(CalendarManagerMock);
});
const CalendarManagerMock = mockDeep<typeof CalendarManager>();
export default CalendarManagerMock;

View File

@ -0,0 +1,16 @@
import type { PrismaClient } from "@prisma/client";
import { beforeEach, vi } from "vitest";
import { mockDeep, mockReset } from "vitest-mock-extended";
vi.mock("@calcom/prisma", () => ({
default: prisma,
availabilityUserSelect: vi.fn(),
userSelect: vi.fn(),
}));
beforeEach(() => {
mockReset(prisma);
});
const prisma = mockDeep<PrismaClient>();
export default prisma;

9
vitest.config.ts Normal file
View File

@ -0,0 +1,9 @@
import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
coverage: {
provider: "c8",
},
},
});

18
vitest.workspace.ts Normal file
View File

@ -0,0 +1,18 @@
import { defineWorkspace } from "vitest/config";
// defineWorkspace provides a nice type hinting DX
export default defineWorkspace([
{
test: {
include: ["packages/**/*.{test,spec}.{ts,js}", "apps/**/*.{test,spec}.{ts,js}"],
},
},
{
test: {
name: "@calcom/closecom",
include: ["packages/app-store/closecom/**/*.{test,spec}.{ts,js}"],
environment: "jsdom",
setupFiles: ["packages/app-store/closecom/test/globals.ts"],
},
},
]);

3098
yarn.lock

File diff suppressed because it is too large Load Diff