Passed
Pull Request — master (#312)
by
unknown
03:23 queued 01:23
created

client/kit/e2e/global.setup.ts   A

Complexity

Total Complexity 2
Complexity/F 1

Size

Lines of Code 38
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 32
mnd 0
bc 0
fnc 2
dl 0
loc 38
bpm 0
cpm 1
noi 0
c 0
b 0
f 0
rs 10

2 Functions

Rating   Name   Duplication   Size   Complexity  
A global.setup.ts ➔ globalSetup 0 9 1
A global.setup.ts ➔ saveAuthenticatedState 0 23 1
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