Skip to content

Commit 7e5e7a0

Browse files
authored
test(svg-constants-type-compiler): verify TypeScript Compiler Validation & Schema Constraints Stability (JhaSourav07#3229)
## Description Creates lib/svg/constants.type-compiler.test.ts with 5 type-level tests using Vitest's expectTypeOf to assert that all exported constants from lib/svg/constants.ts carry the correct TypeScript types at compile time. **Tests:** 1. Numeric dimension constants (SVG_WIDTH, SVG_HEIGHT, GHOST_HEIGHT_PX, MAX_LOG_HEIGHT, MAX_LINEAR_HEIGHT) are typed as number 2. Scale multiplier constants (LOG_SCALE_MULTIPLIER, LINEAR_SCALE_MULTIPLIER) are typed as number 3. FONT_MAP is typed as Record<string, string> — not Record<string, number> or any wider type 4. CONTRIBUTION_MILESTONES is typed as number[] with numeric elements 5. All numeric constants satisfy a number parameter constraint — verifying they can be passed to any function expecting number without type errors Fixes JhaSourav07#2892 ## Pillar - [ ] 🎨 Pillar 1 — New Theme Design - [ ] 📐 Pillar 2 — Geometric SVG Improvement - [ ] 🕐 Pillar 3 — Timezone Logic Optimization - [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview N/A ## Checklist before requesting a review: - [x] I have read the `CONTRIBUTING.md` file. - [x] I have tested these changes locally (`localhost:3000/api/streak?user=YOUR_USERNAME`). - [x] I have run `npm run format` and `npm run lint` locally and resolved all errors (CI will fail otherwise). - [x] My commits follow the Conventional Commits format (e.g., `feat(themes): ...`, `fix(calculate): ...`). - [x] I have updated `README.md` if I added a new theme or URL parameter. - [x] I have started the repo. - [x] I have made sure that i have only one commit to merge in this PR. - [x] The SVG output matches the CommitPulse "premium quality" aesthetic standard (no raw elements, smooth animations, correct fonts). - [x] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.
2 parents a238f9c + 2472938 commit 7e5e7a0

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { describe, expectTypeOf, it } from 'vitest';
2+
import {
3+
CONTRIBUTION_MILESTONES,
4+
FONT_MAP,
5+
GHOST_HEIGHT_PX,
6+
LINEAR_SCALE_MULTIPLIER,
7+
LOG_SCALE_MULTIPLIER,
8+
MAX_LINEAR_HEIGHT,
9+
MAX_LOG_HEIGHT,
10+
SVG_HEIGHT,
11+
SVG_WIDTH,
12+
} from './constants';
13+
14+
describe('lib/svg/constants — TypeScript type compiler', () => {
15+
it('numeric dimension constants are typed as number', () => {
16+
expectTypeOf(SVG_WIDTH).toBeNumber();
17+
expectTypeOf(SVG_HEIGHT).toBeNumber();
18+
expectTypeOf(GHOST_HEIGHT_PX).toBeNumber();
19+
expectTypeOf(MAX_LOG_HEIGHT).toBeNumber();
20+
expectTypeOf(MAX_LINEAR_HEIGHT).toBeNumber();
21+
});
22+
23+
it('scale multiplier constants are typed as number', () => {
24+
expectTypeOf(LOG_SCALE_MULTIPLIER).toBeNumber();
25+
expectTypeOf(LINEAR_SCALE_MULTIPLIER).toBeNumber();
26+
});
27+
28+
it('FONT_MAP satisfies Record<string, string> — keys and values are both strings', () => {
29+
expectTypeOf(FONT_MAP).toEqualTypeOf<Record<string, string>>();
30+
expectTypeOf(FONT_MAP).not.toEqualTypeOf<Record<string, number>>();
31+
});
32+
33+
it('CONTRIBUTION_MILESTONES satisfies a readonly number array and its elements are numbers', () => {
34+
expectTypeOf(CONTRIBUTION_MILESTONES).toEqualTypeOf<number[]>();
35+
expectTypeOf(CONTRIBUTION_MILESTONES).items.toBeNumber();
36+
});
37+
38+
it('a function accepting number accepts all numeric constants without type errors', () => {
39+
const requiresNumber = (n: number): number => n;
40+
41+
expectTypeOf(requiresNumber).parameter(0).toBeNumber();
42+
// Verify each constant satisfies the number parameter type
43+
expectTypeOf(SVG_WIDTH).toEqualTypeOf<Parameters<typeof requiresNumber>[0]>();
44+
expectTypeOf(SVG_HEIGHT).toEqualTypeOf<Parameters<typeof requiresNumber>[0]>();
45+
expectTypeOf(LOG_SCALE_MULTIPLIER).toEqualTypeOf<Parameters<typeof requiresNumber>[0]>();
46+
expectTypeOf(LINEAR_SCALE_MULTIPLIER).toEqualTypeOf<Parameters<typeof requiresNumber>[0]>();
47+
});
48+
});

0 commit comments

Comments
 (0)