fix: convert test to ES6 modules and export app
- Convert test/app.test.js from CommonJS to ES6 import/export - Export app from index.js for testing - Only start server if NODE_ENV !== 'test' - Fixes 'require is not defined' error in tests
This commit is contained in:
parent
51d8b0cc36
commit
f9dd22909c
15
index.js
15
index.js
|
|
@ -93,8 +93,13 @@ app.use("/api/draw", drawRoutes);
|
||||||
// Error handler (doit être après les routes)
|
// Error handler (doit être après les routes)
|
||||||
app.use(errorHandler);
|
app.use(errorHandler);
|
||||||
|
|
||||||
// Lancement serveur
|
// Export app for testing
|
||||||
const PORT = config.server.port;
|
export default app;
|
||||||
app.listen(PORT, "0.0.0.0", () => {
|
|
||||||
console.log(`🚀 Backend lancé sur 0.0.0.0:${PORT} ✅`);
|
// Lancement serveur (seulement si pas importé par les tests)
|
||||||
});
|
if (process.env.NODE_ENV !== 'test') {
|
||||||
|
const PORT = config.server.port;
|
||||||
|
app.listen(PORT, "0.0.0.0", () => {
|
||||||
|
console.log(`🚀 Backend lancé sur 0.0.0.0:${PORT} ✅`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
const request = require('supertest');
|
import request from 'supertest';
|
||||||
const app = require('../index'); // ton serveur express
|
import app from '../index.js';
|
||||||
|
|
||||||
describe('Test API health', () => {
|
describe('Test API health', () => {
|
||||||
it('GET /health doit répondre 200', async () => {
|
it('GET /health doit répondre 200', async () => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user