Skip to content

Commit b124f6b

Browse files
authored
docs(contributing): add Testing Your Changes section with SVG preview… (JhaSourav07#1602)
## Description Fixes JhaSourav07#1343 ## Pillar - [x] 🛠️ Other (Bug fix, refactoring, docs) ## What this PR does Adds a new "🧪 Testing Your Changes" section to CONTRIBUTING.md between the Local Setup and Contributor Onboarding sections. The new section covers: - Visual browser preview URLs for testing valid badges, monthly view, custom themes, invalid usernames, and non-existent usernames - An explanation of the common EntityRef XML parse error and how to fix it - How to run the Vitest test suite (npm run test, watch mode, single file) - A table mapping browser output to pass/fail status so contributors know exactly what a working vs broken response looks like - Lint and format commands to run before every commit Previously, CONTRIBUTING.md mentioned running npm run test and visiting localhost:3000 in passing, but never explained what URLs to visit, what correct output looks like, or how to interpret errors. New contributors (especially during GSSoC) had no way to verify their changes without asking a maintainer. ## Visual Preview N/A — documentation change only, no SVG output affected. ## Checklist before requesting a review: - [x] I have read the CONTRIBUTING.md file. - [x] I have tested these changes locally. - [x] I have run npm run format and npm run lint locally and resolved all errors. - [x] My commits follow the Conventional Commits format. - [x] I have starred the repo. - [x] I have made sure that I have only one commit to merge in this PR.
2 parents 2e7f89d + f496ff9 commit b124f6b

1 file changed

Lines changed: 105 additions & 0 deletions

File tree

CONTRIBUTING.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
- [The Standard We Hold](#-the-standard-we-hold)
1111
- [Local Setup](#-local-setup)
12+
- [Testing Your Changes](#-testing-your-changes)
1213
- [What to Contribute](#-what-to-contribute)
1314
- [Automated Issue Management & Claiming](#-automated-issue-management--claiming)
1415
- [Branch & Commit Conventions](#-branch--commit-conventions)
@@ -88,6 +89,110 @@ http://localhost:3000/api/streak?user=YOUR_GITHUB_USERNAME
8889
8990
---
9091

92+
## 🧪 Testing Your Changes
93+
94+
This section covers everything you need to verify your changes work correctly **before opening a PR**. There are two layers of testing: visual browser preview and the automated test suite.
95+
96+
### 1. Visual Browser Preview
97+
98+
With your dev server running (`npm run dev`), open your browser and visit these URLs to preview the SVG output directly:
99+
100+
**Standard badge — valid username:**
101+
102+
```
103+
http://localhost:3000/api/streak?user=YOUR_GITHUB_USERNAME
104+
```
105+
106+
**Monthly view:**
107+
108+
```
109+
http://localhost:3000/api/streak?user=YOUR_GITHUB_USERNAME&view=monthly
110+
```
111+
112+
**Custom theme — test your color changes:**
113+
114+
```
115+
http://localhost:3000/api/streak?user=YOUR_GITHUB_USERNAME&theme=YOUR_THEME_NAME
116+
```
117+
118+
**Invalid username — must render a styled SVG error card, not raw JSON:**
119+
120+
```
121+
http://localhost:3000/api/streak?user=vivek%20Sangani
122+
```
123+
124+
**Non-existent username — must render the ghost-city not-found badge:**
125+
126+
```
127+
http://localhost:3000/api/streak?user=xyzabc999notreallll
128+
```
129+
130+
> **⚠️ Browser XML error warning:** If your browser shows an `EntityRef: expecting ';'` error instead of rendering the SVG, it means an unescaped `&` character exists somewhere in the SVG output. All `&` characters inside SVG `<style>` blocks (e.g. in Google Fonts `@import` URLs) must be written as `&amp;`. Check `lib/svg/generator.ts` for any raw `&` in template literals.
131+
132+
> **💡 Tip:** For a cleaner SVG preview, open the URL in **Firefox** — it renders SVG directly in the browser with no wrapper page. Chrome wraps it in an XML viewer which can show false parse warnings.
133+
134+
### 2. Running the Vitest Test Suite
135+
136+
CommitPulse uses **Vitest** for unit and integration tests. Run the full test suite with:
137+
138+
```bash
139+
npm run test
140+
```
141+
142+
To run tests in watch mode while you develop (reruns on every file save):
143+
144+
```bash
145+
npm run test -- --watch
146+
```
147+
148+
To run only a specific test file:
149+
150+
```bash
151+
npm run test -- lib/calculate.test.ts
152+
```
153+
154+
**What a passing run looks like:**
155+
156+
```
157+
✓ lib/calculate.test.ts (12 tests)
158+
✓ lib/svg/generator.test.ts (8 tests)
159+
✓ app/api/streak/route.test.ts (6 tests)
160+
161+
Test Files 3 passed (3)
162+
Tests 26 passed (26)
163+
```
164+
165+
> **🚨 All tests must pass before you open a PR.** The CI pipeline runs `npm run test` automatically on every pull request and will block merging if any test fails.
166+
167+
### 3. Interpreting SVG Output in the Browser
168+
169+
When you open a badge URL in your browser, here is what each response means:
170+
171+
| What you see | What it means |
172+
| -------------------------------------------- | ---------------------------------------------------------- |
173+
| Animated isometric city renders correctly | ✅ Everything is working |
174+
| Ghost-city badge with "NOT FOUND" label | ✅ Working — the username doesn't exist on GitHub |
175+
| Styled error card with "Invalid username" | ✅ Working — the username format was invalid |
176+
| Raw JSON `{"error":"Invalid parameters"...}` | ❌ Bug — validation errors must return SVG, not JSON |
177+
| Browser XML parse error / blank white page | ❌ Bug — unescaped `&` or malformed SVG in generator |
178+
| `401 Unauthorized` in the terminal | ❌ Your `GITHUB_PAT` in `.env.local` is missing or invalid |
179+
180+
### 4. Lint and Format
181+
182+
Run these before every commit:
183+
184+
```bash
185+
# Auto-format all files
186+
npm run format
187+
188+
# Check for linting errors
189+
npm run lint
190+
```
191+
192+
Fix every error before pushing. CI will fail if either check reports issues.
193+
194+
---
195+
91196
## 🤝 Contributor Onboarding
92197

93198
### 📁 Project Structure

0 commit comments

Comments
 (0)