Skip to content

Commit e1def9e

Browse files
committed
fix
1 parent 0892426 commit e1def9e

6 files changed

Lines changed: 77 additions & 36 deletions

File tree

PLAYWRIGHT_CONFIG_EXPLAINED.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,54 @@
33
## 🎯 Kluczowe ustawienia
44

55
### `fullyParallel: false`
6+
67
**Co to robi:** Testy uruchamiają się jeden po drugim
78
**Dlaczego:** Łatwiej debugować na początku. Zmień na `true` gdy będziesz mieć dużo stabilnych testów.
89

910
### `workers: 1`
11+
1012
**Co to robi:** Tylko jedna przeglądarka w tym samym czasie
1113
**Dlaczego:** Stabilniejsze, łatwiej śledzić co się dzieje
1214

1315
### `trace: "on"`
16+
1417
**Co to robi:** Zapisuje każdy krok testu (kliknięcia, nawigacja, itp.)
1518
**Jak zobaczyć:** `npx playwright show-trace playwright-report/trace.zip`
1619
**Kiedy:** Zawsze - zobaczysz dokładnie co poszło nie tak
1720

1821
### `screenshot: "only-on-failure"`
22+
1923
**Co to robi:** Robi zdjęcie ekranu gdy test failuje
2024
**Gdzie:** `playwright-report/` folder
2125

2226
### `video: "off"`
27+
2328
**Co to robi:** Nie nagrywa wideo
2429
**Dlaczego:** Trace + screenshoty wystarczą, wideo zajmuje dużo miejsca
2530
**Kiedy włączyć:** Jak będziesz mieć bardzo trudny do zreprodukowania bug
2631

2732
### `baseURL: "http://localhost:3000"`
33+
2834
**Co to robi:** Możesz pisać `page.goto('/')` zamiast `page.goto('http://localhost:3000/')`
2935
**Przykład:**
36+
3037
```typescript
3138
// Zamiast tego:
32-
await page.goto('http://localhost:3000/dashboard');
39+
await page.goto("http://localhost:3000/dashboard");
3340

3441
// Piszesz:
35-
await page.goto('/dashboard');
42+
await page.goto("/dashboard");
3643
```
3744

3845
### `webServer`
46+
3947
**Co to robi:** Automatycznie uruchamia `npm run dev` przed testami
4048
**Bonus:** `reuseExistingServer: true` - jeśli masz już uruchomiony dev server, użyje go (szybciej)
4149

4250
## 🚀 Jak używać
4351

4452
### Pierwszy test
53+
4554
```bash
4655
# Uruchom testy E2E
4756
npm run test:e2e
@@ -52,6 +61,7 @@ npm run test:e2e
5261
```
5362

5463
### Gdy test failuje
64+
5565
```bash
5666
# Playwright automatycznie:
5767
# 1. Zrobi screenshot → playwright-report/
@@ -68,6 +78,7 @@ npm run test:e2e:report
6878
```
6979

