Skip to content

Commit ab01a7a

Browse files
committed
docs: add polish and clarity improvements to test suite
Documentation improvements: - Add environment assumptions to git integration tests Tests now clearly document they require git clone with origin remote - Add "Environment Requirements" section to README_contributors.md - Document gh-pages internal API dependency and upgrade process Explains getRemoteUrl dependency on gh-pages/lib/git (internal API) Provides clear upgrade path for v6 with fallback options Comment improvements: - Fix "EXCEPTION" comment in engine.spec.ts to match CLAUDE.md policy .toContain() is allowed for variable strings, not an exception - Add provenance comments to error message assertions Document exact gh-pages v3.2.3 error messages (lib/git.js lines 213-223) - Add strict whitelist note to EXPECTED_GIT_COMMANDS Explains intentional fail-fast behavior for new git commands in v6 TEST_COVERAGE_PLAN.md updates: - Clarify test count (351) as historical milestone - Document manual upgrade strategy for gh-pages v6 No dual-version harness (intentional) - use manual comparison - Add detailed 5-step upgrade process with failure categorization gh-pages.clean() investigation: - Verified clean() is synchronous in v3.2.3 (uses fs.removeSync) - Determined setTimeout pattern is appropriate (no callback available) All 351 tests passing. Test suite documentation now provides clear upgrade path.
1 parent e29dff7 commit ab01a7a

File tree

5 files changed

+79
-7
lines changed

5 files changed

+79
-7
lines changed

TEST_COVERAGE_PLAN.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,28 @@ Add `"types": "index.d.ts"` to package.json
191191

192192
All behavioral tests for gh-pages v3.2.3 are now complete and provide comprehensive baseline for v6 upgrade.
193193

194+
### 4.3 Upgrade Strategy for gh-pages v6+
195+
196+
**Manual Upgrade Process:**
197+
198+
We intentionally rely on the existing test suite for upgrade verification rather than maintaining a dual-version test harness:
199+
200+
1. **Establish baseline:** Run `npm test` with gh-pages v3.2.3 - all 351 tests should pass
201+
2. **Upgrade:** Update gh-pages dependency to v6.x in package.json
202+
3. **Run tests:** Execute `npm test` with v6 and capture all failures
203+
4. **Analyze failures systematically:**
204+
- Check `engine.prepare-options-helpers.spec.ts` getRemoteUrl tests first (likely internal API changes)
205+
- Review `engine.gh-pages-behavior.spec.ts` for behavioral changes
206+
- Examine `engine.gh-pages-integration.spec.ts` for API signature changes
207+
5. **Categorize each failure:**
208+
- **Expected breaking changes** in gh-pages v6adapt our code
209+
- **Bugs in gh-pages v6**report upstream or work around
210+
- **Our incorrect assumptions about v3**fix our tests
211+
212+
**No Dual-Version Harness:**
213+
214+
We do NOT maintain automated tooling to run tests against both versions simultaneously. This is intentional - the manual comparison process ensures careful evaluation of each change. If automated comparison becomes necessary, it can be added later.
215+
194216
---
195217

196218
## Implementation Order
@@ -215,7 +237,7 @@ All behavioral tests for gh-pages v3.2.3 are now complete and provide comprehens
215237

216238
## Success Criteria
217239

218-
- **Test Count:** 213351 tests (comprehensive suite, see test files for current count)
240+
- **Test Count:** 213351 tests (historical milestone - use `npm test` output for current count)
219241
- **Coverage:**All critical paths tested (error callbacks, monkeypatch, file creation, getRemoteUrl, dotfiles)
220242
- **Refactoring:**prepareOptions split into 6 testable functions
221243
- **Public API:**Types exported via public_api.ts, TypeScript declarations enabled

