Files
2025-12-28 08:13:13 +08:00

83 lines
3.4 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const { removeConsoleWithOllama, checkOllamaHealth } = require('./ollama-console-remover.js');
// 测试用的压缩JS文件包含console语句
const testJsCode = `
function testFunction(){console.log("debug info");const data={name:"test",value:123};console.error("error occurred");return data;}console.warn("warning message");class TestClass{constructor(){console.debug("constructor called");this.id=Math.random();}getId(){console.info("getting id");return this.id;}}module.exports={TestClass,testFunction};
`;
async function runTest() {
console.log('🧪 Testing Ollama console remover...');
console.log('');
// 1. 检查Ollama服务
console.log('1⃣ Checking Ollama service...');
const isAvailable = await checkOllamaHealth();
console.log(` Status: ${isAvailable ? '✅ Available' : '❌ Not available'}`);
if (!isAvailable) {
console.log(' Please make sure Ollama is running with:');
console.log(' - Ollama installed: https://ollama.com/');
console.log(' - Ollama running: ollama serve');
console.log(' - Model pulled: ollama pull deepseek-coder:6.7b');
console.log('');
console.log(' Using local fallback method for test...');
// 使用本地备用方法
const { removeConsoleFallback } = require('./ollama-console-remover.js');
const cleanedCode = removeConsoleFallback(testJsCode);
console.log('');
console.log('📝 Original code:');
console.log(testJsCode);
console.log('');
console.log('🧹 Cleaned code (local method):');
console.log(cleanedCode);
console.log('');
console.log(`📊 Size reduction: ${testJsCode.length - cleanedCode.length} characters`);
return;
}
// 2. 测试Ollama处理
console.log('2⃣ Testing with Ollama...');
try {
const cleanedCode = await removeConsoleWithOllama(testJsCode);
console.log('📝 Original code:');
console.log(testJsCode);
console.log('');
console.log('🧹 Cleaned code (Ollama):');
console.log(cleanedCode);
console.log('');
console.log(`📊 Size reduction: ${testJsCode.length - cleanedCode.length} characters`);
console.log('');
console.log('✅ Test completed successfully!');
// 保存测试结果
const testResults = {
original: testJsCode,
cleaned: cleanedCode,
reduction: testJsCode.length - cleanedCode.length,
timestamp: new Date().toISOString()
};
fs.writeFileSync('test-results.json', JSON.stringify(testResults, null, 2));
console.log('💾 Test results saved to test-results.json');
} catch (error) {
console.error('❌ Error testing Ollama:', error.message);
console.log('');
console.log('🔧 Troubleshooting tips:');
console.log('1. Make sure Ollama is running: ollama serve');
console.log('2. Make sure the model is pulled: ollama pull deepseek-coder:6.7b');
console.log('3. Check if Ollama is accessible at http://localhost:11434');
console.log('4. Try running: curl http://localhost:11434/api/tags');
}
}
// 运行测试
runTest().catch(console.error);