Skip to content

chore: run the mock target in a browser on CI - #142

Merged
electrohyun merged 4 commits into
mainfrom
chore/browser-test-job
Aug 5, 2026
Merged

electrohyun merged 4 commits into
mainfrom
chore/browser-test-job

Conversation

@electrohyun

@electrohyun electrohyun commented Aug 5, 2026 •

Copy link
Copy Markdown
Owner

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. 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. 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.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. Failure screenshots 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.

Two things ride along. The newId comment 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 as toBase64Url and 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 #104 reference 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:browser is the local command and it needs pnpm exec playwright install chromium once.

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

  • Tests added or updated
  • Behavior verified against real socket.io

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.
@electrohyun electrohyun added the chore Tooling, CI, and dependencies label Aug 5, 2026
@electrohyun electrohyun self-assigned this Aug 5, 2026
@coderabbitai

coderabbitai Bot commented Aug 5, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The 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.

Changes

Browser testing

Layer / File(s) Summary
Browser-compatible test setup
src/setup-server.browser.ts, src/connect-url.test.ts
The browser setup exports setupServer without Node-only server imports. The relative-URL test uses the existing browser origin or a Node fallback.
Vitest browser runner configuration
package.json, vitest.browser.config.ts, vitest.config.ts
The project adds the browser test command and Playwright dependencies. Vitest runs the mock target in headless Chromium and excludes the browser setup from coverage.
CI and developer workflow
.github/workflows/ci.yml, AGENTS.md, .gitignore
CI installs Chromium and runs the browser suite. Documentation describes the command, and Vitest browser artifacts are ignored.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes satisfy issue #105 by adding a Playwright Chromium browser job for the mock-target suite without changing delivery behavior.
Out of Scope Changes check ✅ Passed The CI, configuration, dependency, test, setup, ignore, and documentation changes support the linked issue objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title clearly describes the primary change: running the mock target in a browser during CI.
Description check ✅ Passed The description directly explains the browser test job, browser-specific setup, test changes, CI behavior, and related issue.

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.

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

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.
@electrohyun
electrohyun merged commit 30b57a5 into main Aug 5, 2026
8 checks passed
@electrohyun
electrohyun deleted the chore/browser-test-job branch August 5, 2026 15:35
@github-project-automation github-project-automation Bot moved this from Backlog to Done in smocket Aug 6, 2026
@github-project-automation github-project-automation Bot moved this to Backlog in smocket Aug 6, 2026
@electrohyun electrohyun added the 📏 l Pull request changes 200–999 lines label Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Tooling, CI, and dependencies 📏 l Pull request changes 200–999 lines

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

chore: run the test suite in a browser environment

2 participants