| name | Test Runner |
| description | Run Vitest tests for the Babylon.js game project. Use when the user wants to run tests, check test coverage, debug failing tests, or validate code functionality. |
Test Runner
Run and manage Vitest tests for the project.
Quick Start
Run all tests
cd /home/gianfiorenzo/Documents/Vs\ Code/babylon_fp
npm test
Run tests in watch mode
cd /home/gianfiorenzo/Documents/Vs\ Code/babylon_fp
npm run test:watch
Run tests with coverage
cd /home/gianfiorenzo/Documents/Vs\ Code/babylon_fp
npm run test:coverage
Test Commands
Run specific test file
cd /home/gianfiorenzo/Documents/Vs\ Code/babylon_fp
npx vitest run tests/state/stateManager.test.ts
Run tests matching pattern
cd /home/gianfiorenzo/Documents/Vs\ Code/babylon_fp
npx vitest run -t "StateManager"
Run tests in specific directory
cd /home/gianfiorenzo/Documents/Vs\ Code/babylon_fp
npx vitest run tests/systems/
Run with verbose output
cd /home/gianfiorenzo/Documents/Vs\ Code/babylon_fp
npx vitest run --reporter=verbose
Test Analysis
Show test summary
cd /home/gianfiorenzo/Documents/Vs\ Code/babylon_fp
npx vitest run --reporter=verbose | tail -20
Check test count
cd /home/gianfiorenzo/Documents/Vs\ Code/babylon_fp
find tests -name "*.test.ts" -exec echo {} \; | wc -l
echo "test files found"
List all test files
cd /home/gianfiorenzo/Documents/Vs\ Code/babylon_fp
find tests -name "*.test.ts" -o -name "*.spec.ts"
Coverage Analysis
Generate HTML coverage report
cd /home/gianfiorenzo/Documents/Vs\ Code/babylon_fp
npm run test:coverage
# Report will be in coverage/index.html
Check coverage thresholds
cd /home/gianfiorenzo/Documents/Vs\ Code/babylon_fp
npx vitest run --coverage --coverage.reporter=text-summary
Debugging Tests
Run with console output
cd /home/gianfiorenzo/Documents/Vs\ Code/babylon_fp
npx vitest run --no-coverage --reporter=verbose
Run single test file with debugging
cd /home/gianfiorenzo/Documents/Vs\ Code/babylon_fp
npx vitest run tests/systems/loopManager.test.ts --no-coverage
Check for test failures
cd /home/gianfiorenzo/Documents/Vs\ Code/babylon_fp
npm test 2>&1 | grep -E "(FAIL|✓|✗|Error)"
Test Quality Checks
Count assertions per file
cd /home/gianfiorenzo/Documents/Vs\ Code/babylon_fp
for file in tests/**/*.test.ts; do
echo "$file: $(grep -c 'expect(' $file) assertions"
done
Find test files without assertions
cd /home/gianfiorenzo/Documents/Vs\ Code/babylon_fp
for file in tests/**/*.test.ts; do
if ! grep -q 'expect(' "$file"; then
echo "No assertions: $file"
fi
done
Continuous Testing
Watch mode (auto-rerun on file changes)
cd /home/gianfiorenzo/Documents/Vs\ Code/babylon_fp
npx vitest watch
Watch specific tests
cd /home/gianfiorenzo/Documents/Vs\ Code/babylon_fp
npx vitest watch tests/systems/
Test Organization
Current test structure:
tests/content/- Content loading teststests/state/- State management teststests/systems/- System tests (LoopManager, TimeSync, etc.)tests/ui/- UI component teststests/helpers/- Test utilities and mocks
Best Practices
- Run tests before committing: Ensure all tests pass
- Watch mode during development: Catch issues immediately
- Coverage tracking: Aim for >80% coverage on critical systems
- Test naming: Use descriptive test names (describe/it pattern)
- Isolated tests: Each test should be independent
- Mock external dependencies: Use test helpers from
tests/helpers/
Common Test Patterns
Testing async code
it('should handle async operations', async () => {
const result = await asyncFunction();
expect(result).toBe(expected);
});
Testing Babylon.js components
import { mockScene, mockCamera } from '../helpers/testUtils';
it('should initialize scene', () => {
const scene = mockScene();
const camera = mockCamera(scene);
expect(scene).toBeDefined();
});
Testing state changes
it('should update state', () => {
stateManager.setState({ key: 'value' });
expect(stateManager.getState('key')).toBe('value');
});