Performance: Supertest for HTTP assertions
LOW IMPACT
This affects the speed and reliability of backend API testing, impacting development feedback loops but not the frontend rendering performance.
import request from 'supertest'; import app from './app'; describe('GET /users', () => { it('responds with json', async () => { await request(app) .get('/users') .expect('Content-Type', /json/) .expect(200); }); });
const request = require('supertest'); const app = require('./app'); describe('GET /users', () => { it('responds with json', (done) => { request(app) .get('/users') .expect('Content-Type', /json/) .expect(200) .end((err, res) => { if (err) return done(err); done(); }); }); });
| Pattern | Test Execution Time | Server Lifecycle | Error Handling | Verdict |
|---|---|---|---|---|
| Callback style with .end() | Slower due to callbacks | Starts/stops server per test (if misused) | Harder to catch errors quickly | [X] Bad |
| Async/await style | Faster with async code | Single server lifecycle | Better error propagation | [OK] Good |