Skip to content

Teach testing with a stricter CI - #42

Merged
gpbsumido merged 5 commits into
ps/ng-10-directivesfrom
ps/ng-11-testing
Nov 21, 2026
Merged

gpbsumido merged 5 commits into
ps/ng-10-directivesfrom
ps/ng-11-testing

Conversation

@gpbsumido

@gpbsumido gpbsumido commented Nov 21, 2026 •

Copy link
Copy Markdown
Owner

Eleventh lesson in my Angular guide: testing. The feature slice is a CI workflow that checks what actually ships.

What shipped

CI's typecheck checks real files. It ran npx tsc --noEmit against a root tsconfig.json with "files": [] and only project references.

  • Plain tsc doesn't follow references, so it listed 0 source files and passed. With -p tsconfig.app.json, it lists 72.
  • It now typechecks tsconfig.app.json and tsconfig.spec.json.

CI runs the production build. It's the only step that prerenders every route and enforces the bundle budget.

Every job has timeout-minutes. While working on change detection, I hit an ng build / ng test that finished its work and never exited. Without a limit, that holds a runner for GitHub's six-hour default.

  • quality gets 15 minutes and e2e-accessibility gets 20.
  • The job names are unchanged, so nothing that references the checks by name moves.

ci-workflow.spec.ts pins all three. It's a fitness test over .github/workflows/ci.yml.

e2e/lesson-nav.spec.ts. It covers the lesson nav from #41 in a real browser: jumping focuses the heading, and the highlight follows real scrolling. The unit specs can only drive a fake IntersectionObserver.

A correction to #40. That PR's comment on the contact form said form.reset() only re-rendered the OnPush view because a signal write sat next to it. A test I wrote here to pin that claim passed without the signal write.

  • Reactive form controls keep touched and status in signals, and NgControlStatus reads them in its host bindings (forms.mjs, AbstractControlStatus.isTouched).
  • The new spec in contact-app.spec.ts resets the form with no other change and no detectChanges(), and the errors clear.
  • The comment and the lesson 09 intro are corrected. The lesson 11 page tells the story as a pitfall.

Lesson 11: testing (/thoughts/angular-11-testing).

  • Covers the material at three levels (simple, intermediate, expert), then pitfalls and interview Q&A:
    • component specs with axe
    • HttpTestingController with fake timers
    • RouterTestingHarness and setInput
    • marble tests
    • fitness tests
    • when e2e earns its place
    • component harnesses
  • The quoted specs are excerpts of the real ones in this repo.
  • The live demo runs the real notBlank validator's test cases in the page. A switch swaps in lesson 08's whitespace bug, and exactly one test goes red.

Version and changelog. 1.4.10, with a matching changelog entry.

Commits

  1. Add failing specs for CI gaps, lesson 11 and the lesson nav e2e
  2. Correct the contact form reset comment, with a test
  3. Make CI typecheck real files, build, and time out
  4. Write lesson 11 with a run-the-tests demo
  5. Bump to 1.4.10 with the lesson 11 changelog entry

Verification

  • RED first. The CI spec failed on the three gaps: no -p typecheck, no build, no timeout on quality.
    • My first version split the YAML wrong and checked the on: block instead of the jobs. I saw that in the RED output and fixed it before committing.
  • Tests. ng test: 66 files, 462 tests, exit 0.
  • Static checks. Lint and both tsc --noEmit configs are clean. The e2e file typechecks with tsc --strict.
  • Production build. Exit 0, 80 routes (testing was already a tag). Initial bundle 394.92 kB.
    • The prerendered lesson shows "Part 11 of 11" and the demo controls.
  • Not run: the e2e test. Chromium can't launch where I built this, so its first run will be in CI. CI only triggers for PRs into develop, so on this stacked branch that happens once the stack reaches develop.

TO-DOs for this PR

  • Run npx playwright test e2e/lesson-nav.spec.ts locally before merging, and tune the 30% trigger band in scroll-spy.ts if the highlight lags.
  • Before/after screenshots of the lesson 11 demo with the bug switched on, light and dark.

CI's typecheck runs plain tsc against a root tsconfig with no files, so it
checks nothing. CI never builds, and no job has a time limit. The e2e
covers what the fake IntersectionObserver can't: real scrolling.
Lesson 09 said form.reset() only re-rendered the OnPush contact form
because a signal write sat next to it. It renders on its own: controls
keep touched and status in signals, and NgControlStatus reads them in
its host bindings. The new spec resets the form with no other change and
no detectChanges(), and the errors clear.
The root tsconfig has no files, so plain tsc --noEmit checked nothing.
Typecheck the app and spec configs, run the production build (the only
step that prerenders and enforces budgets), and give each job a time
limit so a hung builder can't hold a runner for six hours.
The demo runs the real notBlank validator's cases in the page, with a
switch that swaps in the whitespace bug lesson 08 fixed so exactly one
test goes red.
@gpbsumido
gpbsumido marked this pull request as ready for review November 21, 2026 16:25
@gpbsumido
gpbsumido added this pull request to stack #46 November 21, 2026 17:00
@gpbsumido
gpbsumido merged commit 530c68f into develop Nov 21, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant