Automated acceptance tests for the Hacker News public API using Playwright Test (JavaScript) with a centralized API client + retry/backoff.
- Top Stories: non-empty integer ID list, <2s latency
- Current top story via Items API: required fields,
type: "story" - First comment (if exists):
type: "comment",parentmatches story - Edge cases: invalid/huge ID, negative ID behaves gracefully
- Node 18+
- Playwright Test (
@playwright/test) - Centralized client:
lib/apiClient.jswith retry/backoff + timeout
# 1) Install deps
npm install
# 2) (Optional) Install browsers (not required for API tests)
npm run install:pw
# 3) Run tests
npm test
# 4) View HTML report
npm run test:reporthackernews-api-test/
├── lib/
│ └── apiClient.js # centralized API client with retries/backoff
├── tests/
│ ├── fixtures.js # provides 'hn' client fixture
│ ├── top-stories.spec.js
│ ├── items.spec.js
│ ├── comments.spec.js
│ └── edge-cases.spec.js
├── playwright.config.js
├── package.json
└── reports/ # junit.xml output (CI)
- The
hnfixture wraps the API client so tests are concise and consistent. - Retries/backoff happen automatically within the client; tune via constructor options if needed.
- HTML report →
playwright-report/; JUnit XML →reports/junit.xml(via config).
- Add
getNewStoriesIds()/getAskStoriesIds()etc. toapiClient.jseasily. - Introduce JSON schema validation with
ajvif deeper contract checks are needed. - Add
test.slow()or relax latency assertion if CI is noisy.