UNPKG

eslint-config-styleguidejs

Version:
76 lines (60 loc) โ€ข 2.18 kB
#!/usr/bin/env node import { ESLint } from 'eslint'; import { config } from '../eslint.config.js'; import path from 'path'; import { fileURLToPath } from 'url'; import { validateRules } from './validate-rules.js'; // Get the directory name of the current module const __dirname = path.dirname(fileURLToPath(import.meta.url)); async function runTypescriptTest() { console.log('Running TypeScript configuration test...'); try { const eslint = new ESLint({ overrideConfigFile: true, overrideConfig: config }); const testFile = path.join(__dirname, 'typescript-test.ts'); const results = await eslint.lintFiles([testFile]); const formatter = await eslint.loadFormatter('stylish'); const resultText = formatter.format(results); console.log('ESLint Results:'); console.log(resultText); // Check if there are any errors const hasErrors = results.some(result => result.errorCount > 0); if (hasErrors) { console.error('โŒ TypeScript configuration test failed with errors.'); return false; } else { console.log('โœ… TypeScript configuration test passed successfully!'); return true; } } catch (error) { console.error('โŒ Error running TypeScript test:', error); return false; } } async function runAllTests() { console.log('๐Ÿงช Running all tests for eslint-config-styleguidejs...\n'); const testResults = []; // Run TypeScript test testResults.push(await runTypescriptTest()); // Run rule validation test console.log('\nRunning rule validation test...'); testResults.push(await validateRules()); // Add more tests here as needed // Print summary console.log('\n๐Ÿ“Š Test Summary:'); const passedCount = testResults.filter(result => result).length; const failedCount = testResults.filter(result => !result).length; console.log(`Passed: ${passedCount}, Failed: ${failedCount}, Total: ${testResults.length}`); // Exit with appropriate code if (failedCount > 0) { console.log('\nโŒ Some tests failed.'); process.exit(1); } else { console.log('\nโœ… All tests passed!'); process.exit(0); } } // Run all tests runAllTests();