tractatus/tests/setup.js
TheFlow 7fa3899050 fix: add Jest test infrastructure and reduce test failures from 29 to 13
- Add jest.config.js with test environment configuration
- Add tests/setup.js to load .env.test before tests
- Add tests/helpers/cleanup.js for test data cleanup utilities
- Add scripts/clean-test-db.js for manual test database cleanup
- Fix ObjectId constructor calls in api.admin.test.js (must use 'new')
- Add .env.test for test-specific configuration
- Use tractatus_prod database for tests (staging environment)

Test Results:
- Before: 29 failing tests (4 test suites)
- After: 13 failing tests (4 test suites)
- Progress: 16 test failures fixed (55% improvement)

Remaining Issues:
- 4 auth test failures (user creation/password mismatch)
- 4 documents test failures (duplicate keys)
- 2 admin moderation test failures
- 3 health check test failures (response structure)

🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-09 20:37:45 +13:00

15 lines
524 B
JavaScript

/**
* Jest Test Setup
* Loads .env.test before running tests and cleans test database
*/
const path = require('path');
require('dotenv').config({ path: path.resolve(__dirname, '../.env.test') });
// Set NODE_ENV to test
process.env.NODE_ENV = 'test';
// Note: We don't clean the database here in setup.js because:
// 1. It runs for every test file in parallel, causing race conditions
// 2. Each test suite should handle its own cleanup in beforeAll/beforeEach
// 3. See tests/helpers/cleanup.js for cleanup utilities