Skip to content

Create tests for interface and preload files#7

Merged
acrosman merged 53 commits intomainfrom
feature/interface-preload-tests
Mar 24, 2026
Merged

Create tests for interface and preload files#7
acrosman merged 53 commits intomainfrom
feature/interface-preload-tests

Conversation

@acrosman
Copy link
Copy Markdown
Owner

Adds testing to currently untested code files.

acrosman and others added 30 commits March 15, 2026 23:30
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>
Copilot AI and others added 15 commits March 22, 2026 18:25
…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
* 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
  ...
@acrosman acrosman marked this pull request as ready for review March 23, 2026 02:39
@acrosman acrosman requested a review from Copilot March 23, 2026 02:40
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) and app/preload.js (preload/IPC bridge).
  • Improves renderer robustness by handling games:list IPC failures in app/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.

Comment on lines +14 to +25
global.require = jest.fn((moduleName) => {
if (moduleName === 'electron') {
return {
contextBridge: mockContextBridge,
ipcRenderer: mockIpcRenderer,
};
}
throw new Error(`Unexpected module requested: ${moduleName}`);
});

await import('./preload.js');

Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +76 to +88
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}`);
}

Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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 uses AI. Check for mistakes.
@acrosman
Copy link
Copy Markdown
Owner Author

@copilot open a new pull request to apply changes based on the comments in this thread

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 23, 2026

@acrosman I've opened a new pull request, #26, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 5 commits March 23, 2026 18:24
…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
Remove duplicate gameCard block, restore branch coverage, fix game loading, and add regression tests
@acrosman acrosman merged commit 006da52 into main Mar 24, 2026
4 checks passed
@acrosman acrosman deleted the feature/interface-preload-tests branch March 24, 2026 01:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants