Skip to content

Commit 5900e53

Browse files
committed
test: add git prerequisite validation with loud failure messages
Add test-prerequisites.spec.ts that validates git availability and fails loudly with clear, actionable instructions when prerequisites are missing. This ensures tests crash immediately with helpful error messages instead of failing cryptically later. Emphasizes that angular-cli-ghpages is built on top of git and requires: - git executable on PATH - running in a git repository - origin remote configured Each test failure includes installation/fix commands for macOS, Linux, and Windows. Test count: 374 → 377 tests
1 parent c4a5806 commit 5900e53

File tree

1 file changed

+160
-0
lines changed

1 file changed

+160
-0
lines changed

src/test-prerequisites.spec.ts

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
import { execSync } from 'child_process';
2+
3+
/**
4+
* TEST PREREQUISITES VALIDATION
5+
*
6+
* This test suite validates that the required development environment
7+
* is correctly set up. These tests intentionally FAIL LOUDLY with clear
8+
* instructions rather than skipping silently.
9+
*
10+
* angular-cli-ghpages is built on top of git. Without git, nothing works.
11+
*/
12+
13+
describe('Test Prerequisites', () => {
14+
describe('Git availability', () => {
15+
let gitVersion: string;
16+
17+
it('must have git executable available on PATH', () => {
18+
try {
19+
gitVersion = execSync('git --version', { encoding: 'utf8', stdio: 'pipe' }).trim();
20+
} catch (error) {
21+
throw new Error(
22+
'\n\n' +
23+
'====================================================================\n' +
24+
' PREREQUISITE FAILURE: Git is not installed or not on PATH\n' +
25+
'====================================================================\n' +
26+
'\n' +
27+
'angular-cli-ghpages is built on top of git.\n' +
28+
'Tests cannot run without git being available.\n' +
29+
'\n' +
30+
'To fix this:\n' +
31+
'\n' +
32+
' macOS:\n' +
33+
' brew install git\n' +
34+
' # or install Xcode Command Line Tools:\n' +
35+
' xcode-select --install\n' +
36+
'\n' +
37+
' Ubuntu/Debian:\n' +
38+
' sudo apt-get update\n' +
39+
' sudo apt-get install git\n' +
40+
'\n' +
41+
' Windows:\n' +
42+
' Download from https://git-scm.com/download/win\n' +
43+
' # or use winget:\n' +
44+
' winget install Git.Git\n' +
45+
'\n' +
46+
' Verify installation:\n' +
47+
' git --version\n' +
48+
'\n' +
49+
'====================================================================\n'
50+
);
51+
}
52+
53+
// If we got here, git is available
54+
expect(gitVersion).toMatch(/^git version/);
55+
});
56+
57+
it('must be running in a git repository', () => {
58+
// Only run if git is available (previous test passed)
59+
let gitDir: string;
60+
61+
try {
62+
gitDir = execSync('git rev-parse --git-dir', {
63+
encoding: 'utf8',
64+
stdio: 'pipe',
65+
cwd: '/Users/johanneshoppe/Work/angular-schule/angular-cli-ghpages'
66+
}).trim();
67+
} catch (error) {
68+
throw new Error(
69+
'\n\n' +
70+
'====================================================================\n' +
71+
' PREREQUISITE FAILURE: Not running in a git repository\n' +
72+
'====================================================================\n' +
73+
'\n' +
74+
'angular-cli-ghpages tests must run within a git repository.\n' +
75+
'\n' +
76+
'Current directory:\n' +
77+
' /Users/johanneshoppe/Work/angular-schule/angular-cli-ghpages\n' +
78+
'\n' +
79+
'To fix this:\n' +
80+
'\n' +
81+
' If you cloned this repository:\n' +
82+
' # Ensure you are in the correct directory\n' +
83+
' cd /Users/johanneshoppe/Work/angular-schule/angular-cli-ghpages\n' +
84+
' git status\n' +
85+
'\n' +
86+
' If you downloaded as ZIP:\n' +
87+
' # Clone the repository instead:\n' +
88+
' git clone https://github.com/angular-schule/angular-cli-ghpages.git\n' +
89+
' cd angular-cli-ghpages\n' +
90+
'\n' +
91+
' If git was initialized but corrupted:\n' +
92+
' # Check if .git directory exists:\n' +
93+
' ls -la .git\n' +
94+
' # If corrupted, re-clone the repository\n' +
95+
'\n' +
96+
'====================================================================\n'
97+
);
98+
}
99+
100+
// If we got here, we are in a git repository
101+
expect(gitDir).toBeDefined();
102+
expect(gitDir.length).toBeGreaterThan(0);
103+
});
104+
105+
it('must have origin remote configured', () => {
106+
// Only run if git is available and we are in a repo (previous tests passed)
107+
let remoteUrl: string;
108+
109+
try {
110+
remoteUrl = execSync('git config --get remote.origin.url', {
111+
encoding: 'utf8',
112+
stdio: 'pipe',
113+
cwd: '/Users/johanneshoppe/Work/angular-schule/angular-cli-ghpages'
114+
}).trim();
115+
} catch (error) {
116+
throw new Error(
117+
'\n\n' +
118+
'====================================================================\n' +
119+
' PREREQUISITE FAILURE: No origin remote configured\n' +
120+
'====================================================================\n' +
121+
'\n' +
122+
'angular-cli-ghpages tests expect a git origin remote to be configured.\n' +
123+
'\n' +
124+
'To fix this:\n' +
125+
'\n' +
126+
' Add the origin remote:\n' +
127+
' git remote add origin https://github.com/angular-schule/angular-cli-ghpages.git\n' +
128+
'\n' +
129+
' Verify it was added:\n' +
130+
' git remote -v\n' +
131+
'\n' +
132+
' If origin exists but is misconfigured:\n' +
133+
' # View current remotes:\n' +
134+
' git remote -v\n' +
135+
'\n' +
136+
' # Update origin URL:\n' +
137+
' git remote set-url origin https://github.com/angular-schule/angular-cli-ghpages.git\n' +
138+
'\n' +
139+
' Expected origin:\n' +
140+
' https://github.com/angular-schule/angular-cli-ghpages.git\n' +
141+
' or\n' +
142+
' git@github.com:angular-schule/angular-cli-ghpages.git\n' +
143+
'\n' +
144+
'====================================================================\n'
145+
);
146+
}
147+
148+
// If we got here, origin is configured
149+
expect(remoteUrl).toBeDefined();
150+
expect(remoteUrl.length).toBeGreaterThan(0);
151+
// Verify it looks like a valid git URL (either HTTPS or SSH)
152+
expect(
153+
remoteUrl.includes('github.com') ||
154+
remoteUrl.includes('http') ||
155+
remoteUrl.includes('git@')
156+
).toBe(true);
157+
});
158+
});
159+
160+
});

0 commit comments

Comments
 (0)