Tests share module state: add a shared loader that resets modules per test

Aperta
#40 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
javascript
Ambito
testing

Direzione di ricerca

Read tests/unit/game-moves.test.js and tests/integration/game-flow.test.js, then inspect the module-level DOM references in js/board.js and js/game.js. Implement the shared loader and position-builder described in the issue, update both test files, and run npm test and npm run lint. Done when consecutive loads are shown to be independent and both test files use the helper.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

severity: medium testing

Summary

Each beforeEach builds a new JSDOM and then requires the game modules, but nothing calls jest.resetModules(). A second test in the same file would get the cached modules, which still hold the first test's DOM nodes and game state.

Where

  • tests/unit/game-moves.test.js:6-109, tests/integration/game-flow.test.js:6-116 (about 100 duplicated setup lines each)
  • js/board.js:5, js/game.js:17-18 (DOM nodes captured at module load)
  • js/game.js:27 (reset happens only when history is empty)

Details

This is from reading the code, assuming Jest's default of one module registry per test file; the suite was not run. It is invisible today only because each file holds exactly one test.

Impact

The first contributor who adds a second test to either file gets order-dependent failures or false passes. This blocks the test work in #41 and #42.

Suggested fix

Move the setup into one helper, for example tests/helpers/load-game.js, that calls jest.resetModules(), creates the JSDOM, sets the globals, requires the modules and returns { window, game, board }. Add a position-builder that places pieces on an empty board and sets king positions.

Acceptance criteria

  • Both existing test files use the helper
  • A test proves two consecutive loads are independent
  • A position-builder exists for non-starting positions

Getting started

  • Relevant files: tests/unit/game-moves.test.js, tests/integration/game-flow.test.js
  • How to run tests: npm install, then npm test and npm run lint
  • Related docs: docs/ARCHITECTURE.md, .github/CONTRIBUTING.md

Filed by repo-audit/full-audit at 8a2c86c. Severity: medium. Effort: S. audit-key: testing|tests/unit/game-moves.test.js|beforeEach

Lingua principale
JavaScript
Stelle
4
Fork
2
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di TMHSDigital/Static_Chess

Tutte le issue di TMHSDigital/Static_Chess

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.