Enigma Game Documentation

Documentation for the Enigma puzzle collection

View the Project on GitHub ianfhunter/Enigma

Testing Strategy

Overview

Enigma uses a hybrid testing approach to handle the complexities of testing both frontend React components and backend plugin system functionality.

Test Structure

Frontend Tests (3,425+ tests)

All frontend tests run smoothly with vitest's default configuration.

Backend Plugin Tests

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:

1. Standalone Tests (6 tests)

Example 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

2. Integration Tests (Placeholders)

These tests will verify plugin functionality through HTTP endpoints once the plugin API is exposed.

3. Original Unit Tests (72 tests - Reference Only)

Running Tests Locally

Run all frontend tests:

npm test
# or
npm run test:run

Run backend plugin tests:

npm run test:backend-standalone

Run both:

npm run test:run && npm run test:backend-standalone

Run specific test files:

npm test -- src/pages/Sudoku/Sudoku.test.js

Run tests in watch mode:

npm test

CI/CD

Main Test Workflow (.github/workflows/vitest.yml)

Runs on every push and PR:

  1. Frontend tests (npm run test:run)
  2. Backend plugin standalone tests (npm run test:backend-standalone)

Integration Tests Workflow (.github/workflows/integration-tests.yml)

Runs when backend or integration test files change:

  1. Backend plugin standalone tests
  2. Integration tests (currently placeholders)

Why This Approach?

Problem: better-sqlite3 is a native Node.js addon that causes segmentation faults when loaded in vitest's worker threads/forks.

Solutions tried:

Root cause: Native modules and worker pools fundamentally don't mix well.

Final solution:

Adding New Tests

Frontend tests:

Create *.test.js or *.test.jsx files next to your components. They'll automatically be picked up by vitest.

Backend plugin tests:

  1. For quick verification: Add to or create new scripts in backend/test-scripts/
  2. For API testing: Add to tests/integration/backend-plugins.test.js
  3. For reference: Keep comprehensive unit tests in backend/src/plugins/*.test.js as documentation

Test Coverage

Run coverage reports:

npm run test:coverage

View in browser:

npm run test:ui:coverage

Troubleshooting

"Worker fork errors" in test output

Standalone tests fail

Integration tests always skip