-
Notifications
You must be signed in to change notification settings - Fork 0
/
playwright-setup.ts
44 lines (41 loc) · 1.44 KB
/
playwright-setup.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { prisma } from './lib/db'
import { chromium, FullConfig } from '@playwright/test'
import { createAndSaveUser } from './tests/util'
// Clear the database
async function resetDatabase() {
const [{ current_database }] = await prisma.$queryRaw<{ current_database: string }[]>`select current_database()`
if (current_database !== 'db_dev') throw new Error(`Expected to connect to the dev database, got ${current_database}`)
// NB: we can't use 'prisma migrate reset' because it will recreate enums and we'll end up with outdated type
// references in the running server
await prisma.subscriptionUpdate.deleteMany()
await prisma.reply.deleteMany()
await prisma.user.deleteMany()
console.log('The database has been reset')
}
async function globalSetup(config: FullConfig) {
await resetDatabase()
// Note: regardless of the chosen browser, we always use Chromium to create users. This isn't a conscious choice, it
// just happened and should ideally be fixed.
const browser = await chromium.launch()
const page = await browser.newPage({ baseURL: config.projects[0].use.baseURL })
await createAndSaveUser(
page,
{ logout: true },
{
email: 'alice@woc.test',
handle: 'alice',
displayName: 'Alice T.',
}
)
await createAndSaveUser(
page,
{ logout: true },
{
email: 'bob@woc.test',
handle: 'bob',
displayName: 'Bob T.',
}
)
await browser.close()
}
export default globalSetup