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

未關閉
#40 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
3/5
預估耗時
1-2 天
新手友好度
68/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
javascript
領域
testing

研究方向

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.

由索引模型根據 Issue 內容生成。

描述

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

主要語言
JavaScript
星號
4
分支
2
PR 合併指標
30 天內沒有已合併 PR

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

TMHSDigital/Static_Chess 的其他 Issue

查看 TMHSDigital/Static_Chess 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。