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
28 changes: 28 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: CI

on:
pull_request:
push:
branches: [master, devin/angular21-base]

concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true

jobs:
build-and-test:
name: Build and unit tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: npm
- run: npm ci
- name: Production build (with service worker)
run: npm run build
- name: Check the service worker was emitted
run: test -f dist/angular-hnpwa/browser/ngsw-worker.js && test -f dist/angular-hnpwa/browser/ngsw.json
- name: Unit tests
run: npm test -- --watch=false
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ Thumbs.db

# Angular cache
/.angular/cache
/.parity-legacy
5 changes: 3 additions & 2 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
"maximumError": "16kB"
}
],
"outputHashing": "all"
"outputHashing": "all",
"serviceWorker": "ngsw-config.json"
},
"development": {
"optimization": false,
Expand Down Expand Up @@ -79,4 +80,4 @@
}
}
}
}
}
2 changes: 1 addition & 1 deletion ngsw-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"/index.html",
"/*.css",
"/*.js",
"/manifest.webmanifest"
"/manifest.json"
]
}
}, {
Expand Down
20 changes: 20 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@angular/forms": "^21.2.0",
"@angular/platform-browser": "^21.2.0",
"@angular/router": "^21.2.0",
"@angular/service-worker": "^21.2.26",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"zone.js": "~0.16.0"
Expand Down
4 changes: 4 additions & 0 deletions parity/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
test-results/
report/html/
report/screenshots/
62 changes: 62 additions & 0 deletions parity/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Parity suite (Playwright)

The same specs run against both apps and check what a user sees:

| Project | App | URL | Node |
|---|---|---|---|
| `legacy` | Angular 9, branch `master` (production build) | http://localhost:4000 | 14 |
| `angular21` | Angular 21, this branch (production build) | http://localhost:4200 | 24 |

| Spec | Covers |
|---|---|
| `specs/feeds.spec.ts` | news list (30 stories, points, author, comment count), More/Prev pagination, header nav (new/show/ask/jobs), jobs header, logo link |
| `specs/story.spec.ts` | story page from the feed, title/domain/points/author, full comment tree, collapse/expand, author link to profile |
| `specs/user.spec.ts` | user profile: id, karma, account age, about |
| `specs/settings.spec.ts` | settings popup, theme toggle (Default/Night/AMOLED) persisted across reload, open links in new tab, font size and list spacing |
| `specs/pwa.spec.ts` | web app manifest, `ngsw.json`, `ngsw-worker.js` registered and the app shell loading offline |

## Run

```bash
cd parity
nvm use 24
npm ci
npx playwright install chromium

npx playwright test # both projects
npx playwright test --project=legacy # Angular 9 only
npx playwright test --project=angular21 # Angular 21 only
npx playwright show-report report/html
```

Playwright starts the servers it needs (`scripts/serve-legacy.sh`, `scripts/serve-angular21.sh`) and reuses
any already listening on 4000/4200:

- `serve-legacy.sh` checks out `origin/master` into `../.parity-legacy` (git worktree, ignored), switches to
Node 14 with nvm, installs, runs `ng build --prod` and serves `dist/angular-hnpwa` on 4000.
Set `LEGACY_DIR` to reuse an existing master checkout, `REBUILD=1` to force a rebuild.
- `serve-angular21.sh` switches to Node 24, runs `ng build` (production, service worker included) and serves
`dist/angular-hnpwa/browser` on 4200.

Both are served by `scripts/static-server.js` (no dependencies, SPA fallback). `PARITY_NO_SERVER=1` skips
starting servers; `LEGACY_PORT` / `ANGULAR21_PORT` change the ports.

## Data

By default every Hacker News API call (`node-hnapi.herokuapp.com`, `api.hnpwa.com`) is answered from
`fixtures/`, recorded from the live API, so both apps render the same stories and the specs assert exact
text. `PARITY_LIVE=1` uses the live API instead (story assertions are skipped, the rest check shape only).

`node-hnapi` no longer serves `/user/:id`, so the legacy profile page is broken against the live API. In live
mode the suite forwards that call to `api.hnpwa.com/v0/user/:id.json` (same JSON shape, the endpoint the
Angular 21 app uses); with fixtures both URLs return the same recorded user.

Service workers are blocked in every spec except `pwa.spec.ts`, so the API mocks always apply.

Full-page screenshots of every test end up in `report/screenshots/<project>/` for side-by-side review.

## Expected state

`legacy` is fully green. On `angular21`, specs for features that are still placeholders on
`devin/angular21-base` (feeds, story page, user profile, header/settings) fail until those feature PRs merge;
`pwa.spec.ts` passes.
88 changes: 88 additions & 0 deletions parity/fixtures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { test as base, expect, type BrowserContext, type Route } from '@playwright/test';
import { existsSync, readFileSync } from 'node:fs';
import { join } from 'node:path';

// By default every Hacker News API call is answered from fixtures/ (recorded from the live API),
// so both apps render identical data and the specs can assert exact text.
// PARITY_LIVE=1 hits the live API instead.
export const live = !!process.env.PARITY_LIVE;
const fixturesDir = join(__dirname, 'fixtures');

export function fixture<T = any>(name: string): T {
return JSON.parse(readFileSync(join(fixturesDir, `${name}.json`), 'utf8'));
}

const cors = { 'access-control-allow-origin': '*' };

// node-hnapi: /news?page=1, /item/1, /user/pg. HNPWA: /v0/news/1.json, /v0/item/1.json, /v0/user/pg.json
function fixtureNameFor(url: URL): string | undefined {
const parts = url.pathname
.replace(/^\/v0/, '')
.replace(/\.json$/, '')
.split('/')
.filter(Boolean);
if (parts.length === 1) return `${parts[0]}-${url.searchParams.get('page') ?? 1}`;
if (parts.length === 2) return `${parts[0]}-${parts[1]}`;
return undefined;
}

async function answerFromFixtures(route: Route): Promise<void> {
const name = fixtureNameFor(new URL(route.request().url()));
const file = name && join(fixturesDir, `${name}.json`);
if (file && existsSync(file)) {
await route.fulfill({
status: 200,
headers: cors,
contentType: 'application/json',
body: readFileSync(file, 'utf8'),
});
} else {
await route.fulfill({
status: 404,
headers: cors,
contentType: 'application/json',
body: '{"error":"no fixture"}',
});
}
}

// node-hnapi dropped /user/:id; the legacy app still calls it, so live runs send it to HNPWA (same shape).
async function legacyUserToHnpwa(route: Route): Promise<void> {
const id = new URL(route.request().url()).pathname.split('/').pop();
const response = await route.fetch({ url: `https://api.hnpwa.com/v0/user/${id}.json` });
await route.fulfill({ response, headers: { ...response.headers(), ...cors } });
}

export async function routeHackerNewsApi(context: BrowserContext): Promise<void> {
if (live) {
await context.route('https://node-hnapi.herokuapp.com/user/**', legacyUserToHnpwa);
return;
}
await context.route('https://node-hnapi.herokuapp.com/**', answerFromFixtures);
await context.route('https://api.hnpwa.com/**', answerFromFixtures);
}

export const test = base.extend<{ hnApi: void }>({
hnApi: [
async ({ context }, use) => {
await routeHackerNewsApi(context);
await use();
},
{ auto: true },
],
});

test.afterEach(async ({ page }, testInfo) => {
const name = testInfo.titlePath
.slice(1)
.join(' - ')
.replace(/[^\w-]+/g, '_');
await page
.screenshot({
path: join(__dirname, 'report', 'screenshots', testInfo.project.name, `${name}.png`),
fullPage: true,
})
.catch(() => undefined);
});

export { expect };
Loading
Loading