Add unit tests for stellar.ts; fix build-breaking errors across the codebase - #16
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
1. Add test coverage for src/lib/stellar.ts
package.jsonalready had"test": "vitest run"wired up, but therewas no
vitest.config.tsand zero test files anywhere in the repo.Added:
vitest.config.ts— points vitest atsrc/**/*.test.tssrc/lib/stellar.test.ts— 21 unit tests covering the pure,network-free helpers (
getNetworkPassphrase,getHorizonUrl,parseAsset,isValidPublicKey,isValidSecretKey), including thepublic/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 insidereturn (, before theroot element (invalid JSX). Removed it. Also fixed two type
mismatches:
valuepassed toAssetInputneeded the realAssettype instead of a loose shape, and
error(typedstring | null)needed
?? undefinedbefore being passed toAssetInput.src/components/TransactionBuilder/OperationsStep.tsx— removed anorphaned validation snippet referencing undefined variables, and
fixed a
Type 'unknown' is not assignable to type 'ReactNode'errorby wrapping
op.params.destinationinBoolean(...).src/lib/stellar.ts— removed an unusedTransactionParamsimport,and fixed
Memo.return()'s type mismatch (its types only acceptstring, unlikeMemo.hash()) by passing the hex string directlyinstead of
Buffer.from(...).src/lib/operationDefinitions.ts— twovalidatefunctions used!v || v.trim(), which TypeScript narrowsunknownto{}ratherthan
stringon the truthy branch (a known TS quirk). Switched totypeof v !== "string" || ..., which narrows correctly.import React from "react"across severalcomponents (project uses
"jsx": "react-jsx"), restoring namedimports (
useEffect,Fragment) where a file actually needed them.Testing
npx vitest run— 21/21 passingnpm run build— CJS, ESM, and DTS all build successfully