test: add node:test coverage for WS URL, arrangement, and prefs logic#19
Conversation
Node-only module.exports hook placed at the very end of the IIFE (after every let/const initializer has run and FOLLOWER-mode is correctly skipped in Node), exporting getWsUrl, resolveArrIndex, getDefaultArrangements, panelToPrefs, migratePanelPrefs, _ctlRange plus a test-only arrangements setter. Tests stub window/document/ localStorage minimally; no deps needed. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThis PR adds a guarded Node/test-only export block in ChangesTest exports and coverage
Estimated code review effort: 2 (Simple) | ~12 minutes Possibly related issues
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
tests/screen.test.js (2)
18-36: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win
freshPlugin()hardcodesprotocol: 'http:', ignoring any caller-provided protocol.This forces the
wss://test (Line 50-55) to work around it by mutatingglobal.location.protocolafterfreshPlugin()runs, relying on the fact thatgetWsUrlreads the sharedlocationobject reference dynamically at call time rather than at require time. It works, but it's fragile and the location object assigned at Line 51 is effectively dead code sincefreshPlugin()immediately replaces it.Consider parameterizing
protocolalongsidesearchfor clarity:♻️ Proposed refactor
-function freshPlugin({ search = '' } = {}) { - const location = { search, host: 'localhost:8420', protocol: 'http:' }; +function freshPlugin({ search = '', protocol = 'http:' } = {}) { + const location = { search, host: 'localhost:8420', protocol };🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/screen.test.js` around lines 18 - 36, freshPlugin() currently hardcodes window.location.protocol to http:, which makes protocol-sensitive tests depend on later mutation and hides the intended setup. Update freshPlugin to accept a protocol option alongside search, and use that value when building the shared location object assigned to global.window and global.location. Then adjust the wss:// test to pass the protocol through freshPlugin instead of mutating global.location.protocol afterward, so the setup stays explicit and stable.
50-55: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winSimplify by using the
protocolparam instead of post-hoc mutation.Once
freshPlugin()acceptsprotocol, this test can pass it directly instead of pre-settingglobal.location(which gets discarded) and patching it after the fact.♻️ Proposed fix
test('getWsUrl uses wss:// under https', () => { - global.location = { search: '', host: 'x', protocol: 'https:' }; - const { getWsUrl } = freshPlugin(); - global.location.protocol = 'https:'; // freshPlugin rebuilds location; keep consistent + const { getWsUrl } = freshPlugin({ protocol: 'https:' }); assert.match(getWsUrl('a.sloppak', 1), /^wss:\/\//); });🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/screen.test.js` around lines 50 - 55, The test setup for getWsUrl is mutating global.location after freshPlugin() rebuilds it, which is unnecessary once protocol can be passed directly. Update the test to supply the https protocol through freshPlugin() itself and remove the pre-setting and post-hoc mutation of global.location, keeping the assertion against getWsUrl unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@tests/screen.test.js`:
- Around line 18-36: freshPlugin() currently hardcodes window.location.protocol
to http:, which makes protocol-sensitive tests depend on later mutation and
hides the intended setup. Update freshPlugin to accept a protocol option
alongside search, and use that value when building the shared location object
assigned to global.window and global.location. Then adjust the wss:// test to
pass the protocol through freshPlugin instead of mutating
global.location.protocol afterward, so the setup stays explicit and stable.
- Around line 50-55: The test setup for getWsUrl is mutating global.location
after freshPlugin() rebuilds it, which is unnecessary once protocol can be
passed directly. Update the test to supply the https protocol through
freshPlugin() itself and remove the pre-setting and post-hoc mutation of
global.location, keeping the assertion against getWsUrl unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 86f4662c-8a58-4030-a253-f37f9656668d
📒 Files selected for processing (2)
screen.jstests/screen.test.js
Coderabbit nit: the wss:// test mutated global.location after freshPlugin() already rebuilt it, relying on getWsUrl reading the shared reference at call time. Pass protocol through directly. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Eighth repo from the org test-coverage audit. screen.js interleaves top-level DOM/window access with function declarations throughout (not a clean declarations-then-init split like earlier plugins), so the
module.exportshook sits at the very end of the IIFE instead of before init — after everylet/constbinding the exported functions close over has run its initializer, and after the FOLLOWER-mode bootstrap check (which no-ops under Node sincelocation.searchis empty).15 tests:
%2F→/, matching core highway.js), arrangement param, ws/wss protocol selection_ctlRange: default/clamped bounds, non-finite → defaults__3d_highway__sentinel migration, no reset once already migratedA test-only
_setArrangementsForTestsetter is exported alongside the real functions sincearrangementsis a closuredletthe tested functions read.🤖 Generated with Claude Code
Summary by CodeRabbit