feat(tests): integrate Vitest for testing framework and add test scripts
- Added Vitest as a dependency for improved testing capabilities. - Updated package.json with new test scripts for running tests, watching, and coverage reporting. - Configured ESLint to recognize test runner scripts and included them in the linting process. - Modified tsconfig.json to include Vitest types for better TypeScript support in tests.
This commit is contained in:
62
scripts/test-runner.js
Executable file
62
scripts/test-runner.js
Executable file
@@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* Script pour gérer PostCSS pendant les tests
|
||||
* Renomme temporairement postcss.config.mjs pour éviter les erreurs Vitest
|
||||
*/
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { spawn } = require('child_process');
|
||||
|
||||
const postcssConfigPath = path.join(process.cwd(), 'postcss.config.mjs');
|
||||
const postcssConfigBackupPath = path.join(
|
||||
process.cwd(),
|
||||
'postcss.config.mjs.testbak'
|
||||
);
|
||||
|
||||
// Fonction pour restaurer le fichier
|
||||
function restorePostCSS() {
|
||||
if (fs.existsSync(postcssConfigBackupPath)) {
|
||||
fs.renameSync(postcssConfigBackupPath, postcssConfigPath);
|
||||
console.log('✓ PostCSS config restauré');
|
||||
}
|
||||
}
|
||||
|
||||
// Renommer le fichier PostCSS avant les tests
|
||||
if (fs.existsSync(postcssConfigPath)) {
|
||||
fs.renameSync(postcssConfigPath, postcssConfigBackupPath);
|
||||
console.log('✓ PostCSS config temporairement désactivé pour les tests');
|
||||
|
||||
// Lancer Vitest avec reporter verbose pour plus de détails
|
||||
const vitest = spawn('pnpm', ['vitest', '--run', '--reporter=verbose'], {
|
||||
stdio: 'inherit',
|
||||
});
|
||||
|
||||
// Restaurer le fichier après que Vitest ait terminé
|
||||
vitest.on('close', (code) => {
|
||||
restorePostCSS();
|
||||
process.exit(code || 0);
|
||||
});
|
||||
|
||||
// Gérer les signaux d'interruption
|
||||
process.on('SIGINT', () => {
|
||||
vitest.kill('SIGINT');
|
||||
restorePostCSS();
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
process.on('SIGTERM', () => {
|
||||
vitest.kill('SIGTERM');
|
||||
restorePostCSS();
|
||||
process.exit(0);
|
||||
});
|
||||
} else {
|
||||
// Si le fichier n'existe pas, lancer Vitest directement
|
||||
const vitest = spawn('pnpm', ['vitest', '--run'], {
|
||||
stdio: 'inherit',
|
||||
});
|
||||
|
||||
vitest.on('close', (code) => {
|
||||
process.exit(code || 0);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user