feat(tests): add @chat-adapter/tests test kit#470
Merged
Conversation
New package providing Vitest factories, custom matchers, and a setup file for people building Chat SDK adapters and bots. Factories: createMockAdapter, createMockChatInstance, createMockState (with working in-memory subscriptions/locks/KV/queues), createTestMessage, mockLogger / createMockLogger. Matchers: toHavePosted(threadId, textPattern?), toHaveDispatched(handler), toBeSubscribedTo(threadId). Auto-register via the '@chat-adapter/tests/setup' subpath in vitest setupFiles. chat and vitest are peer dependencies. Adapter-specific helpers (e.g. signed Slack webhook builders) belong in each adapter's own /testing subpath, not in this kit.
New content/docs/testing.mdx walks bot authors and custom-adapter authors through the kit's factories, custom matchers, and setup file. Added under the Usage section in the sidebar, after error-handling. Cross-link from contributing/testing.mdx clarifying that the hand-rolled patterns there are for repo contributors building first-party adapters, while consumers of Chat SDK should use @chat-adapter/tests.
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
visyat
approved these changes
May 9, 2026
Adapter.postMessage is (threadId: string, message: AdapterPostableMessage)
— previously the matcher read args[0] as { id: string } and args[1] as
{ text: string }, neither of which match the actual SDK shape. The matcher's
own tests fed the same wrong shape into the mock so they passed locally
while the matcher silently failed against any real bot or adapter.
Now compares args[0] as a string threadId, and extracts a comparable string
from AdapterPostableMessage's union — strings directly, PostableMarkdown
.markdown, PostableRaw.raw, and PostableCard.fallbackText. PostableAst and
fallback-less cards aren't text-matchable; documented in the JSDoc.
Tests updated to call postMessage with the real signature and to cover
each comparable AdapterPostableMessage shape.
Construct a real `Chat` with a `createMockAdapter` + `createMockState` and exercise `Chat.thread().post()` and `.subscribe()` end-to-end. The matchers (toHavePosted, toBeSubscribedTo) then assert against the actual call shape the SDK uses, so a future signature drift breaks here instead of silently agreeing with whatever wrong shape lives in the unit tests. This is the regression guard for the postMessage-shape bug fixed in the prior commit: each new matcher in subsequent PRs should be paired with a smoke case here.
Adds toHaveEdited, toHaveDeleted, toHaveReactedWith, toHaveStartedTyping,
and toHavePostedToChannel — covering the common Adapter mutation surface
that bot authors assert on. Each matcher's signature was checked against
packages/chat/src/types.ts, and each is paired with a smoke case that
drives a real Chat through the corresponding Thread/Channel API so
signature drift breaks the smoke test instead of silently agreeing with
the unit tests.
Emoji matching accepts both plain strings and EmojiValue ({ name }).
Text matching reuses the same extraction rules as toHavePosted —
strings, PostableMarkdown.markdown, PostableRaw.raw, and
PostableCard.fallbackText. Documented in matcher JSDoc, README, and
the Testing docs page.
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.
Adds a new published package
@chat-adapter/testswith Vitest factories, custom matchers, and a setup file for people building Chat SDK bots and custom adapters.Factories (
@chat-adapter/tests):createMockAdapter(name?, overrides?)— every method isvi.fn()with sensible defaults;overridesmerges on topcreateMockChatInstance(options?)— everyprocess*handler isvi.fn();getState/getUserName/getLoggerwired upcreateMockState()— in-memoryMockStateAdapterwith working subscriptions, locks, KV, lists, and queues;cacheexposes the underlying mapcreateTestMessage(id, text, overrides?)— markdown text is parsed into the formatted ASTmockLogger/createMockLogger()— shared default vs fresh-per-callMatchers (
@chat-adapter/tests/matchers):expect(adapter).toHavePosted(threadId, textPattern?)expect(chat).toHaveDispatched(handler)await expect(state).toBeSubscribedTo(threadId)Setup file (
@chat-adapter/tests/setup) auto-registers all matchers viaexpect.extend— drop intovitest.config.tssetupFiles.chatandvitestare peer dependencies. Adapter-specific helpers (e.g. signed Slack webhook builders, Teams claim builders) belong in each adapter's own/testingsubpath, not in this kit, so adopting@chat-adapter/testsdoesn't pull in adapter dependencies you don't use.Docs:
/docs/testingwalks through factories, matchers, and the two main flows (bot authors testing handlers, adapter authors testing webhook → dispatch)./docs/contributing/testingclarifying that the hand-rolled patterns there are for repo contributors building first-party adapters; consumers should use the kit instead.Existing internal
packages/chat/src/mock-adapter.tsis left untouched — migrating the chat package's own tests onto the kit (and droppingvitestfromchat's deps) is a follow-up.