Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ jobs:
quality:
name: Lint, Typecheck & Test
runs-on: ubuntu-latest
# A builder that finishes its work and never exits would otherwise hold
# the runner for GitHub's six-hour default.
timeout-minutes: 15

steps:
- uses: actions/checkout@v4
Expand All @@ -25,16 +28,25 @@ jobs:
- name: Lint
run: npm run lint

# The root tsconfig has "files": [] and only references, so a bare
# `tsc --noEmit` checks no files at all. Point it at the real configs.
- name: Typecheck
run: npx tsc --noEmit
run: |
npx tsc --noEmit -p tsconfig.app.json
npx tsc --noEmit -p tsconfig.spec.json

- name: Run unit tests (includes axe accessibility scans)
run: npm test

# The only step that prerenders every route and enforces the bundle budget.
- name: Production build
run: npm run build

e2e-accessibility:
name: E2E & Accessibility
runs-on: ubuntu-latest
needs: quality
timeout-minutes: 20

steps:
- uses: actions/checkout@v4
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

All notable changes to this project will be documented in this file.

## 2026-11-21 - version 1.4.10

- **fix: CI's typecheck checked zero files.** It ran `npx tsc --noEmit` against the root `tsconfig.json`, which has `"files": []` and only project references, so plain `tsc` compiled nothing and passed. 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, and CI never ran it
- **Every CI job has a time limit.** I've seen `ng build` and `ng test` finish their work and then never exit; without `timeout-minutes` that holds a runner for GitHub's six-hour default
- **A spec reads the CI workflow** (`ci-workflow.spec.ts`), so none of the three gaps can come back quietly
- **An e2e test for the lesson nav** (`e2e/lesson-nav.spec.ts`). The unit specs drive a fake `IntersectionObserver`; this one scrolls a real page in Chromium
- **Corrected: the contact form's reset comment.** In 1.4.8 I wrote that `form.reset()` only re-rendered the OnPush contact form because a signal write sat next to it. A new spec shows it renders on its own: reactive form controls keep touched and status in signals, and `NgControlStatus` reads them in its host bindings
- **Angular guide, lesson 11: testing** (`/thoughts/angular-11-testing`). The live demo runs the real `notBlank` validator's tests in the page, with a switch that puts back the bug lesson 08 fixed. The lesson covers component specs, `HttpTestingController` with fake timers, `RouterTestingHarness`, marble tests, fitness tests and when e2e earns its place

## 2026-11-21 - version 1.4.9

- **Every lesson has an "On this page" nav.** It sticks to the top while you read, jumps to a section (moving focus to its heading), and highlights the section in view with `aria-current="location"`. Smooth scrolling switches off under `prefers-reduced-motion`. The lessons had grown long enough that I kept losing my place in them
Expand Down
27 changes: 27 additions & 0 deletions e2e/lesson-nav.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { expect, test } from '@playwright/test';

// The unit specs drive ScrollSpy with a fake IntersectionObserver, which can
// only prove the wiring. Whether the highlight follows real scrolling needs a
// real browser.
test.describe('lesson "On this page" nav', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/thoughts/angular-10-directives');
await expect(page.getByRole('navigation', { name: 'On this page' })).toBeVisible();
});

test('jumping to a section focuses its heading and marks it current', async ({ page }) => {
const nav = page.getByRole('navigation', { name: 'On this page' });
await nav.getByRole('button', { name: 'Pitfalls' }).click();

await expect(page.locator('h2#pitfalls')).toBeFocused();
await expect(nav.getByRole('button', { name: 'Pitfalls' })).toHaveAttribute('aria-current', 'location');
});

