Performance: Testing authentication flows
MEDIUM IMPACT
Testing authentication flows affects the development feedback loop and server response time during tests, impacting developer productivity and CI pipeline speed.
const request = require('supertest'); const app = require('../app'); const authService = require('../services/authService'); jest.mock('../services/authService'); test('login with mocked auth service', async () => { authService.login.mockResolvedValue({ token: 'fake-token' }); const response = await request(app) .post('/login') .send({ username: 'user', password: 'pass' }); expect(response.statusCode).toBe(200); expect(response.body.token).toBe('fake-token'); });
const request = require('supertest'); const app = require('../app'); test('login with real DB', async () => { const response = await request(app) .post('/login') .send({ username: 'user', password: 'pass' }); expect(response.statusCode).toBe(200); });
| Pattern | Server Calls | Test Duration | Resource Usage | Verdict |
|---|---|---|---|---|
| Real DB calls in tests | Multiple real DB queries | Slow (100-300ms per test) | High CPU and DB load | [X] Bad |
| Mocked auth service | No real DB calls | Fast (10-50ms per test) | Low resource usage | [OK] Good |
| Full server startup | Starts HTTP server | Slow startup (500ms+) | High memory and CPU | [X] Bad |
| Direct app instance with supertest | No server startup | Fast startup | Low resource usage | [OK] Good |