Skip to content

Add unit tests for stellar.ts; fix build-breaking errors across the codebase - #16

Merged
cokehill merged 1 commit into
mainfrom
test/stellar-lib-unit-tests
Jul 13, 2026
Merged

Add unit tests for stellar.ts; fix build-breaking errors across the codebase#16
cokehill merged 1 commit into
mainfrom
test/stellar-lib-unit-tests

Conversation

@cokehill

Copy link
Copy Markdown
Contributor

What changed

1. Add test coverage for src/lib/stellar.ts

package.json already had "test": "vitest run" wired up, but there
was no vitest.config.ts and zero test files anywhere in the repo.
Added:

  • vitest.config.ts — points vitest at src/**/*.test.ts
  • src/lib/stellar.test.ts — 21 unit tests covering the pure,
    network-free helpers (getNetworkPassphrase, getHorizonUrl,
    parseAsset, isValidPublicKey, isValidSecretKey), including the
    public/secret-key-swap case that's an easy mistake for consumers of
    this library to make.

2. Fix npm run build (was failing before this PR)

Running the build surfaced a series of pre-existing, unrelated issues:

  • src/index.ts — raw CSS had been appended after the exports,
    breaking esbuild's parser. Moved the intended style into
    src/styles/index.css.
  • src/components/ui/Field.tsx — a duplicate, unreachable
    {error && (...)} block was pasted inside return (, before the
    root element (invalid JSX). Removed it. Also fixed two type
    mismatches: value passed to AssetInput needed the real Asset
    type instead of a loose shape, and error (typed string | null)
    needed ?? undefined before being passed to AssetInput.
  • src/components/TransactionBuilder/OperationsStep.tsx — removed an
    orphaned validation snippet referencing undefined variables, and
    fixed a Type 'unknown' is not assignable to type 'ReactNode' error
    by wrapping op.params.destination in Boolean(...).
  • src/lib/stellar.ts — removed an unused TransactionParams import,
    and fixed Memo.return()'s type mismatch (its types only accept
    string, unlike Memo.hash()) by passing the hex string directly
    instead of Buffer.from(...).
  • src/lib/operationDefinitions.ts — two validate functions used
    !v || v.trim(), which TypeScript narrows unknown to {} rather
    than string on the truthy branch (a known TS quirk). Switched to
    typeof v !== "string" || ..., which narrows correctly.
  • Removed unused import React from "react" across several
    components (project uses "jsx": "react-jsx"), restoring named
    imports (useEffect, Fragment) where a file actually needed them.

Testing

  • npx vitest run — 21/21 passing
  • npm run build — CJS, ESM, and DTS all build successfully

@cokehill
cokehill merged commit 2465f44 into main Jul 13, 2026
1 check failed
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.

1 participant