test('the highlight follows the reader while scrolling', async ({ page }) => {
await page.locator('h2#expert').evaluate((heading) => heading.scrollIntoView({ block: 'start' }));

const nav = page.getByRole('navigation', { name: 'On this page' });
await expect(nav.getByRole('button', { name: 'Expert' })).toHaveAttribute('aria-current', 'location');
await expect(nav.locator('[aria-current]')).toHaveCount(1);
});
});
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-paul",
"version": "1.4.9",
"version": "1.4.10",
"scripts": {
"ng": "ng",
"start": "ng serve",
Expand Down
17 changes: 17 additions & 0 deletions src/app/apps/contact-app.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,21 @@ describe('ContactApp', () => {
expect(component.form.value.email).toBeFalsy();
expect(component.form.value.message).toBeFalsy();
});

// [ng-11 testing] Pins a correction. Lesson 09 claimed reset() renders only
// because a signal write sits next to it. It renders on its own: each
// formControlName input carries NgControlStatus, whose host bindings read the
// control's touched and status signals. No detectChanges() here on purpose.
it('clears shown errors on reset() alone, with no other state change or event', async () => {
component.form.markAllAsTouched();
fixture.detectChanges();
await fixture.whenStable();
expect(nativeEl.querySelector('.contact-error-name')).toBeTruthy();

component.form.reset();
await fixture.whenStable();

expect(nativeEl.querySelector('.contact-error-name')).toBeNull();
expect(nativeEl.querySelector('.contact-error-email')).toBeNull();
});
});
9 changes: 6 additions & 3 deletions src/app/apps/contact-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,12 @@ export class ContactApp {
this.submissionStatus.set('pending');

// Simulate async submission
// [ng-09 change detection] form.reset() changes plain control state,
// which marks nothing for check. It renders because the signal write next
// to it does. Drop that write and the old errors stay on screen.
// [ng-09 change detection] form.reset() re-renders this OnPush view on its
// own. Controls keep touched and status in signals, and NgControlStatus
// (the directive behind ng-touched/ng-invalid, on every formControlName
// input) reads them in its host bindings. I first thought only the signal
// write below made it render; contact-app.spec.ts has the test that
// proved otherwise.
setTimeout(() => {
this.submissionStatus.set('success');
this.form.reset();
Expand Down
34 changes: 34 additions & 0 deletions src/app/ci-workflow.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { readFileSync } from 'node:fs';
import { resolve } from 'node:path';

/**
* [ng-11 testing] CI is code too, and it can be green while checking nothing.
* These pin the three gaps I found in .github/workflows/ci.yml: a typecheck
* that covered no files, no production build, and no time limit on a job.
*/
const workflow = readFileSync(resolve(process.cwd(), '.github/workflows/ci.yml'), 'utf-8');

describe('[ng-11] CI workflow', () => {
it('the root tsconfig only holds references, so a bare `tsc --noEmit` checks no files', () => {
const root = readFileSync(resolve(process.cwd(), 'tsconfig.json'), 'utf-8');
expect(root).toMatch(/"files":\s*\[\]/);
});

it('typechecks the app and the specs through their own tsconfigs', () => {
expect(workflow).toMatch(/tsc --noEmit -p tsconfig\.app\.json/);
expect(workflow).toMatch(/tsc --noEmit -p tsconfig\.spec\.json/);
});

it('runs the production build, which is the only step that prerenders and enforces budgets', () => {
expect(workflow).toMatch(/run: npm run build/);
});

it('gives every job a time limit, so a hung builder fails in minutes rather than six hours', () => {
const jobs = workflow
.slice(workflow.indexOf('\njobs:\n'))
.split(/\n {2}(?=[\w-]+:\n)/)
.slice(1);
expect(jobs.map((job) => job.slice(0, job.indexOf(':')))).toEqual(['quality', 'e2e-accessibility']);
for (const job of jobs) expect(job).toMatch(/\n {4}timeout-minutes: \d+/);
});
});
58 changes: 58 additions & 0 deletions src/app/thoughts-content/lessons/lesson-11-testing.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import * as axeMatchers from 'vitest-axe/matchers';
import { axe } from '../../../test/a11y';
import { LESSON_PAGES } from './lessons';
import { Lesson11Testing } from './lesson-11-testing';

expect.extend(axeMatchers);

describe('Lesson11Testing', () => {
let fixture: ComponentFixture<Lesson11Testing>;
let el: HTMLElement;

const summary = () => el.querySelector('#demo-test-summary')?.textContent?.trim();
const click = async (selector: string) => {
el.querySelector<HTMLElement>(selector)!.click();
await fixture.whenStable();
};

beforeEach(async () => {
await TestBed.configureTestingModule({ imports: [Lesson11Testing] }).compileComponents();
fixture = TestBed.createComponent(Lesson11Testing);
await fixture.whenStable();
el = fixture.nativeElement as HTMLElement;
});

it('is registered as the lesson page for its thought', () => {
expect(LESSON_PAGES['angular-11-testing']).toBeDefined();
});

it('teaches at three levels, then pitfalls and interview questions', () => {
const headings = [...el.querySelectorAll('h2')].map((h) => h.textContent?.trim());
expect(headings).toEqual(
expect.arrayContaining(['Simple', 'Intermediate', 'Expert', 'Pitfalls', 'Interview questions']),
);
});

it("runs the real notBlank validator's tests in the page, and they pass", async () => {
await click('#demo-run-tests');
expect(summary()).toBe('3 passed');
});

it('putting the lesson 08 bug back makes exactly the whitespace test fail', async () => {
await click('#demo-break');
await click('#demo-run-tests');

expect(summary()).toBe('1 failed, 2 passed');
const failures = [...el.querySelectorAll('.demo-test-result')].filter((li) =>
li.textContent?.includes('FAIL'),
);
expect(failures.map((li) => li.textContent)).toEqual([expect.stringContaining('only spaces')]);
});

it('has no axe violations, with results showing', async () => {
await click('#demo-break');
await click('#demo-run-tests');
expect(await axe(el)).toHaveNoViolations();
});
});
Loading
Loading