From 9330c68e5cc07c767f80c72cf5aadb02ad3b3c08 Mon Sep 17 00:00:00 2001 From: soufiane Date: Tue, 18 Nov 2025 15:40:04 +0100 Subject: [PATCH] fix: improve CI/CD quality checks and fix test/lint configuration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Backend fixes: - Add eslint.config.js with proper ES6 module configuration - Add jest.config.js to support ES modules - Update package.json with @eslint/js dependency - Configure npm test script with NODE_OPTIONS for ES modules - Update Jenkinsfile to block deployments on failed lint/tests This ensures: 1. ESLint works correctly with ES6 modules 2. Jest can run tests with ES6 imports 3. Deployments are blocked if quality checks fail đŸ€– Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- Jenkinsfile | 19 ++++++++++++++----- eslint.config.js | 36 ++++++++++++++++++++++++++++++++++++ jest.config.js | 37 +++++++++++++++++++++++++++++++++++++ package.json | 5 +++-- 4 files changed, 90 insertions(+), 7 deletions(-) create mode 100644 eslint.config.js create mode 100644 jest.config.js diff --git a/Jenkinsfile b/Jenkinsfile index a90eb4fb..90f17b83 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -77,11 +77,20 @@ pipeline { } steps { echo "đŸ§Ș Lancement des tests et analyse..." - sh ''' - npm ci - npm run lint || echo "⚠ Erreurs de lint dĂ©tectĂ©es" - npm test || echo "⚠ Tests Ă©chouĂ©s — ignorĂ©s pour le dĂ©ploiement" - ''' + script { + def lintStatus = sh(script: 'npm ci && npm run lint', returnStatus: true) + def testStatus = sh(script: 'npm test', returnStatus: true) + + if (lintStatus != 0) { + error "❌ ESLint a Ă©chouĂ© - Le dĂ©ploiement est bloquĂ©" + } + + if (testStatus != 0) { + error "❌ Les tests ont Ă©chouĂ© - Le dĂ©ploiement est bloquĂ©" + } + + echo "✅ Tests et lint passĂ©s avec succĂšs" + } } } diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 00000000..e8f37268 --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,36 @@ +import js from '@eslint/js'; + +export default [ + js.configs.recommended, + { + languageOptions: { + ecmaVersion: 2022, + sourceType: 'module', + globals: { + // Node.js globals + console: 'readonly', + process: 'readonly', + Buffer: 'readonly', + __dirname: 'readonly', + __filename: 'readonly', + global: 'readonly', + module: 'readonly', + require: 'readonly', + exports: 'writable', + }, + }, + rules: { + 'no-unused-vars': ['warn', { argsIgnorePattern: '^_' }], + 'no-console': 'off', + 'no-undef': 'error', + }, + }, + { + ignores: [ + 'node_modules/**', + 'dist/**', + 'coverage/**', + '*.config.js', + ], + }, +]; diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 00000000..6fa789eb --- /dev/null +++ b/jest.config.js @@ -0,0 +1,37 @@ +export default { + // Use Node's experimental ESM support + testEnvironment: 'node', + + // Transform ES modules + transform: {}, + + // Extensions to consider + extensionsToTreatAsEsm: ['.js'], + + // Module name mapper for ES modules + moduleNameMapper: { + '^(\\.{1,2}/.*)\\.js$': '$1', + }, + + // Test match patterns + testMatch: [ + '**/test/**/*.test.js', + '**/__tests__/**/*.js', + ], + + // Coverage configuration + collectCoverageFrom: [ + 'src/**/*.js', + '!src/**/*.test.js', + '!**/node_modules/**', + ], + + // Ignore patterns + testPathIgnorePatterns: [ + '/node_modules/', + '/dist/', + ], + + // Verbose output + verbose: true, +}; diff --git a/package.json b/package.json index 945a342b..e1b6535f 100755 --- a/package.json +++ b/package.json @@ -8,8 +8,8 @@ "start": "node index.js", "dev": "nodemon index.js", "lint": "eslint .", - "test": "jest", - "test:integration": "jest --config jest.integration.config.js", + "test": "NODE_OPTIONS=--experimental-vm-modules jest", + "test:integration": "NODE_OPTIONS=--experimental-vm-modules jest --config jest.integration.config.js", "db:schema": "psql -h 51.75.24.29 -U postgres -d thetiptop_dev -p 5433 -f database/schema.sql", "db:create": "node scripts/create-tables.js", "db:seed": "node database/seed.js", @@ -42,6 +42,7 @@ "zod": "^4.1.12" }, "devDependencies": { + "@eslint/js": "^9.39.0", "eslint": "^9.39.0", "jest": "^30.2.0", "nodemon": "^3.1.10",