Performance: Jest or Vitest setup for Express
MEDIUM IMPACT
This affects the development workflow speed and test execution time, impacting how quickly developers get feedback.
import express from 'express'; import request from 'supertest'; import { describe, test, expect } from 'vitest'; // Import only the route handler or use a lightweight app instance const app = express(); app.get('/', (req, res) => res.send('OK')); describe('Express route test', () => { test('GET / endpoint', async () => { const response = await request(app).get('/'); expect(response.status).toBe(200); }); });
import express from 'express'; import request from 'supertest'; // Full app import with all middleware and database connections import app from './app'; describe('Express app tests', () => { test('GET / endpoint', async () => { const response = await request(app).get('/'); expect(response.status).toBe(200); }); });
| Pattern | Module Loading Time | Memory Usage | Test Startup Delay | Verdict |
|---|---|---|---|---|
| Full app import with all middleware | High (300-500ms) | High | High (500ms+) | [X] Bad |
| Minimal Express instance or isolated routes | Low (under 100ms) | Low | Low (under 100ms) | [OK] Good |