Skip to content

Commit e48131f

Browse files
authored
merge: test(GeneratorClient-type-compiler): verify TypeScript Compiler Validation & Schema Constraints Stability (Variation 10) (#7833)
## Description Fixes #6912 This PR introduces an isolated TypeScript compiler type-safety and validation schema constraint test suite for the `GeneratorClient` component. It asserts that: - Core types and property configurations on `GeneratorState`, `Technology`, and `Social` are strictly enforced. - Invalid configurations/parameters (e.g. incorrect graph placements or non-array technologies) are blocked with compile-time assertions (`@ts-expect-error`). - Optional/nullable properties inside `GitHubUser` data interfaces compile cleanly without strict type mismatches. - Exported helper structures (`mapGitHubData`) enforce strict parameter configurations and return type constraints. ## Pillar - [ ] 🎨 Pillar 1 — New Theme Design - [ ] 📐 Pillar 2 — Geometric SVG Improvement - [ ] 🕐 Pillar 3 — Timezone Logic Optimization - [x] 🛠️ Other (Bug fix, refactoring, docs, testing) ## Visual Preview N/A (This PR only adds type compiler tests) ## 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 (e.g., `feat(themes): ...`, `fix(calculate): ...`). - [x] I have updated `README.md` if I added a new theme or URL parameter. - [x] I have starred 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.
2 parents 21479c6 + 607e2d9 commit e48131f

1 file changed

Lines changed: 109 additions & 0 deletions

File tree

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import { describe, expectTypeOf, it } from 'vitest';
2+
import { GeneratorClient } from './GeneratorClient';
3+
import type {
4+
GeneratorState,
5+
Technology,
6+
Social,
7+
TechCategory,
8+
SocialCategory,
9+
IconType,
10+
} from './types';
11+
import type {
12+
GitHubUser,
13+
GitHubRepo,
14+
GitHubSocialAccount,
15+
ImportedData,
16+
} from './utils/githubMapper';
17+
import { mapGitHubData } from './utils/githubMapper';
18+
19+
describe('GeneratorClient TypeScript Compiler Validation', () => {
20+
// 1. Use type-testing assertions (expectTypeOf) to enforce field property configurations.
21+
it('enforces field property configurations of GeneratorState', () => {
22+
expectTypeOf<GeneratorState['name']>().toEqualTypeOf<string>();
23+
expectTypeOf<GeneratorState['description']>().toEqualTypeOf<string>();
24+
expectTypeOf<GeneratorState['selectedTechs']>().toEqualTypeOf<string[]>();
25+
expectTypeOf<GeneratorState['selectedSocials']>().toEqualTypeOf<string[]>();
26+
expectTypeOf<GeneratorState['socialLinks']>().toEqualTypeOf<Record<string, string>>();
27+
expectTypeOf<GeneratorState['githubUsername']>().toEqualTypeOf<string>();
28+
expectTypeOf<GeneratorState['showCommitPulse']>().toEqualTypeOf<boolean>();
29+
expectTypeOf<GeneratorState['commitPulseAccent']>().toEqualTypeOf<string>();
30+
expectTypeOf<GeneratorState['showRepoSpotlight']>().toEqualTypeOf<boolean>();
31+
expectTypeOf<GeneratorState['spotlightRepo']>().toEqualTypeOf<string>();
32+
expectTypeOf<GeneratorState['showSnakeGraph']>().toEqualTypeOf<boolean>();
33+
expectTypeOf<GeneratorState['showPacmanGraph']>().toEqualTypeOf<boolean>();
34+
expectTypeOf<GeneratorState['graphPlacement']>().toEqualTypeOf<'top' | 'middle' | 'bottom'>();
35+
});
36+
37+
// 2. Assert that invalid prop parameters are blocked during static type checking.
38+
it('blocks invalid prop parameters during static type checking', () => {
39+
// GeneratorClient has no props
40+
expectTypeOf(GeneratorClient).toBeFunction();
41+
42+
void ({
43+
name: 'John Doe',
44+
description: 'Bio details',
45+
selectedTechs: [],
46+
selectedSocials: [],
47+
socialLinks: {},
48+
githubUsername: 'john',
49+
showCommitPulse: true,
50+
commitPulseAccent: '#ff0000',
51+
showRepoSpotlight: false,
52+
spotlightRepo: '',
53+
showSnakeGraph: false,
54+
showPacmanGraph: false,
55+
// @ts-expect-error graphPlacement must be 'top' | 'middle' | 'bottom'
56+
graphPlacement: 'left',
57+
} satisfies GeneratorState);
58+
59+
void ({
60+
name: 'John Doe',
61+
description: 'Bio details',
62+
// @ts-expect-error selectedTechs must be array of strings
63+
selectedTechs: 'react',
64+
selectedSocials: [],
65+
socialLinks: {},
66+
githubUsername: 'john',
67+
showCommitPulse: true,
68+
commitPulseAccent: '#ff0000',
69+
showRepoSpotlight: false,
70+
spotlightRepo: '',
71+
showSnakeGraph: false,
72+
showPacmanGraph: false,
73+
graphPlacement: 'top',
74+
} satisfies GeneratorState);
75+
});
76+
77+
// 3. Verify custom types accept optional/nullable values without compile errors.
78+
it('verifies custom GitHub data types accept optional/nullable values without compile errors', () => {
79+
const user: GitHubUser = {
80+
name: null,
81+
bio: null,
82+
blog: null,
83+
twitter_username: null,
84+
email: null,
85+
};
86+
87+
expectTypeOf(user.name).toEqualTypeOf<string | null>();
88+
expectTypeOf(user.bio).toEqualTypeOf<string | null>();
89+
});
90+
91+
// 4. Verify field configurations and types for Technology and Social interfaces.
92+
it('verifies Technology and Social interfaces and categories', () => {
93+
expectTypeOf<Technology['category']>().toEqualTypeOf<TechCategory>();
94+
expectTypeOf<Social['category']>().toEqualTypeOf<SocialCategory>();
95+
expectTypeOf<Technology['type']>().toEqualTypeOf<IconType>();
96+
expectTypeOf<Social['type']>().toEqualTypeOf<IconType>();
97+
});
98+
99+
// 5. Verify schema validation constraints return strict validation reports.
100+
it('verifies parameter constraints and return shapes on mapGitHubData', () => {
101+
expectTypeOf(mapGitHubData).parameter(0).toEqualTypeOf<GitHubUser>();
102+
expectTypeOf(mapGitHubData).parameter(1).toEqualTypeOf<GitHubRepo[]>();
103+
expectTypeOf(mapGitHubData).parameter(2).toEqualTypeOf<GitHubSocialAccount[]>();
104+
expectTypeOf(mapGitHubData).returns.toEqualTypeOf<ImportedData>();
105+
106+
// @ts-expect-error mapGitHubData parameter 0 must satisfy GitHubUser structure
107+
void mapGitHubData({ name: 123 }, [], []);
108+
});
109+
});

0 commit comments

Comments
 (0)