From e24fd1cdcd389c2ab5e28e7c4f288100572184f8 Mon Sep 17 00:00:00 2001 From: Jessica Ho Date: Tue, 27 Feb 2024 02:19:21 +0000 Subject: [PATCH] prismaclient fixture --- playwright.config.ts | 1 + tests/db.spec.ts | 35 +++++++---------------------------- tests/test.ts | 13 +++++++++++++ 3 files changed, 21 insertions(+), 28 deletions(-) create mode 100644 tests/test.ts diff --git a/playwright.config.ts b/playwright.config.ts index c54c5b6..4f60067 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -18,6 +18,7 @@ const config: PlaywrightTestConfig = { }, timeout: 10000, testDir: 'tests', + testMatch:'*spec.ts', use: { locale: 'en-US', timezoneId: 'America/Los_Angeles' diff --git a/tests/db.spec.ts b/tests/db.spec.ts index e78a1c9..1107b8d 100644 --- a/tests/db.spec.ts +++ b/tests/db.spec.ts @@ -1,31 +1,10 @@ -import { expect, test } from '@playwright/test'; -import { PrismaClient } from '@prisma/client'; +import { expect } from '@playwright/test'; import SeedUtils from '../prisma/utils'; +import { test } from './test'; const host = 'http://localhost:5173'; -const prisma = new PrismaClient(); -test.beforeAll(async () => { - const utils = new SeedUtils(new Date(), prisma); - await Promise.all([ - utils.deleteUserAndHousehold('+12015550003'), - utils.deleteUserAndHousehold('+12015550004'), - utils.deleteAllFriendRequests() - ]); - - await Promise.all([ - ...[3, 4].map((userInd) => utils.createUserWithEmptyHousehold(userInd)), - ...[4].map((userInd) => utils.createActiveSession(userInd)) - ]); - - await Promise.all([ - utils.createFriendRequest(4, 3), - utils.createHouseholdConnection(3, 5), - utils.createHouseholdInvite(5, 2) - ]); -}); - -test.only("User can't save profile without session cookie", async ({ page, context }) => { +test("User can't save profile without session cookie", async ({ page, context }) => { const res = await context.request.fetch(host + '/db', { method: 'post', headers: { @@ -52,8 +31,8 @@ that info is derived from the session cookie - User 6 fails to delete another user */ -test.describe.only('Household Invites', () => { - test.beforeAll(async () => { +test.describe('Household Invites', () => { + test.beforeAll(async ({ prisma }) => { const utils = new SeedUtils(new Date(), prisma); await Promise.all([ @@ -117,8 +96,8 @@ test.describe.only('Household Invites', () => { }); }); -test.describe.only('Friend Requests', () => { - test.beforeAll(async () => { +test.describe('Friend Requests', () => { + test.beforeAll(async ({ prisma }) => { const utils = new SeedUtils(new Date(), prisma); await Promise.all([ diff --git a/tests/test.ts b/tests/test.ts new file mode 100644 index 0000000..04dcf80 --- /dev/null +++ b/tests/test.ts @@ -0,0 +1,13 @@ +import { test as base } from '@playwright/test'; +import { PrismaClient } from '@prisma/client'; + +// Note that we pass worker fixture types as a second template parameter. +export const test = base.extend<{}, { prisma: PrismaClient }>({ + prisma: [ + async ({}, use) => { + const prisma = new PrismaClient(); + await use(prisma); + }, + { scope: 'worker' } + ], +});