7080
### Debugowanie
81+
7182
```bash
7283
# Tryb debug - zatrzymuje test i pokazuje przeglądarkę
7384
npm run test:e2e:debug
@@ -83,26 +94,32 @@ npm run test:e2e:ui
8394
## 💡 Tipsy
8495

8596
### 1. Zacznij od prostych testów
97+
8698
```typescript
87-
test('should load homepage', async ({ page }) => {
88-
await page.goto('/');
99+
test("should load homepage", async ({ page }) => {
100+
await page.goto("/");
89101
await expect(page).toHaveTitle(/Pathly/);
90102
});
91103
```
92104

93105
### 2. Używaj UI mode podczas pisania testów
106+
94107
```bash
95108
npm run test:e2e:ui
96109
```
110+
97111
Zobaczysz na żywo co robi Twój test!
98112

99113
### 3. Trace to Twój najlepszy przyjaciel
114+
100115
Gdy test failuje:
116+
101117
1. Otwórz `npm run test:e2e:report`
102118
2. Kliknij na failed test
103119
3. Zobacz trace - zobaczysz DOKŁADNIE co się stało, krok po kroku
104120

105121
### 4. Nie martw się o wydajność na początku
122+
106123
- `workers: 1` jest OK
107124
- `fullyParallel: false` jest OK
108125
- `trace: "on"` jest OK
@@ -112,18 +129,21 @@ Optymalizujesz później, gdy będziesz mieć dużo testów.
112129
## 🎨 Kiedy zmienić ustawienia
113130

114131
### Masz już 10+ stabilnych testów?
132+
115133
```typescript
116134
fullyParallel: true, // Szybsze testy
117135
workers: 4, // 4 przeglądarki naraz
118136
trace: "retain-on-failure", // Trace tylko przy failach
119137
```
120138

121139
### Potrzebujesz wideo?
140+
122141
```typescript
123142
video: "retain-on-failure", // Tylko przy failach
124143
```
125144

126145
### Testujesz mobile?
146+
127147
```typescript
128148
projects: [
129149
{ name: "chromium", use: { ...devices["Desktop Chrome"] } },
@@ -147,4 +167,3 @@ A: To "nagranie" testu - każdy klik, nawigacja, assertion. Bezcenne przy debugo
147167

148168
**Q: Muszę testować na Firefox/Safari?**
149169
A: Na początku nie. Chromium wystarczy. Dodasz później jeśli będzie potrzeba.
150-

VITEST_CONFIG_EXPLAINED.md

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,72 +3,86 @@
33
## 🎯 Kluczowe ustawienia
44

55
### `environment: "jsdom"`
6+
67
**Co to robi:** Symuluje środowisko przeglądarki (DOM, window, document)
78
**Dlaczego:** Twoje komponenty React potrzebują DOM
89
**Alternatywa:** `happy-dom` (szybszy, ale mniej kompatybilny) - zostań przy jsdom
910

1011
### `globals: true`
12+
1113
**Co to robi:** Możesz pisać `describe`, `it`, `expect` bez importów
1214
**Przykład:**
15+
1316
```typescript
1417
// Bez globals:
15-
import { describe, it, expect } from 'vitest';
18+
import { describe, it, expect } from "vitest";
1619

1720
// Z globals (prostsze!):
18-
describe('MyComponent', () => {
19-
it('should render', () => {
21+
describe("MyComponent", () => {
22+
it("should render", () => {
2023
expect(true).toBe(true);
2124
});
2225
});
2326
```
2427

2528
### `setupFiles: ["./src/test/setup-tests.ts"]`
29+
2630
**Co to robi:** Uruchamia ten plik przed wszystkimi testami
2731
**Co jest w środku:**
32+
2833
- `@testing-library/jest-dom` (matchery jak `toBeInTheDocument()`)
2934
- Mocki Next.js (`useRouter`, `usePathname`, itp.)
3035
- Mocki next-intl, next-themes
3136
- MSW (Mock Service Worker) setup
3237

3338
### `css: true`
39+
3440
**Co to robi:** Nie failuje gdy importujesz CSS w komponentach
3541
**Przykład:**
42+
3643
```typescript
3744
// Bez css: true → ERROR
38-
import './Button.css';
45+
import "./Button.css";
3946

4047
// Z css: true → OK ✅
41-
import './Button.css';
48+
import "./Button.css";
4249
```
4350

4451
## 📊 Coverage (Pokrycie kodu)
4552

4653
### `reporter: ["text", "html"]`
54+
4755
**Co to robi:**
56+
4857
- `text` - pokazuje wyniki w terminalu
4958
- `html` - generuje stronę HTML w `coverage/index.html`
5059

5160
**Usunięte:** `json` i `lcov` (niepotrzebne bez CI/CD)
5261

5362
### `thresholds: 60`
63+
5464
**Co to robi:** Minimalny % pokrycia kodu
5565
**Zmienione z 70% na 60%** - łatwiej na początek
5666

5767
**4 typy pokrycia:**
68+
5869
- **lines:** % linii kodu które zostały uruchomione
5970
- **functions:** % funkcji które zostały wywołane
6071
- **branches:** % ścieżek (if/else) które zostały przetestowane
6172
- **statements:** % instrukcji które zostały wykonane
6273

6374
**Co się stanie jak spadnie poniżej 60%?**
75+
6476
```bash
6577
npm run test:coverage
6678
# ERROR: Coverage threshold not met!
6779
```
6880

6981
### `exclude` (w coverage)
82+
7083
**Co to robi:** Te pliki nie liczą się do pokrycia
7184
**Co wykluczamy:**
85+
7286
- `src/test/` - same testy
7387
- `**/*.config.*` - pliki konfiguracyjne (vitest.config.ts, itp.)
7488
- `src/db/database.types.ts` - auto-generowane przez Supabase
@@ -77,19 +91,22 @@ npm run test:coverage
7791
## 🎨 Aliasy ścieżek
7892

7993
### `alias: { "@": "./src" }`
94+
8095
**Co to robi:** Możesz pisać `@/components` zamiast `../../../components`
8196
**Przykład:**
97+
8298
```typescript
8399
// Zamiast:
84-
import { Button } from '../../../components/ui/Button';
100+
import { Button } from "../../../components/ui/Button";
85101

86102
// Piszesz:
87-
import { Button } from '@/components/ui/Button';
103+
import { Button } from "@/components/ui/Button";
88104
```
89105

90106
## 🚀 Jak używać
91107

92108
### Podstawowe komendy
109+
93110
```bash
94111
# Watch mode (rekomendowane podczas developmentu)
95112
npm run test
@@ -106,6 +123,7 @@ npm run test:coverage
106123
```
107124

108125
### Pierwszy test
126+
109127
```typescript
110128
// src/components/Button.test.tsx
111129
import { render, screen } from '@testing-library/react';
@@ -120,6 +138,7 @@ describe('Button', () => {
120138
```
121139

122140
### Uruchom:
141+
123142
```bash
124143
npm run test
125144
# Vitest automatycznie znajdzie *.test.tsx
@@ -128,22 +147,28 @@ npm run test
128147
## 💡 Tipsy dla początkujących
129148

130149
### 1. Używaj Watch Mode
150+
131151
```bash
132152
npm run test
133153
```
154+
134155
Vitest automatycznie uruchomi testy gdy zapiszesz plik!
135156

136157
### 2. Używaj UI Mode do debugowania
158+
137159
```bash
138160
npm run test:ui
139161
```
162+
140163
Zobaczysz GUI z:
164+
141165
- Listą wszystkich testów
142166
- Wynikami w czasie rzeczywistym
143167
- Stack traces
144168
- Console logi
145169

146170
### 3. Filtruj testy podczas developmentu
171+
147172
```bash
148173
# Tylko testy z "Button" w nazwie
149174
npm run test -- Button
@@ -153,9 +178,11 @@ npm run test -- src/components/Button.test.tsx
153178
```
154179

155180
### 4. Nie martw się o coverage na początku
181+
156182
Zacznij od pisania testów, coverage przyjdzie z czasem.
157183

158184
Kiedy sprawdzać coverage:
185+
159186
- Przed mergem do main
160187
- Co jakiś czas, żeby zobaczyć progress
161188

@@ -168,6 +195,7 @@ npm run test:coverage
168195
## 🎓 Dobre praktyki
169196

170197
### 1. Jeden plik testowy na komponent
198+
171199
```
172200
src/
173201
components/
@@ -176,38 +204,42 @@ src/
176204
```
177205

178206
### 2. Grupuj testy w describe
207+
179208
```typescript
180-
describe('Button', () => {
181-
describe('when disabled', () => {
182-
it('should not call onClick', () => {
209+
describe("Button", () => {
210+
describe("when disabled", () => {
211+
it("should not call onClick", () => {
183212
// test
184213
});
185214
});
186215

187-
describe('when enabled', () => {
188-
it('should call onClick', () => {
216+
describe("when enabled", () => {
217+
it("should call onClick", () => {
189218
// test
190219
});
191220
});
192221
});
193222
```
194223

195224
### 3. Używaj opisowych nazw testów
225+
196226
```typescript
197227
// ❌ Źle
198-
it('works', () => {});
228+
it("works", () => {});
199229

200230
// ✅ Dobrze
201-
it('should call onClick when button is clicked', () => {});
231+
it("should call onClick when button is clicked", () => {});
202232
```
203233

204234
### 4. Najpierw funkcjonalność, potem coverage
235+
205236
Nie pisz testów tylko po to żeby mieć 100% coverage.
206237
Pisz testy które testują **zachowanie** Twojej aplikacji.
207238

208239
## ⚙️ Kiedy zmienić ustawienia
209240

210241
### Masz już stabilne testy i chcesz wyższych standardów?
242+
211243
```typescript
212244
thresholds: {
213245
lines: 80,
@@ -218,15 +250,19 @@ thresholds: {
218250
```
219251

220252
### Potrzebujesz LCOV dla CI/CD?
253+
221254
```typescript
222255
reporter: ["text", "html", "lcov"],
223256
```
257+
224258
LCOV używa się do integracji z narzędziami jak Codecov.
225259

226260
### Chcesz testować bez DOM (czyste funkcje)?
261+
227262
```typescript
228263
environment: "node", // Zamiast "jsdom"
229264
```
265+
230266
Szybsze, ale nie zadziała dla komponentów React!
231267

232268
## ❓ FAQ
@@ -268,4 +304,3 @@ A: Nie! 60-80% to dobry cel. 100% często oznacza testowanie implementacji zamia
268304
### Wszystko inne jest OK! ✅
269305

270306
Config był już dobry, tylko lekko zoptymalizowany dla początkującego.
271-

0 commit comments

Comments
 (0)