Documentation for the Enigma puzzle collection
Enigma uses a hybrid testing approach to handle the complexities of testing both frontend React components and backend plugin system functionality.
src/**/*.test.js, src/**/*.test.jsxnpm test or npm run test:run.github/workflows/vitest.ymlAll frontend tests run smoothly with vitest's default configuration.
The backend plugin system uses better-sqlite3, a native Node.js module that causes segmentation faults when loaded in vitest's worker pool. To work around this, we use two approaches:
backend/test-scripts/*.jsnpm run test:backend-standaloneExample output:
๐งช Testing Plugin Database Isolation...
โ
PASS: Plugin databases are separate files
โ
PASS: Plugin A can store data
โ
PASS: Plugin B cannot access Plugin A tables
โ
PASS: Plugin B can store independent data
โ
PASS: Plugin A still cannot see Plugin B data
โ
PASS: Can calculate database file size
tests/integration/backend-plugins.test.jsnpm run test:backend-integrationcd backend && npm start)These tests will verify plugin functionality through HTTP endpoints once the plugin API is exposed.
backend/src/plugins/*.test.js--runInBand (requires different test framework)npm test
# or
npm run test:run
npm run test:backend-standalone
npm run test:run && npm run test:backend-standalone
npm test -- src/pages/Sudoku/Sudoku.test.js
npm test
.github/workflows/vitest.yml)Runs on every push and PR:
npm run test:run)npm run test:backend-standalone).github/workflows/integration-tests.yml)Runs when backend or integration test files change:
Problem: better-sqlite3 is a native Node.js addon that causes segmentation faults when loaded in vitest's worker threads/forks.
Solutions tried:
beforeAll hooksRoot cause: Native modules and worker pools fundamentally don't mix well.
Final solution:
Create *.test.js or *.test.jsx files next to your components. They'll automatically be picked up by vitest.
backend/test-scripts/tests/integration/backend-plugins.test.jsbackend/src/plugins/*.test.js as documentationRun coverage reports:
npm run test:coverage
View in browser:
npm run test:ui:coverage
backend/src/plugins/*.test.jsvite.config.js exclude patternsbetter-sqlite3 is installed: npm list better-sqlite3node --versioncd backend && npm starthttp://localhost:3000/api/health