Skip to content

Add integration tests for main() entry point in game.test.js #256

@arasaka-net

Description

@arasaka-net

The application entry point main() in game.js has zero test coverage. Its fetch-error fallback, global event listeners, and module initialization orchestration are all untested.

Context
game.test.js covers setupCorp and setupRunner but stops there. The main() function (lines 52–87) is the actual entry point imported by index.html. It fetches the card database, handles fetch failure by rendering an error message, registers three global event listeners (middle-click prevention, context menu dismissal, auxclick dismissal), and calls setupKeyboardShortcuts, setupP2P, setupSidePanels, and setupTokenSpawning. None of these behaviors have any test coverage. A fetch failure in production silently renders a <p> tag and returns — if that rendering ever breaks, no test will catch it. The module initialization order is also load-bearing (e.g., setupP2P queries DOM elements created by index.html) and deserves at least a smoke-level integration test.

Affected Files

  • src/scripts/game.test.js — Add a describe("main") block with tests for the fetch-error path and the success path
  • src/scripts/game.js:52 — The main() function under test — no changes needed to the source

Requirements

  • A test verifies that when fetchAllCards rejects, main() appends a #fetch-error element with the expected message text and returns without calling setupP2P or other initialization functions.
  • A test verifies that when fetchAllCards resolves, main() populates window.allCards and calls setupKeyboardShortcuts, setupP2P, setupSidePanels, and setupTokenSpawning.
  • A test verifies that main() maps each card entry to include an image URL derived from card.code.
  • All existing tests continue to pass.

Verification

  • npm test -- --reporter=verbose src/scripts/game.test.js
  • npm test

Not In Scope

  • Do not refactor main() — test the existing behavior as-is.
  • Do not add tests for setupP2P internals — those belong in p2p.test.js.
  • Do not test the window.addEventListener('load', ...) wrapper in index.html.

Evidence

  • src/scripts/game.test.js — File contains describe blocks for setupCorp and setupRunner only — no mention of main
  • src/scripts/game.js:52-67main() catches fetch errors and renders a #fetch-error paragraph — untested path
  • src/scripts/game.js:69-86main() registers three global event listeners and calls four setup functions — none covered by any test

Arasaka Queue Planning Division.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions