Optimize tests, takes ~20% less (#184)

Co-authored-by: antanst <>
This commit is contained in:
Antonis Anastasiadis 2025-07-20 16:33:58 +03:00 committed by GitHub
parent 468e299059
commit 3cc9ec2191
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 10 deletions

View file

@ -14,15 +14,17 @@ beforeAll(async () => {
beforeEach(async () => {
// Clean all tables except Sessions to avoid conflicts
try {
const models = Object.values(sequelize.models);
const nonSessionModels = models.filter(
(model) => model.name !== 'Session'
);
await Promise.all(
nonSessionModels.map((model) =>
model.destroy({ truncate: true, cascade: true })
)
);
// Use raw SQL for faster cleanup
const tableNames = [
'users', 'areas', 'projects', 'tasks', 'tags', 'notes',
'inbox_items', 'task_events', 'tasks_tags', 'notes_tags', 'projects_tags'
];
await sequelize.query('PRAGMA foreign_keys = OFF');
for (const tableName of tableNames) {
await sequelize.query(`DELETE FROM ${tableName}`);
}
await sequelize.query('PRAGMA foreign_keys = ON');
} catch (error) {
// Ignore errors during cleanup
}

View file

@ -4,7 +4,7 @@ const { User } = require('../../models');
const createTestUser = async (userData = {}) => {
const defaultUser = {
email: 'test@example.com',
password: 'password123', // Use password field to trigger model hook
password_digest: '$2b$10$DPcA0XSvK9FT04mLyKGza.uHb8d.bESwP.XdQfQ47.sKVT4fYzbP.', // Pre-computed hash for 'password123'
...userData,
};