Create tests for interface and preload files#7
Conversation
Co-authored-by: acrosman <2972053+acrosman@users.noreply.github.com>
Co-authored-by: acrosman <2972053+acrosman@users.noreply.github.com>
…images, sound, display range, progress fix) Co-authored-by: acrosman <2972053+acrosman@users.noreply.github.com>
…ling blank lines Co-authored-by: acrosman <2972053+acrosman@users.noreply.github.com>
Co-authored-by: acrosman <2972053+acrosman@users.noreply.github.com>
…ectly Co-authored-by: acrosman <2972053+acrosman@users.noreply.github.com>
… Speed Memory Co-authored-by: acrosman <2972053+acrosman@users.noreply.github.com>
…ve countdown banner Co-authored-by: acrosman <2972053+acrosman@users.noreply.github.com>
This reverts commit 21c9042.
Co-authored-by: acrosman <2972053+acrosman@users.noreply.github.com>
…labels, audio context, game logic validation Co-authored-by: acrosman <2972053+acrosman@users.noreply.github.com> Agent-Logs-Url: https://github.com/acrosman/BrainSpeedExercises/sessions/550ed7f7-9f1e-42b0-91bb-31cec38618ae
… shifts Co-authored-by: acrosman <2972053+acrosman@users.noreply.github.com> Agent-Logs-Url: https://github.com/acrosman/BrainSpeedExercises/sessions/adc8dc8c-bc12-402a-bdd6-6c45bc00a4a5
…teGameCard Co-authored-by: acrosman <2972053+acrosman@users.noreply.github.com> Agent-Logs-Url: https://github.com/acrosman/BrainSpeedExercises/sessions/c59600aa-4016-4483-8135-bbf8b78db514
* main: (39 commits) Package file clean up Revert response panel hide/show during trial phases to prevent layout shifts Address review feedback: fix imports, manifest, split index.js, aria labels, audio context, game logic validation Initial plan Further improved game play. Fix timer ordering in submitSelection, update JSDoc for init and createGameCard Initial plan Improved game play Adding images, updating to use images. Update game name in index file. First draft of field of view game. Improved orbit memory game play. Updates to improve game play of rabbit memory First draft of bunny memory Fix to wrong answer guidance. NPM Update Update end game modal Fix to wrong answer guidance. NPM Update Bump flatted in the npm_and_yarn group across 1 directory ...
There was a problem hiding this comment.
Pull request overview
Adds Jest coverage for previously untested renderer/preload code and extends existing game/plugin test suites to hit additional lifecycle and helper paths.
Changes:
- Adds new Jest test suites for
app/interface.js(renderer) andapp/preload.js(preload/IPC bridge). - Improves renderer robustness by handling
games:listIPC failures inapp/interface.js. - Expands several existing game/plugin tests and registry tests to cover additional branches and event wiring.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| app/preload.test.js | New tests for the preload context-bridge API (send/receive/invoke allowlists). |
| app/interface.test.js | New jsdom tests covering renderer init, game selection flow, stylesheet injection, and return-to-menu behavior. |
| app/interface.js | Adds try/catch around games:list to render a user-facing error on failure. |
| app/games/registry.test.js | Adds tests for default importFn behavior and multi-game selection. |
| app/games/orbit-sprite-memory/tests/index.test.js | Adds coverage for audio close rejection handling, flash timeouts, selection flow, and best-stats loading. |
| app/games/high-speed-memory/tests/index.test.js | Adds coverage for audio close rejection handling and click listener wiring. |
| app/games/field-of-view/tests/index.test.js | Adds coverage for click wiring, early-return paths, timers/RAF branches, and next-trial behavior. |
| app/games/fast-piggie/tests/index.test.js | Adds coverage for end-panel flow, return-to-menu dispatch, timer callbacks, and image-load failure paths. |
| app/games/fast-piggie/tests/game.test.js | Adds tests for the new/updated getBestStats() contract and behavior. |
| app/components/gameCard.js | Adds a field-of-view stats display branch on the game card UI. |
| mocks/electron.js | Extends Electron Jest mock to include contextBridge and ipcRenderer. |
| global.require = jest.fn((moduleName) => { | ||
| if (moduleName === 'electron') { | ||
| return { | ||
| contextBridge: mockContextBridge, | ||
| ipcRenderer: mockIpcRenderer, | ||
| }; | ||
| } | ||
| throw new Error(`Unexpected module requested: ${moduleName}`); | ||
| }); | ||
|
|
||
| await import('./preload.js'); | ||
|
|
There was a problem hiding this comment.
global.require won't provide a lexical require binding for ES modules, and even if preload.js were treated as CommonJS, its local require would not be affected by global.require. This makes the await import('./preload.js') setup brittle and likely to fail or load the real electron module. Prefer mocking electron via Jest's ESM mocking (jest.unstable_mockModule('electron', ...) before importing preload.js) or by refactoring preload.js to use ESM imports so it can be imported and mocked consistently in tests.
| if (manifest.id === 'field-of-view' && progress) { | ||
| scoreElem = document.createElement('p'); | ||
| scoreElem.className = 'game-high-score'; | ||
|
|
||
| if (typeof progress.bestThresholdMs === 'number') { | ||
| scoreElem.textContent = `All-time Best Threshold: ${progress.bestThresholdMs}ms`; | ||
| } else { | ||
| scoreElem.textContent = 'All-time Best Threshold: No data yet'; | ||
| } | ||
|
|
||
| scoreElem.setAttribute('aria-label', `Stats for ${manifest.name}: ${scoreElem.textContent}`); | ||
| } | ||
|
|
There was a problem hiding this comment.
This field-of-view progress rendering block is duplicated (an identical if (manifest.id === 'field-of-view' && progress) block appears immediately above). Keeping both adds dead code and increases the chance of future divergence. Remove the duplicate and keep a single code path for the field-of-view stats rendering.
| if (manifest.id === 'field-of-view' && progress) { | |
| scoreElem = document.createElement('p'); | |
| scoreElem.className = 'game-high-score'; | |
| if (typeof progress.bestThresholdMs === 'number') { | |
| scoreElem.textContent = `All-time Best Threshold: ${progress.bestThresholdMs}ms`; | |
| } else { | |
| scoreElem.textContent = 'All-time Best Threshold: No data yet'; | |
| } | |
| scoreElem.setAttribute('aria-label', `Stats for ${manifest.name}: ${scoreElem.textContent}`); | |
| } |
|
@copilot open a new pull request to apply changes based on the comments in this thread |
…lock Co-authored-by: acrosman <2972053+acrosman@users.noreply.github.com> Agent-Logs-Url: https://github.com/acrosman/BrainSpeedExercises/sessions/79b2abf0-fe3d-4b34-ae9e-d456f73424d7
…ted tests for FoV, OSM Co-authored-by: acrosman <2972053+acrosman@users.noreply.github.com> Agent-Logs-Url: https://github.com/acrosman/BrainSpeedExercises/sessions/a0470ad6-e86a-48b3-ab49-8e4ae55f493c
…Game, integration tests Co-authored-by: acrosman <2972053+acrosman@users.noreply.github.com> Agent-Logs-Url: https://github.com/acrosman/BrainSpeedExercises/sessions/9b111692-7ad6-4fb5-b1f2-0af22bdfb9ac
Co-authored-by: acrosman <2972053+acrosman@users.noreply.github.com> Agent-Logs-Url: https://github.com/acrosman/BrainSpeedExercises/sessions/9f474ce9-da51-430f-bf65-4759799c1b6e
Remove duplicate gameCard block, restore branch coverage, fix game loading, and add regression tests
Adds testing to currently untested code files.