Skip to content

test: add unit tests for the asset map hooks - #1335

Merged
stevenle merged 1 commit into
codex/fix-issue-183-on-githubfrom
claude/review-issue-183-tests-592ba9
Jul 30, 2026
Merged

test: add unit tests for the asset map hooks#1335
stevenle merged 1 commit into
codex/fix-issue-183-on-githubfrom
claude/review-issue-183-tests-592ba9

Conversation

@stevenle

Copy link
Copy Markdown
Member

Adds test coverage for the useAssetUrl() hook introduced in #1334, which this
branch targets so the diff is tests only.

src/core/hooks/useAssetMap.test.tsx

Renders components through a stub AssetMap and asserts:

  • useAssetUrl() resolves a src to its compiled asset URL, run against both
    renderers (preact-render-to-string and @blinkk/root/jsx), since the
    renderer is picked by the jsxRenderer config in root.config.ts.
  • A leading / on the src is normalized away.
  • Unknown srcs and assets with an empty assetUrl throw.
  • useAsset() returns the asset from the module graph.
  • useAssetMap() throws when rendered outside of ASSET_MAP_CONTEXT.

src/render/asset-map/dev-asset-map.test.ts

Covers the path containment checks in DevServerAssetMap.get(), which changed
from file.startsWith(rootDir) + the async directoryContains() in fsutils
to a local synchronous helper:

  • Files inside the project resolve to a root-relative URL.
  • A sibling dir that shares the root dir's path prefix (<ws>/site-legacy vs.
    <ws>/site) is served from /@fs/ instead of producing the truncated
    -legacy/main.ts URL the old prefix check returned.
  • Workspace files that don't exist on disk resolve instead of throwing
    ENOENT, which the old realpath()-based check did.
  • Files outside the workspace return null and log.

The suite builds a temp workspace with a pnpm-workspace.yaml so vite's
searchForWorkspaceRoot() resolves deterministically.

Testing

pnpm test in packages/root: 38 files / 216 tests passing. pnpm lint is
clean. No changeset — tests only, and #1334 already carries one.

Generated with Claude Code.


Generated by Claude Code

Covers `useAssetUrl()`/`useAsset()`/`useAssetMap()` against both the
`preact-render-to-string` and `@blinkk/root/jsx` renderers, and the
`DevServerAssetMap` path containment checks.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XdqjF4kM5drMB4vSLGsqvf
@stevenle
stevenle merged commit 3aba405 into codex/fix-issue-183-on-github Jul 30, 2026
@stevenle
stevenle deleted the claude/review-issue-183-tests-592ba9 branch July 30, 2026 16:56
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.

2 participants