docs/README_contributors.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ cd angular-cli-ghpages/src
155155
npm test
156156
```
157157

158+
**Environment Requirements:**
159+
160+
Some tests (remote URL discovery and `getRemoteUrl` integration tests) expect to run inside a real git clone of this repository with an `origin` remote configured. Running tests from a zip file or bare copy without `.git` is not supported and will cause test failures.
161+
158162
### 5. Debugging
159163

160164
To debug angular-cli-ghpages you need to:
@@ -247,6 +251,27 @@ const result = await angularDeploy(context, builderConfig, 'your-project-name');
247251

248252
**Note:** The CLI (`ng deploy`) remains the primary and recommended way to use this tool. Programmatic usage is considered advanced/experimental and may change between versions.
249253

254+
## Dependency on gh-pages Internal API
255+
256+
### Remote URL Discovery
257+
258+
The `getRemoteUrl` function in `src/engine/engine.prepare-options-helpers.ts` calls into `gh-pages/lib/git`, which is an **internal API** not documented in gh-pages' public interface. This dependency carries upgrade risk.
259+
260+
**What we depend on:**
261+
- `new Git(process.cwd(), options.git).getRemoteUrl(options.remote)` from `gh-pages/lib/git`
262+
- The exact error message format when remote doesn't exist or not in a git repository
263+
264+
**Upgrade process for gh-pages v6+:**
265+
266+
1. Check test failures in `src/engine/engine.prepare-options-helpers.spec.ts` first, specifically the `getRemoteUrl` test block
267+
2. If those tests fail, it likely indicates a breaking change in gh-pages' internal Git API
268+
3. Options:
269+
- If `gh-pages/lib/git` still exists with same interface: update our error message assertions
270+
- If the internal API changed significantly: implement our own git remote discovery using `child_process.execSync('git config --get remote.{remote}.url')`
271+
- If gh-pages added a public API for this: switch to the public API
272+
273+
**Current baseline:** Tests are pinned to gh-pages v3.2.3 behavior and error messages.
274+
250275
## Keeping track of all the forks
251276

252277
[ngx-deploy-starter](https://github.com/angular-schule/ngx-deploy-starter/) and

src/engine/engine.gh-pages-behavior.spec.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,13 @@ function createMockChildProcess(): Partial<ChildProcess> {
4343
return child;
4444
}
4545

46-
// Whitelist of expected git commands (fail fast on unexpected commands)
46+
/**
47+
* Whitelist of expected git commands from gh-pages v3.2.3
48+
*
49+
* Strict whitelist: If gh-pages adds new git subcommands in v6,
50+
* this array must be updated first and tests will fail loudly.
51+
* This is intentional - we want to know about any new git operations.
52+
*/
4753
const EXPECTED_GIT_COMMANDS = [
4854
'clone', 'clean', 'fetch', 'checkout', 'ls-remote', 'reset',
4955
'rm', 'add', 'config', 'diff-index', 'commit', 'tag', 'push', 'update-ref'

src/engine/engine.prepare-options-helpers.spec.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,14 @@ describe('prepareOptions helpers - intensive tests', () => {
590590
* comment in engine.prepare-options-helpers.ts for fallback options.
591591
*/
592592

593+
/**
594+
* Environment assumptions for this test:
595+
* - Tests must be run from a git clone of angular-schule/angular-cli-ghpages
596+
* - The "origin" remote must exist and point to that repository
597+
* - git must be installed and on PATH
598+
*
599+
* If run from a bare copy of files (no .git), this test will fail by design.
600+
*/
593601
it('should return correct URL from git config and be consistent', async () => {
594602
// This test verifies the internal API returns ACTUAL git config values
595603
const options = { remote: 'origin' };
@@ -613,7 +621,8 @@ describe('prepareOptions helpers - intensive tests', () => {
613621
remote: 'nonexistent-remote-12345' // Remote that definitely doesn't exist
614622
};
615623

616-
// gh-pages v3.2.3 throws this exact error message for non-existent remotes
624+
// Expected message from gh-pages v3.2.3 (lib/git.js lines 213-223)
625+
// If this fails after upgrading gh-pages, the internal API changed
617626
await expect(helpers.getRemoteUrl(options))
618627
.rejects
619628
.toThrow('Failed to get remote.nonexistent-remote-12345.url (task must either be run in a git repository with a configured nonexistent-remote-12345 remote or must be configured with the "repo" option).');
@@ -629,7 +638,8 @@ describe('prepareOptions helpers - intensive tests', () => {
629638
process.chdir(tempDir);
630639
const options = { remote: 'origin' };
631640

632-
// gh-pages v3.2.3 throws this exact error message when not in a git repo
641+
// Expected message from gh-pages v3.2.3 (lib/git.js lines 213-223)
642+
// Note: gh-pages returns same error for both "not in git repo" and "remote doesn't exist"
633643
await expect(helpers.getRemoteUrl(options))
634644
.rejects
635645
.toThrow('Failed to get remote.origin.url (task must either be run in a git repository with a configured origin remote or must be configured with the "repo" option).');

src/engine/engine.spec.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,24 @@ describe('engine', () => {
9090
});
9191

9292
// NEW in 0.6.2: always discover remote URL (if not set)
93+
/**
94+
* Environment assumptions for this test:
95+
* - Tests must be run from a git clone of angular-schule/angular-cli-ghpages
96+
* - The "origin" remote must exist and point to that repository
97+
* - git must be installed and on PATH
98+
*
99+
* If run from a bare copy of files (no .git), this test will fail by design.
100+
*/
93101
// this allows us to inject tokens from environment even if --repo is not set manually
94102
// it uses gh-pages lib directly for this
95103
it('should discover the remote url, if no --repo is set', async () => {
96104
const options = {};
97105
const finalOptions = await engine.prepareOptions(options, logger);
98106

99-
// EXCEPTION to testing philosophy: Use .toContain() here because the protocol
100-
// (SSH: git@github.com: vs HTTPS: https://github.com/) depends on developer's
101-
// git config. We only care that the correct repo is discovered.
107+
// Justification for .toContain():
108+
// The protocol (SSH vs HTTPS) depends on developer's git config.
109+
// Our testing philosophy allows .toContain() for substrings in long/variable messages.
110+
// We only care that the correct repo path is discovered.
102111
expect(finalOptions.repo).toContain('angular-schule/angular-cli-ghpages');
103112
});
104113

0 commit comments

Comments
 (0)