From f9dd22909cc507559bc7146fecff554dc5da5b7a Mon Sep 17 00:00:00 2001 From: soufiane Date: Tue, 18 Nov 2025 16:53:46 +0100 Subject: [PATCH] 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 --- index.js | 15 ++++++++++----- test/app.test.js | 4 ++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 3d0ddadb..c6dc7233 100644 --- a/index.js +++ b/index.js @@ -93,8 +93,13 @@ app.use("/api/draw", drawRoutes); // Error handler (doit être après les routes) app.use(errorHandler); -// Lancement serveur -const PORT = config.server.port; -app.listen(PORT, "0.0.0.0", () => { - console.log(`🚀 Backend lancé sur 0.0.0.0:${PORT} ✅`); -}); \ No newline at end of file +// Export app for testing +export default app; + +// 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} ✅`); + }); +} \ No newline at end of file diff --git a/test/app.test.js b/test/app.test.js index 2fd6a0ba..fd274a2b 100644 --- a/test/app.test.js +++ b/test/app.test.js @@ -1,5 +1,5 @@ -const request = require('supertest'); -const app = require('../index'); // ton serveur express +import request from 'supertest'; +import app from '../index.js'; describe('Test API health', () => { it('GET /health doit répondre 200', async () => {