test(tar-xz): cover toAsyncIterable across Node and Browser variants#124
Merged
Conversation
The two internal/to-async-iterable.{ts,browser.ts} implementations had
0% coverage on the browser file and 28.57% on the Node one — the
ArrayBuffer, Iterable, AsyncIterable, and ReadableStream paths were
all untested.
Add 35 cases parametrized via describe.each across both
implementations (Node 18+ has ReadableStream in globalThis, so both
files run directly without JSDOM):
- All accepted input types: Uint8Array, Buffer, ArrayBuffer,
Iterable, AsyncIterable, ReadableStream, NodeJS.Readable.
- Empty cases for every iterable input shape.
- Error contract: null and number reject with TypeError; string
resolves via the Symbol.iterator branch (locked behavior, not a
bug).
- A makeGetReaderOnlyStream fake forces the webReadableToAsyncIterable
path even on Node where ReadableStream natively supports
Symbol.asyncIterator.
- A Browser-only assertion locks the contract that custom
AsyncIterables are returned by reference (no Readable.from
wrapping in the browser variant).
Coverage:
- to-async-iterable.ts: 28.57% → 100% (27/27 lines, 20/20
branches, 5/5 functions).
- to-async-iterable.browser.ts: 0% → 100% (25/25 lines, 18/18
branches, 5/5 functions).
- tar-xz overall: 86.96% lines / 82.1% branches → 95.33% lines /
89.45% branches.
35 new vitest cases, 0 source changes; tar-xz suite goes from 155
to 190 passing.
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.
Summary
35 new vitest cases parametrized across the two
internal/to-async-iterable.{ts,browser.ts}implementations. Both files were 0% / 28.57% covered before — theArrayBuffer,Iterable,AsyncIterable,ReadableStream, andNodeJS.Readablepaths were untested.Approach
Direct imports of both files in a single
packages/tar-xz/test/to-async-iterable.spec.ts. Node 18+ hasReadableStreaminglobalThis, so both implementations run directly without JSDOM.describe.eachparametrizes shared cases across both ; Node-only and Browser-only contracts get separatedescribeblocks.Smart trick
Real
ReadableStreaminstances on Node 18+ have BOTHSymbol.asyncIteratorANDgetReader. Since both implementations checkSymbol.asyncIteratorfirst, a real stream takes the fast path. To force thewebReadableToAsyncIterable(getReader-only) path through coverage, amakeGetReaderOnlyStreamfake provides onlygetReader. Locks the contract for that path.Contracts locked
nullandnumber→TypeError(both impls).string→ resolves through theSymbol.iteratorbranch (NOT a TypeError ; this is current behavior, locked verbatim).AsyncIterablereturned by reference (noReadable.fromwrapping).Readable.fromwraps even existingReadable(verified by reference comparison).Coverage
to-async-iterable.tsto-async-iterable.browser.tsDiff
1 new file, +289 lines (test only, no source change).
Gates
pnpm install --frozen-lockfile: EXIT 0pnpm --filter tar-xz build: EXIT 0pnpm type-check: EXIT 0pnpm exec biome check .: EXIT 0, 0 warningspnpm test: tar-xz 155 → 190 passing (+35), 3 skipped unchanged ; full workspace 489 root + 190 tar-xz + 63 nxz = 742 passing, 0 failTest plan