Skip to content

test(translator): make nine fragment assertions fail when nothing is collected - #138

Merged
SearheiParkhamchuk merged 1 commit into
mainfrom
test/translator-fragment-assertions
Sep 11, 2026
Merged

SearheiParkhamchuk merged 1 commit into
mainfrom
test/translator-fragment-assertions

Conversation

@SearheiParkhamchuk

Copy link
Copy Markdown
Contributor

Follow-up on #137, found by auditing its own suite.

How they were found

A throwing stub proves little — every check goes red because everything explodes. The harder question is what survives an implementation that returns nothing, quietly. collectInlineFragments was replaced with () => [] and the suite re-run:

checks in the file 49
passed against a collector that collected nothing 11

Why they passed

One mechanism, four spellings — the assertion reaches its value through an optional chain, or runs a predicate over an array that is empty:

const fragment = collectInlineFragments(root)[0]?.fragments[0];
expect(fragment?.top).toBe(fragment?.node);      // undefined === undefined → passes

expect(containers.every((c) => c.skip !== undefined)).toBe(true);   // [] → vacuously true
expect(containers.some((c) => c.node === link)).toBe(false);        // [] → false
expect(collectInlineFragments(root)[0]?.skip).toBeUndefined();      // undefined → passes

The most uncomfortable one was gives a multi-leaf wrapper's fragment a copy of the wrapper as top, not the wrapper — the distinction the module is built around — passing against a collector that returns an empty array.

The fix

Each check now asserts the container or fragment exists before asserting anything about it. No production code changed.

Re-running the same audit afterwards: 11 survivors → 2. Those two are toEqual([]) for an empty root and for a node with no text children — checks whose entire content is the absence, which is their contract clause rather than an oversight. Strengthening them would mean asserting something they do not claim.

Also removes the three anys from the createNode helper. oxlint does not flag them; the project's own rule does.

Verification

1469 unit tests, unchanged in count and all green. check-types clean. Lint 58 warnings, 0 errors — identical to main.

…collected

An audit of the suite replaced `collectInlineFragments` with an implementation
that silently returns `[]` and ran the tests. Eleven of the forty-nine passed.

The mechanism was the same in every case: the assertion reached the value
through an optional chain, or ran a predicate over an array that was empty, so
it was satisfied by the absence of a result.

    const fragment = collectInlineFragments(root)[0]?.fragments[0];
    expect(fragment?.top).toBe(fragment?.node);    // undefined === undefined

    expect(containers.every((c) => c.skip !== undefined)).toBe(true);   // [] → true
    expect(containers.some((c) => c.node === link)).toBe(false);        // [] → false
    expect(collectInlineFragments(root)[0]?.skip).toBeUndefined();      // undefined

The worst of them was the check that a multi-leaf wrapper's `top` is a copy
rather than the wrapper from the tree — the distinction the whole module
exists for, passing against a collector that collected nothing.

Each now asserts that the container or fragment exists before asserting
anything about it. Re-running the same audit: eleven survivors down to two,
and those two are `toEqual([])` on an empty root and on a node with no text
children — assertions whose whole content is the absence, which is their
contract clause rather than an oversight.

Also drops the three `any`s from the `createNode` helper, which the repo's
lint does not flag but the project forbids.

Verification: 1469 unit tests, unchanged in count and all green; check-types
clean; lint 58 warnings and 0 errors, identical to main.
@vercel

vercel Bot commented Sep 11, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
ideal-cms Ready Ready Preview Sep 11, 2026 12:33pm UTC

Request Review

@SearheiParkhamchuk
SearheiParkhamchuk merged commit 7145331 into main Sep 11, 2026
2 checks passed
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 0.13.0 🎉

The release is available on npm package (@latest dist-tag)

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant