Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cypress/e2e/screenshots.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ describe("Game Visual Documentation", () => {
win.dispatchEvent(new CustomEvent('test:targetClick'));
win.dispatchEvent(new CustomEvent('test:targetClick'));
});


// Wait for React to process the state updates (consistent with gameplay.cy.ts pattern)
cy.wait(100);

// Verify score updated
cy.get("[data-testid=score-value]").should("not.contain", "0");

Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Canvas } from "@react-three/fiber";
import { useRef, useState, useCallback, useEffect } from "react";
import { useRef, useState, useCallback, useEffect, useLayoutEffect } from "react";
import type { JSX } from "react";
import { useGameState } from "./hooks/useGameState";
import { useAudioManager } from "./hooks/useAudioManager";
Expand Down Expand Up @@ -96,7 +96,10 @@ function App(): JSX.Element {
const gameStateRef = useRef(gameState);
gameStateRef.current = gameState;

useEffect(() => {
// useLayoutEffect (not useEffect) ensures the listener is registered synchronously
// before the browser paints, preventing a race where Cypress finds the target-sphere
// in the DOM before the test event listener is ready to receive events.
useLayoutEffect(() => {
const handleTestTargetClick = (): void => {
const gs = gameStateRef.current;
if (gs.isPlaying && gs.timeLeft > 0 && gs.targets.length > 0) {
Expand Down
Loading