Word Search: extract pure selection/match logic + pin with vitest
Per Codex's Phase 2 audit notes. Moved the drag-snap (lineFrom) and find-match (matchWord) logic into $lib/wordsearch.js and added vitest coverage: - lineFrom always yields a straight, in-bounds path — a non-straight drag snaps, never returns bent; single cell and edge-clamping covered. - matchWord matches forward + reversed selections, is a harmless no-op on an already-found word (so completion/best-time can't double-record), and returns null for non-words / too-short selections. Restore behaviour audited: finish() (which records best-time) only runs when the final word is found mid-play; on refresh, restore() repopulates found cells + time and the derived status flips to done WITHOUT calling finish(), so best-time never re-records. First JS test runner for the frontend (npm test → vitest run). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -6,7 +6,8 @@
|
||||
"scripts": {
|
||||
"dev": "vite dev --host",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview"
|
||||
"preview": "vite preview",
|
||||
"test": "vitest run"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@sveltejs/adapter-static": "^3.0.6",
|
||||
@@ -14,6 +15,7 @@
|
||||
"@sveltejs/vite-plugin-svelte": "^5.0.0",
|
||||
"an-array-of-english-words": "^2.0.0",
|
||||
"svelte": "^5.1.0",
|
||||
"vite": "^6.0.0"
|
||||
"vite": "^6.0.0",
|
||||
"vitest": "^4.1.8"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user