Tests share module state: add a shared loader that resets modules per test
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Facilidade para iniciantes
- 68/100
- Tipo de issue
- Bug
- Clareza
- Claramente especificada
- Status de atividade
- Ativa
- Stack de tecnologia
- javascript
- Domínio
- testing
Direção de pesquisa
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.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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, thennpm testandnpm 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
- Linguagem predominante
- JavaScript
- Estrelas
- 4
- Forks
- 2
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de TMHSDigital/Static_Chess
-
enhancement good first issue severity: medium
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
TMHSDigital/Static_Chess#53 ·
-
documentation good first issue severity: low
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
TMHSDigital/Static_Chess#49 ·
-
documentation good first issue severity: low
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 83/100
TMHSDigital/Static_Chess#48 ·
-
documentation severity: medium
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
TMHSDigital/Static_Chess#47 ·
-
documentation good first issue severity: low
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
TMHSDigital/Static_Chess#46 ·
Todas as issues de TMHSDigital/Static_Chess
Issues semelhantes
-
good first issue tests
Dificuldade 1/5 1-3 horas Facilidade para iniciantes 68/100
Mantenedores costumam responder em até 1 dia
-
enhancement good first issue
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 90/100
-
1️⃣ phase/under-investigation flaky/confirmed flaky/needs-decision type/bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 65/100
growilabs/growi#12246 · 3 comentários ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 72/100
TMHSDigital/Free-Game-Dev-Assets#301 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 79/100