forked from jonaszb/kanban-next
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobalSetup.ts
43 lines (42 loc) · 1.87 KB
/
globalSetup.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
import { chromium, request, expect } from '@playwright/test';
require('dotenv').config();
export default async () => {
const users = [
{ webhookId: process.env.WEBHOOK_ID ?? '', storageState: 'storageState.json' },
{ webhookId: process.env.WEBHOOK_ID_ALT ?? '', storageState: 'storageStateAlt.json' },
];
const emailLogin = async (user: { webhookId: string; storageState: string }) => {
const apiContext = await request.newContext();
await apiContext.delete(`https://webhook.site/token/${user.webhookId}/request`);
const browser = await chromium.launch();
const context = await browser.newContext();
const page = await context.newPage();
await page.goto(process.env.BASE_URL ?? '');
await page.getByPlaceholder('[email protected]').fill(`${user.webhookId}@email.webhook.site`);
await page.getByText('Sign in with email').click();
let responseData: any;
await expect
.poll(
async () => {
const response = await apiContext.get(
`https://webhook.site/token/${user.webhookId}/requests?page=1&sorting=newest`
);
const data = (await response.json()).data;
responseData = data;
return responseData;
},
{ intervals: [500], timeout: 30000 }
)
.toHaveLength(1);
const magicLink = responseData[0]['text_content'].match(/http.*site/)[0];
await page.goto(magicLink);
await expect(page.locator('.app-container')).toBeVisible();
await page.context().storageState({ path: user.storageState });
await browser.close();
};
const loginPromises = [];
for (const user of users) {
loginPromises.push(emailLogin(user));
}
await Promise.all(loginPromises);
};