Skip to content

test(infra): add vitest unit tests and CI quality gates - #20

Merged
ibrahimmosouf-png merged 1 commit into
OrbitChainLabs:mainfrom
nasalehj:fix/issue-10-test-infra-ci
Aug 23, 2026
Merged

test(infra): add vitest unit tests and CI quality gates#20
ibrahimmosouf-png merged 1 commit into
OrbitChainLabs:mainfrom
nasalehj:fix/issue-10-test-infra-ci

Conversation

@nasalehj

Copy link
Copy Markdown
Contributor

Summary

Closes #10

The repository had no test infrastructure and no CI: package.json defined no test script, a search for *.test.*/*.spec.* found nothing, and .github/workflows did not exist. This PR introduces Vitest as the test runner, adds a test script, writes 76 unit tests across the seven modules the issue lists, and adds a GitHub Actions workflow that gates every push/PR on type-check, lint, test, and build with no required secrets.

Runner rationale — Vitest over Jest: it is TypeScript-native with zero config for unit tests (no ts-jest/babel ceremony), has jsdom built in (used here for the browser-API image tests, and a direct path to React Testing Library for the component tests the issue anticipates), and is significantly faster. It coexists with the existing Storybook scripts without touching the Next.js 14 build.

Why

Before this change the only verification a contributor could run was npm run type-check and npm run lint. Pure logic had zero regression protection: Stellar amount/address formatting, address validation, Stellar/Web3 error mapping, the TTL cache manager, the auth and UI stores, and the image-upload utilities were all unguarded, so behavioral fixes could regress silently and reviewers had no test output to judge changes on. The milestone issues (JWT verification, draft storage, wallet balance, env contract) each call for tests, and none could be written before this infrastructure existed.

What was built

File What it contains
vitest.config.ts Minimal config: include: ['tests/**/*.test.ts'], Node environment by default; browser-API tests opt into jsdom via a per-file // @vitest-environment jsdom pragma.
package.json Adds "test": "vitest run" and devDependencies vitest + jsdom.
tests/stellar-formatting.test.ts toStroops/fromStroops (incl. round-trip and error cases), formatAmount, formatCurrency, formatAsset (native + issued via the SDK Asset type), getBaseFee, formatFee, truncateAddress, parseAssetString — 13 tests.
tests/stellar-validation.test.ts Valid/invalid public keys, secret keys, muxed addresses, and contract ids built from real SDK keypairs/StrKey encodings, plus getAddressType classification — 10 tests.
tests/stellar-errorHandler.test.ts parseStellarError over JSON-RPC numeric codes, Horizon operation/transaction result codes, string codes, message-substring matching, and both fallbacks; isUserRejection — 10 tests.
tests/cacheManager.test.ts Hits/misses/metrics, namespace isolation, TTL expiry (fake timers), LRU eviction, single-key and namespace invalidation, getOrSet caching + refresh-after-expiry, and metrics snapshot immutability — 10 tests.
tests/authStore.test.ts Login/logout/setUser/setLoading/setTokens state transitions (persist middleware no-ops in Node since localStorage is unavailable) — 7 tests.
tests/uiStore.test.ts Modal open/close, notification add (generated ids)/remove, sidebar toggle, theme, global loading — 7 tests.
tests/imageUpload.test.ts jsdom environment: file type/size validation with custom limits, dimension validation with deterministic FileReader/Image stubs (within bounds, oversized, decode failure), preview URL create/revoke, formatFileSize, getFileExtension — 13 tests.
.github/workflows/ci.yml GitHub Actions workflow: on push to main and on every PR, runs npm ci then npm run type-check, npm run lint, npm test, and npm run build (Node 22, npm cache). No secrets; any failing step fails the run and blocks the PR.
README.md Documents the Vitest setup, the npm test command, and the CI workflow in the Testing section and scripts table.

The tests exercise the modules' real behavior — including error paths and edge cases (negative/NaN amounts, malformed addresses, TTL expiry, eviction, oversized images) — rather than implementation details, so they double as regression protection for the milestone's behavioral fixes.

Integration changes outside tests/

No other files were modified.

Acceptance criteria coverage

  • npm test exists and runs green in a fresh clone with only npm install. (package.json"test": "vitest run"; verified locally: npm test → 76/76 passing. Vitest/jsdom are declared devDependencies, so npm install is sufficient.)
  • Unit tests cover lib/stellar/formatting.ts, lib/stellar/validation.ts, lib/stellar/errorHandler.ts, lib/cache/cacheManager.ts, store/authStore.ts, store/uiStore.ts, and utils/imageUpload.ts. (One test file per module in tests/ — 76 tests total.)
  • A GitHub Actions workflow under .github/workflows/ runs type-check, lint, build, and test on push and pull request, with no required secrets. (.github/workflows/ci.yml — four steps on push to main and on pull_request; no secrets, only actions/checkout, actions/setup-node, npm ci.)
  • The workflow is the only gate; test failures block the run. (Each quality command is a separate step; a failing step fails the job, so type-check, lint, test, or build failures all block the PR.)
  • README documents how to run the tests. (README.md — Testing section with npm test and the CI description.)

Test plan

  • npm test — 76/76 passing (76 new tests across 7 files)
  • npm run type-check — no errors
  • npm run lint — no warnings or errors
  • npm run build — succeeds

Env vars / Notes

No new environment variables and no runtime dependency changes (vitest and jsdom are devDependencies only).

Notes:

@nasalehj
nasalehj force-pushed the fix/issue-10-test-infra-ci branch 2 times, most recently from 05b4d9c to 2ae7ba2 Compare August 23, 2026 16:58

@ibrahimmosouf-png ibrahimmosouf-png left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

The repository had no test infrastructure and no CI: package.json had no
test script, no test files existed, and .github/workflows did not exist,
so pure logic (Stellar formatting/validation/error mapping, the cache
manager, the auth and UI stores, image uploads) had zero regression
protection. Introduce Vitest as the runner (TS-native, zero-config unit
tests, built-in jsdom for browser-API tests, and a path to React Testing
Library for future component tests), add a test script, and write 76
unit tests across the seven modules the issue lists. Add a GitHub
Actions workflow that runs type-check, lint, test, and build on push and
pull request with no required secrets, and document npm test in the
README. Also fixes pre-existing type errors in adminStore, draftStore,
and campaignDeployer that blocked the required type-check and build
gates (identical to PRs OrbitChainLabs#18 and OrbitChainLabs#19).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Repository has no test infrastructure or CI: zero test files, no test script, and no workflow gates

2 participants