Skip to content

dn1231/hackernews-api-test-playwright-js-client

Repository files navigation

hackernews-api-test (Playwright — JavaScript, Centralized API Client)

Automated acceptance tests for the Hacker News public API using Playwright Test (JavaScript) with a centralized API client + retry/backoff.

✅ What this covers

  1. Top Stories: non-empty integer ID list, <2s latency
  2. Current top story via Items API: required fields, type: "story"
  3. First comment (if exists): type: "comment", parent matches story
  4. Edge cases: invalid/huge ID, negative ID behaves gracefully

🛠️ Stack

  • Node 18+
  • Playwright Test (@playwright/test)
  • Centralized client: lib/apiClient.js with retry/backoff + timeout

🚀 Getting Started

# 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:report

🧱 Project Layout

hackernews-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)

🔧 Notes

  • The hn fixture 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).

🧪 Extending

  • Add getNewStoriesIds()/getAskStoriesIds() etc. to apiClient.js easily.
  • Introduce JSON schema validation with ajv if deeper contract checks are needed.
  • Add test.slow() or relax latency assertion if CI is noisy.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published