Total Complexity | 2 |
Complexity/F | 1 |
Lines of Code | 38 |
Function Count | 2 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import { expect, firefox, type FullConfig, type Browser } from "@playwright/test"; |
||
2 | |||
3 | import { STATE_AUTHENTICATED } from "./constants.js"; |
||
4 | |||
5 | export default async function globalSetup(config: FullConfig): Promise<void> { |
||
6 | const browser = await firefox.launch({ |
||
7 | headless: true, |
||
8 | }); |
||
9 | |||
10 | await saveAuthenticatedState(browser, config, "[email protected]", "john", STATE_AUTHENTICATED); |
||
11 | |||
12 | await browser.close(); |
||
13 | } |
||
14 | |||
15 | async function saveAuthenticatedState( |
||
16 | browser: Browser, |
||
17 | config: FullConfig, |
||
18 | email: string, |
||
19 | password: string, |
||
20 | path: string |
||
21 | ) { |
||
22 | const page = await browser.newPage({ |
||
23 | baseURL: config.projects[0].use.baseURL, |
||
24 | }); |
||
25 | await page.goto("/kit/login"); |
||
26 | |||
27 | await page.getByLabel("Adresse email").fill(email); |
||
28 | await page.getByLabel("Mot de passe").fill(password); |
||
29 | await page.getByText("Se connecter").click(); |
||
30 | |||
31 | const response = await page.waitForResponse("**/api/login"); |
||
32 | expect(response.status()).toBe(201); |
||
33 | |||
34 | await page.context().storageState({ path }); |
||
35 | |||
36 | await page.close(); |
||
37 | } |
||
38 |