Next.js 16 rebuild of the Chromatic Collapse puzzle game with MongoDB Atlas-backed leaderboards for Vercel.
- Next.js 16 App Router app in
C:\ksong\Projects\blocks\blocks-next - Win-only name submission flow with a 10-character max
- Per-difficulty leaderboards backed by MongoDB Atlas
- Top 10 leaderboard section in the right sidebar
- Server route at
/api/leaderboardfor loading and saving scores
- Copy
.env.exampleto.env.local. - Fill in:
MONGODB_URIMONGODB_DB
- Run the app:
npm install
npm run devOpen http://localhost:3000.
The repo now has three test layers:
npm testruns the Jest suite.npm run test:unitruns fast unit tests for pure game and leaderboard helpers.npm run test:integrationruns integration tests for the App Router leaderboard route and theGameShellUI with React Testing Library.npm run test:e2eruns Playwright against a local Next server onhttp://127.0.0.1:3000.npm run test:e2e:installinstalls the Playwright Chromium browser used by the default config.npm run test:seleniumruns a Selenium smoke test against the same local app.
Notes:
- Jest is configured with
next/jest, matching the Next.js 16 guidance bundled innode_modules/next/dist/docs/. - The React Testing Library setup stubs browser APIs used by the canvas board and Radix select components, including
ResizeObserver,matchMedia, andcanvas.getContext. - The Playwright test mocks
/api/leaderboardresponses so E2E runs do not require MongoDB. - The Selenium smoke test defaults to Edge on Windows and Chrome elsewhere. Override that with
SELENIUM_BROWSER=edgeorSELENIUM_BROWSER=chrome.
- The app stores leaderboard rows in a
leaderboard_entriescollection. - The required leaderboard index is created automatically on first request.
- Scores are derived from the winning completion time and the active board preset, since the game itself is time-based.
Each saved record includes:
playerNamedifficultyscorecompletionTimeMscreatedAt