Skip to content

Commit 2889794

Browse files
committed
chore: add prettier, lint-staged, and hardened git hooks
- Add prettier + lint-staged for auto-formatting on commit - pre-commit: lint-staged (format) + astro check + test:unit + no-.only guard - pre-push: build check + full test suite (unit + e2e) - Add .prettierignore, .prettierrc config - Format entire codebase with prettier - Add npm scripts: format, format:check
1 parent fa7ac80 commit 2889794

45 files changed

Lines changed: 2967 additions & 2016 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.husky/pre-commit

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
1-
npm run check && npm run test:unit
1+
# Check for .only() in test files
2+
if grep -r "\.only(" tests/ --include="*.ts" 2>/dev/null; then
3+
echo "❌ Found .only() in tests! Remove before committing."
4+
exit 1
5+
fi
6+
7+
# Run lint-staged (prettier + astro check + tsc on changed files)
8+
npx lint-staged
9+
10+
# Run unit tests
11+
npm run test:unit

.husky/pre-push

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
echo "Running pre-push tests..."
2+
3+
# Ensure it builds
4+
npm run build || { echo "❌ Build failed!"; exit 1; }
5+
6+
# Run full test suite
27
npm run test

.prettierignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.agent
2+
.astro
3+
.claude
4+
.git
5+
.github
6+
.husky/_
7+
dist
8+
node_modules
9+
playwright-report
10+
test-results
11+
package-lock.json

.prettierrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"semi": true,
3+
"singleQuote": true,
4+
"trailingComma": "all",
5+
"printWidth": 100,
6+
"tabWidth": 2
7+
}

TESTING.md

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,48 @@
33
This project uses a robust testing pipeline combining Vitest and Playwright to ensure the `GameBoy` component and site functionality work flawlessly across browsers.
44

55
## 1. Unit Testing (Vitest)
6+
67
Unit tests focus on isolated logic and utility functions that don't depend on browser rendering.
78

8-
* **Location:** `tests/unit/`
9-
* **Config:** `vitest.config.ts`
10-
* **Command:** `npm run test:unit`
9+
- **Location:** `tests/unit/`
10+
- **Config:** `vitest.config.ts`
11+
- **Command:** `npm run test:unit`
1112

1213
## 2. End-to-End Testing (Playwright)
14+
1315
E2E tests simulate real user interactions in a browser environment. The suite covers 100% of the interactive features of the device.
1416

15-
* **Location:** `tests/e2e/gameboy.spec.ts`
16-
* **Config:** `playwright.config.ts`
17-
* **Command:** `npm run test:e2e`
17+
- **Location:** `tests/e2e/gameboy.spec.ts`
18+
- **Config:** `playwright.config.ts`
19+
- **Command:** `npm run test:e2e`
1820

1921
### Test Coverage
22+
2023
The E2E suite verifies the following user stories:
24+
2125
1. **Boot Sequence**: Ensures the start overlay appears and is dismissible via keyboard interaction.
2226
2. **Navigation**:
23-
* **D-Pad**: Verifies Up/Down navigation correctly updates active links.
24-
* **Tabs**: Verifies Left/Right navigation switches between Links, About, and Help tabs.
27+
- **D-Pad**: Verifies Up/Down navigation correctly updates active links.
28+
- **Tabs**: Verifies Left/Right navigation switches between Links, About, and Help tabs.
2529
3. **Selection**: Validates that pressing 'Enter' (A button) triggers link navigation.
2630
4. **Theming**: Checks that switching themes (B button) updates the DOM and persists across page reloads (via `localStorage`).
2731
5. **Audio**: Confirms toggling mute (M key) updates state and persists across reloads.
2832
6. **Hardware Features**:
29-
* **Power Switch**: Verifies the power switch toggles the console on/off.
30-
* **Konami Code**: Inputs the secret code (Up, Up, Down, Down, Left, Right, Left, Right, B, A) and verifies the "Matrix Mode" visual effect.
33+
- **Power Switch**: Verifies the power switch toggles the console on/off.
34+
- **Konami Code**: Inputs the secret code (Up, Up, Down, Down, Left, Right, Left, Right, B, A) and verifies the "Matrix Mode" visual effect.
3135

3236
## 3. Static Analysis
37+
3338
Validates `.astro` file syntax and TypeScript types.
3439

35-
* **Command:** `npm run check` (runs `astro check`)
40+
- **Command:** `npm run check` (runs `astro check`)
3641

3742
## CI/CD Pipeline
43+
3844
A GitHub Actions workflow (`.github/workflows/ci.yml`) runs on every push to `main` and pull requests.
3945

4046
**Workflow Steps:**
47+
4148
1. **Install**: Sets up Node.js and dependencies.
4249
2. **Check**: Runs static analysis.
4350
3. **Unit Tests**: Executes Vitest suite.
@@ -46,6 +53,7 @@ A GitHub Actions workflow (`.github/workflows/ci.yml`) runs on every push to `ma
4653
6. **Artifacts**: Uploads failure traces and videos if tests fail.
4754

4855
## Pre-Push Hooks (Husky)
56+
4957
To catch errors before they event reach the CI pipeline, this project uses [Husky](https://typicode.github.io/husky/) to enforce local testing before pushing code to the remote repository.
5058

5159
A `pre-push` hook is configured (in `.husky/pre-push`) to automatically run `npm run test` (which triggers both Unit Tests and E2E Tests) whenever `git push` is invoked locally. If any tests fail, the push is aborted.
@@ -55,13 +63,17 @@ This prevents the codebase from bloated `pre-commit` times, while guaranteeing t
5563
## Debugging
5664

5765
### Interactive Mode (UI)
66+
5867
To debug tests visually, use the Playwright UI mode. This allows you to step through tests, time-travel, and inspect the DOM.
68+
5969
```bash
6070
npx playwright test --ui
6171
```
6272

6373
### Viewing Reports
74+
6475
Playwright generates an HTML report for each run.
76+
6577
```bash
6678
npx playwright show-report
6779
```

0 commit comments

Comments
 (0)