Repository navigation
chore: run the mock target in a browser on CI - #142
Merged
Merged
Conversation
Add a browser job. smocket exists for frontend test suites, which run in a browser or something browser-like, and nothing confirmed the library works there. #139 is what that cost. `newId` used `node:crypto` and a bundler's `Buffer` shim has no `base64url`, so no client could connect in a page at all while this suite stayed green on Node 22 and 24, both targets. Dual-run answers whether smocket behaves like socket.io. It says nothing about whether smocket runs here, and that question had no test. Vitest browser mode with the Playwright provider, Chromium, headless. Only the mock target has a counterpart in a page, since a browser cannot host a socket.io server process, so this is a narrower question than the dual run rather than a second one. `setup-server.ts` imports both targets statically and the real one pulls in `node:http` and `node:net`, which fail at load in a bundle even when nothing calls them. `vitest.browser.config.ts` aliases `setup-server` to a new `setup-server.browser.ts` that re-exports the mock setup, so the real target never enters the graph. Screenshots on failure are off, since the page holds the runner and nothing else. One test needed changing. `a relative url resolves against location.origin` stubbed `location`, which a real browser will not let you redefine. It now reads the page origin when there is one and stubs only under Node, so the browser run resolves against the origin it is actually served from. All 160 pass in Chromium, and both Node targets stay green.
The repo rules say done means both targets green. There is a third run now, it is not part of that pair, and it needs a one-time Playwright install, so say so where the other test rules live.
📝 WalkthroughWalkthroughThe change adds Vitest browser mode with Playwright and Chromium support. It provides a browser-safe mock server setup, updates relative-URL test handling, adds a browser test command, and runs that command in CI. ChangesBrowser testing
Estimated code review effort: 3 (Moderate) | ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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. Comment |
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
The comment on `newId` claimed the encoding was verified byte for byte against
`Buffer.toString('base64url')` and nothing held that claim. The dual-run test added
with #140 reads the id's shape, `/^[A-Za-z0-9_-]{20}$/`, which a broken encoder can
still satisfy. Drop the padding strip and it passes, because 15 bytes emit no
padding. Swap neither `+` nor `/` and it passes, until the day random bytes land on
one of those characters, at which point ids stop being url-safe with the suite green.
Split the encoder out as `toBase64Url` and cover it directly. A caller that can pass
a length other than the id's is the only thing that can pin the strip, so the export
exists for the test and stays out of `index.ts`. Three cases: the url-safe alphabet
over bytes whose standard encoding holds both `+` and `/`, the padding strip at
lengths 1, 2 and 3, and an id built from a fixed byte source so the length and the
encoding are pinned together.
Mock-only, like the adapter tests, since id generation is smocket's own and there is
no socket.io counterpart to read it off. Each case was checked against a mutation:
removing the strip fails the padding test, removing either swap fails the other two.
The matrix comment gave the pnpm 11 constraint first and Node 20's end of maintenance second. Only the second is a reason about supported versions, and in that order the next pnpm bump reads as a reason to raise the matrix. The reference to #104 died when that issue closed with the packaging work, so point at #143, which is where the supported range is actually being settled. The Codecov note said the token does not exist yet, and it does now.
This was referenced Aug 12, 2026
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
smocket exists for frontend test suites, which run in a browser or something browser-like, and nothing confirmed the library works there. #139 is what that cost.
newIdusednode:cryptoand a bundler'sBuffershim has nobase64url, so no client could connect in a page at all while this suite stayed green on Node 22 and 24, both targets. The dual run answers whether smocket behaves like socket.io. It says nothing about whether smocket runs here, and that question had no test.Vitest browser mode with the Playwright provider, Chromium, headless. Only the mock target has a counterpart in a page, since a browser cannot host a socket.io server process, so this asks a narrower question than the dual run rather than being a second one.
setup-server.tsimports both targets statically and the real one pulls innode:httpandnode:net, which fail at load in a bundle even when nothing calls them.vitest.browser.config.tsaliasessetup-serverto a newsetup-server.browser.tsthat re-exports the mock setup, so the real target never enters the graph. Failure screenshots are off, since the page holds the runner and nothing else.One test needed changing.
a relative url resolves against location.originstubbedlocation, which a real browser will not let you redefine. It now reads the page origin when there is one and stubs only under Node, so the browser run resolves against the origin it is actually served from.Two things ride along. The
newIdcomment claimed the encoding was verified byte for byte and no test held that claim, since the shape check still passes with the padding strip or the url-safe swaps removed. The encoder is split out astoBase64Urland covered directly, each case checked against a mutation.The CI comments are corrected too. The matrix now leads with Node 20 leaving maintenance rather than with the pnpm constraint, so a pnpm bump does not read as a reason to raise the matrix. The dead
#104reference points at #143, where the supported range is being settled. The Codecov note no longer says the token is missing.All 163 pass in Chromium and on both Node targets. The job adds a Playwright install step, so it runs longer than the others.
pnpm test:browseris the local command and it needspnpm exec playwright install chromiumonce.The other half of #105 goes to #144, the bundle assertion that would pin the package to no external imports. That is a different mechanism for the same regression, so it lands on its own.
Related issue
Closes #105
Checklist