Skip to content
Closed
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
58 changes: 58 additions & 0 deletions .github/workflows/react-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# CI for the React migration under react/. Mirrors .travis.yml (install -> build on master),
# adding lint, unit tests with coverage gates and Playwright e2e. Firebase deploy stays on Travis
# until the final migration phase switches hosting to the React build.
name: React CI

on:
push:
branches: [master]
pull_request:

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

defaults:
run:
working-directory: react

jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
cache-dependency-path: react/package-lock.json
- run: npm ci
- run: npm run format:check
- run: npm run lint
- run: npm test
- run: npm run build
- uses: actions/upload-artifact@v4
if: always()
with:
name: coverage
path: react/coverage
retention-days: 7

e2e:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
cache-dependency-path: react/package-lock.json
- run: npm ci
- run: npx playwright install --with-deps chromium
- run: npm run e2e
- uses: actions/upload-artifact@v4
if: failure()
with:
name: playwright-report
path: react/playwright-report
retention-days: 7
8 changes: 8 additions & 0 deletions react/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules
dist
coverage
test-results
playwright-report
blob-report
playwright/.cache
*.tsbuildinfo
6 changes: 6 additions & 0 deletions react/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dist
coverage
test-results
playwright-report
public
package-lock.json
21 changes: 21 additions & 0 deletions react/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# React HN (migration in progress)

React 18 + TypeScript + Vite port of the Angular HN PWA in the repo root. The Angular app stays intact until the final migration phase.

## Scripts (run from `react/`)

| Command | What it does |
| --------------------------------- | ---------------------------------------------------------------------------------------------------- |
| `npm start` / `npm run dev` | Vite dev server on http://localhost:5173 |
| `npm run build` | Type-check + production build to `dist/` |
| `npm run preview` | Serve the production build on http://localhost:4173 |
| `npm run lint` | ESLint (flat config, typescript-eslint, react-hooks) |
| `npm run format` / `format:check` | Prettier (tabWidth 4, singleQuote, printWidth 120 — same as the Angular app) |
| `npm test` | Vitest + React Testing Library with v8 coverage; fails below 80% lines/branches/functions/statements |
| `npm run e2e` | Playwright (chromium) against the production build; run `npm run e2e:install` once first |

## Conventions

- Unit tests live next to source as `*.test.ts(x)`; jsdom environment, globals enabled, `localStorage` cleared after each test.
- E2E specs live in `e2e/`. Use `mockHnApi` from `e2e/support/mock-api.ts` to stub `https://node-hnapi.herokuapp.com` so runs are deterministic.
- Static assets (icons, logo, cog) are in `public/assets/`, copied from `src/assets/`.
6 changes: 6 additions & 0 deletions react/e2e/smoke.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { expect, test } from '@playwright/test';

test('app boots', async ({ page }) => {
await page.goto('/');
await expect(page.getByRole('heading', { name: 'React HN' })).toBeVisible();
});
24 changes: 24 additions & 0 deletions react/e2e/support/mock-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { Page, Route } from '@playwright/test';

export const HN_API_BASE = 'https://node-hnapi.herokuapp.com';

export type ApiHandler = (url: URL) => unknown | Promise<unknown>;

/**
* Intercepts every request to the HN API so e2e runs are deterministic and offline-safe.
* `handlers` maps a path prefix (e.g. '/news', '/item/', '/user/') to a function returning the JSON body.
* Unmatched requests fail with 404 so missing fixtures surface loudly.
*/
export async function mockHnApi(page: Page, handlers: Record<string, ApiHandler>): Promise<void> {
await page.route(`${HN_API_BASE}/**`, async (route: Route) => {
const url = new URL(route.request().url());
const prefix = Object.keys(handlers)
.sort((a, b) => b.length - a.length)
.find((p) => url.pathname.startsWith(p));
if (!prefix) {
await route.fulfill({ status: 404, json: { error: `No mock for ${url.pathname}` } });
return;
}
await route.fulfill({ status: 200, json: await handlers[prefix](url) });
});
}
27 changes: 27 additions & 0 deletions react/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import js from '@eslint/js';
import globals from 'globals';
import reactHooks from 'eslint-plugin-react-hooks';
import reactRefresh from 'eslint-plugin-react-refresh';
import prettier from 'eslint-config-prettier';
import tseslint from 'typescript-eslint';

export default tseslint.config(
{ ignores: ['dist', 'coverage', 'test-results', 'playwright-report'] },
{
extends: [js.configs.recommended, ...tseslint.configs.recommended],
files: ['**/*.{ts,tsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: { ...globals.browser, ...globals.node },
},
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
},
},
prettier
);
18 changes: 18 additions & 0 deletions react/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>React HN</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="A Hacker News client built with React, TypeScript and Vite" />
<meta name="theme-color" content="#b92b27" />
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
<link rel="icon" type="image/png" href="/assets/icons/favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="/assets/icons/favicon-16x16.png" sizes="16x16" />
<link rel="apple-touch-icon" sizes="180x180" href="/assets/icons/apple-touch-icon.png" />
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
Loading
Loading