Skip to content

test: re-work some brittle atproto mocks#2798

Draft
serhalp wants to merge 2 commits into
mainfrom
serhalp/test/fix-atproto-mocks
Draft

test: re-work some brittle atproto mocks#2798
serhalp wants to merge 2 commits into
mainfrom
serhalp/test/fix-atproto-mocks

Conversation

@serhalp
Copy link
Copy Markdown
Member

@serhalp serhalp commented May 26, 2026

🔗 Linked issue

N/A

🧭 Context

I dunno, these started failing on a completely unrelated branch and simplifying them like this fixed it 😅.

📚 Description

Stop mocking useAtproto in a few tests and instead just set the composable state directly. These tests were brittle because the untyped mock could diverge from the actual use in the component/composable under test, suddenly quietly shifting the exercised state from under us, leading to difficult to debug failures like the one I encountered.

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 26, 2026

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

Project Deployment Actions Updated (UTC)
npmx.dev Ready Ready Preview, Comment May 26, 2026 3:56am
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
docs.npmx.dev Ignored Ignored Preview May 26, 2026 3:56am
npmx-lunaria Ignored Ignored May 26, 2026 3:56am

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 26, 2026

Review Change Stack

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b5865ca2-0708-468b-95f5-5eed22b95c1e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Three test files refactor how they control useAtproto() composable state during unit tests. Instead of hoisted mocks or mockNuxtImport factories, they now import useAtproto directly and mutate the returned user ref inside test setup and cleanup functions. The atproto disconnect test also shifts to registering and asserting an actual DELETE /api/auth/session endpoint handler.

Changes

useAtproto mock refactoring across component and composable tests

Layer / File(s) Summary
Package/Likes component test: direct user state mutation
test/nuxt/components/Package/Likes.spec.ts
Package/Likes test imports useAtproto() directly and sets user.value to null in beforeEach. The "keeps the top liked badge when a like response omits the rank" test replaces mockUseAtproto.mockReturnValue(...) with direct user.value mutation and updates the /api/social/like endpoint mock to use an object form with method: 'POST' and handler.
ProfileInviteSection component test: composable state per test case
test/nuxt/components/ProfileInviteSection.spec.ts
ProfileInviteSection test removes the hoisted useAtproto mock and imports the composable directly. Individual tests set user.value to null, undefined, or user objects with appropriate handles instead of configuring mocked return payloads with pending and logout.
useCommandPaletteCommands composable test: state-driven helper and endpoint assertion
test/nuxt/composables/use-command-palette-commands.spec.ts
useCommandPaletteCommands test removes module-scoped mockAtprotoHandle and mockNuxtImport('useAtproto', ...), then updates captureCommandPalette helper and afterEach cleanup to configure atproto state via direct useAtproto() calls. The atproto disconnect test registers a DELETE /api/auth/session endpoint and asserts the handler invocation instead of checking a mocked logout call.

Possibly related PRs

  • npmx-dev/npmx.dev#2459: Introduced the topLikedRank badge behaviour in the Package/Likes component that this PR's test refactoring now supports with direct state mutation.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: refactoring brittle atproto mocks in test files to use direct composable state mutation instead.
Description check ✅ Passed The description explains the motivation and approach for the changes, relating directly to the test file modifications in the changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch serhalp/test/fix-atproto-mocks

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@serhalp serhalp marked this pull request as draft May 26, 2026 00:23
serhalp added 2 commits May 25, 2026 23:52
Stop mocking `useAtproto` in a few tests and instead set the shared
composable state that the app reads at runtime. These tests were brittle
because the mocked binding could diverge from the import path used by
the component or composable under test, suddenly quietly shifting the
exercised state from under us, leading to difficult to debug failures.
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