diff --git a/jest.config.js b/jest.config.js index 955d567..9f34ee4 100644 --- a/jest.config.js +++ b/jest.config.js @@ -14,4 +14,11 @@ module.exports = { '^@app/(.*)$': '/src/app/$1', '^@env/(.*)$': '/src/environments/$1', }, + // Ajouter cette section pour gérer les warnings Node.js + testEnvironmentOptions: { + customExportConditions: ['node', 'node-addons'], + }, + + // Supprimer les warnings de dépréciation + setupFiles: ['/suppress-deprecation-warnings.js'], }; diff --git a/src/setup-jest.ts b/src/setup-jest.ts index 6e92006..0f356ca 100644 --- a/src/setup-jest.ts +++ b/src/setup-jest.ts @@ -32,23 +32,47 @@ global.fetch = jest.fn(() => }) ) as jest.Mock; -// 🟡 Ignore le warning pdfjs-dist +// 🟡 Ignore les warnings pdfjs-dist const originalWarn = console.warn; console.warn = (...args) => { - if ( - typeof args[0] === 'string' && - args[0].includes('ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING_FLAG') - ) { + const message = typeof args[0] === 'string' ? args[0] : ''; + + // Liste des warnings à ignorer + const ignoredWarnings = [ + 'ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING_FLAG', + 'loadPackages', + 'pdfjs-dist', + ]; + + if (ignoredWarnings.some((warning) => message.includes(warning))) { return; } + originalWarn(...args); }; -// 🔴 Ignore le log angularx-qrcode après les tests -const originalError = console.error; -console.error = (...args) => { - if (typeof args[0] === 'string' && args[0].includes('[angularx-qrcode]')) { +// 🟡 Ignore les logs angularx-qrcode +const originalLog = console.log; +console.log = (...args) => { + const message = typeof args[0] === 'string' ? args[0] : ''; + + const ignoredLogs = ['Warning: loadPackages', 'ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING_FLAG']; + + if (ignoredLogs.some((log) => message.includes(log))) { return; } + + originalLog(...args); +}; + +// 🔴 Ignore les errors angularx-qrcode +const originalError = console.error; +console.error = (...args) => { + const message = typeof args[0] === 'string' ? args[0] : ''; + + if (message.includes('[angularx-qrcode]')) { + return; + } + originalError(...args); }; diff --git a/suppress-deprecation-warnings.js b/suppress-deprecation-warnings.js new file mode 100644 index 0000000..66e6da1 --- /dev/null +++ b/suppress-deprecation-warnings.js @@ -0,0 +1,9 @@ +// suppress-deprecation-warnings.js +const originalEmitWarning = process.emitWarning; + +process.emitWarning = (warning, type, code, ...args) => { + if (code === 'DEP0040') { + return; + } + return originalEmitWarning.call(process, warning, type, code, ...args); +};