Skip to content

Commit

Permalink
[E2E] Ensure cookies are fetched before logging in
Browse files Browse the repository at this point in the history
  • Loading branch information
samtgarson committed Dec 18, 2023
1 parent d3cfd7a commit ba4441f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
16 changes: 9 additions & 7 deletions packages/e2e/smoke-tests/homepage.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { expect, test } from 'test'

test.describe('Homepage', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/')
})
test.describe('when logged out', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/')
})

test('basic content', async ({ page }) => {
await expect(page.getByRole('heading', { level: 1 })).toHaveText(
"The cookbook industry's new digital home."
)
test('basic content', async ({ page }) => {
await expect(page.getByRole('heading', { level: 1 })).toHaveText(
"The cookbook industry's new digital home."
)
})
})

test.describe('when logged in', () => {
Expand Down
13 changes: 11 additions & 2 deletions packages/e2e/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@ import { encode } from '@auth/core/jwt'
import prisma from '@books-about-food/database'
import { BrowserContext, Page, test as base } from '@playwright/test'

const helpers = ({ context }: { page: Page; context: BrowserContext }) => ({
const helpers = ({
context,
page
}: {
page: Page
context: BrowserContext
}) => ({
async login() {
await page.goto('/', { waitUntil: 'commit' })
const cookies = await context.cookies()
const authCookie = cookies.find((cookie) => cookie.name.includes('authjs'))
const authCookie = cookies.find(
({ name }) => name.includes('authjs') && name.endsWith('callback-url')
)
if (!authCookie) throw new Error('No auth cookie found')

const prefix = authCookie.name.split('.')[0]
Expand Down

0 comments on commit ba4441f

Please sign in to comment.