This project uses Vitest — a test runner built for Vite projects. Tests run in Node (no browser, no Epic) and are suitable for CI (npm test on every push).
npm install
npm testDuring development, re-run on file save:
npm run test:watchOpen tests/documentReferenceSearch.test.js. Each file uses:
describe— groups related cases (e.g. one function).it— one behavior you expect (“builds core clinical-note search…”).expect(...).toBe(...)— assertion; the test fails if reality ≠ expectation.
const url = buildDocumentSearchUrl('patient-123', LOINC_CODES_CORE, { category: 'clinical-note' });
expect(url).toContain('category=clinical-note');No Epic, no fhirclient, no Vue — just inputs and outputs. That is the fastest regression net.
| File | What it teaches |
|---|---|
tests/documentReferenceSearch.test.js |
Pure FHIR search URL building |
tests/progressNoteFilter.test.js |
Fixtures (fixtures/fhir/*.json) + progress vs telephone filter |
tests/whiteListAccess.test.js |
Non-FHIR config logic |
tests/fetchNotes.integration.test.js |
Mock client.request — same hook as after SMART OAuth |
Production code for (1) and (2) lives under src/data/fhir/ so it stays small and importable. fetchNotes.js orchestrates those pieces plus Binary fetch and ClinicalNote construction.
After SMART login, the app calls fetchNotes($client, $patientId). In tests we pass a stub:
const client = createMockFhirClient({
handlers: {
'/DocumentReference?patient=test-patient&...': () => bundleWithEntries([...]),
'Binary': () => '<p>note html</p>',
},
});
await fetchNotes(client, 'test-patient');See tests/helpers/mockFhirClient.js. Add JSON under fixtures/fhir/ as Epic-shaped examples grow.
- SMART launch, redirect URI, OAuth
- Real Epic
DocumentReference/ Binary behavior
Use staging as a short smoke checklist before release; use npm test for day-to-day regressions.
Add .github/workflows/test.yml:
name: test
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: npm
- run: npm ci
- run: npm testnpm ci installs exactly what package-lock.json pins (including vitest).
- If logic is pure → move or export to
src/data/fhir/orsrc/config/. - Add
tests/yourFeature.test.jswithdescribe/it/expect. - Run
npm testuntil green. - For FHIR pipelines → extend fixtures + mock handlers.