S7_snap7_Stremer_n_Recorder/testing/setup.js

176 lines
4.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
/**
* Script de configuración inicial para Playwright MCP
*/
import { execSync } from 'child_process';
import fs from 'fs/promises';
import path from 'path';
console.log('🚀 Configurando Playwright MCP para PLC Streamer...');
async function setup() {
try {
// 1. Verificar instalación de Playwright
console.log('📦 Verificando instalación de Playwright...');
try {
execSync('npx playwright --version', { stdio: 'pipe' });
console.log('✅ Playwright instalado');
} catch (error) {
console.log('⚠️ Instalando Playwright...');
execSync('npm install', { stdio: 'inherit' });
execSync('npx playwright install', { stdio: 'inherit' });
}
// 2. Crear directorios necesarios
console.log('📁 Creando directorios...');
const dirs = ['screenshots', 'videos', 'test-results', 'playwright-report'];
for (const dir of dirs) {
try {
await fs.mkdir(dir, { recursive: true });
console.log(`✅ Directorio creado: ${dir}`);
} catch (error) {
console.log(` Directorio ya existe: ${dir}`);
}
}
// 3. Verificar que los servidores estén configurados
console.log('🔧 Verificando configuración de servidores...');
// Check frontend
const frontendPath = '../frontend/package.json';
try {
await fs.access(frontendPath);
console.log('✅ Frontend encontrado');
} catch (error) {
console.log('⚠️ Frontend no encontrado en ruta esperada');
}
// Check backend
const backendPath = '../main.py';
try {
await fs.access(backendPath);
console.log('✅ Backend encontrado');
} catch (error) {
console.log('⚠️ Backend no encontrado en ruta esperada');
}
// 4. Crear archivo de configuración de entorno
console.log('⚙️ Creando configuración de entorno...');
const envConfig = {
FRONTEND_URL: 'http://localhost:5173',
BACKEND_URL: 'http://localhost:5000',
PLAYWRIGHT_HEADLESS: 'false',
PLAYWRIGHT_SLOWMO: '100',
SCREENSHOT_PATH: './screenshots',
VIDEO_PATH: './videos'
};
await fs.writeFile('.env',
Object.entries(envConfig)
.map(([key, value]) => `${key}=${value}`)
.join('\n')
);
console.log('✅ Archivo .env creado');
// 5. Crear script de inicio rápido
console.log('🎯 Creando script de inicio rápido...');
const quickStart = `#!/bin/bash
# Script de inicio rápido para testing con Playwright
echo "🚀 Iniciando PLC Streamer Testing Suite"
# Verificar que los servidores estén corriendo
echo "🔍 Verificando servidores..."
# Check frontend
if curl -f http://localhost:5173 >/dev/null 2>&1; then
echo "✅ Frontend (5173) running"
else
echo "❌ Frontend no está corriendo en puerto 5173"
echo "💡 Ejecuta: cd ../frontend && npm run dev"
fi
# Check backend
if curl -f http://localhost:5000/api/status >/dev/null 2>&1; then
echo "✅ Backend (5000) running"
else
echo "❌ Backend no está corriendo en puerto 5000"
echo "💡 Ejecuta: cd .. && python main.py"
fi
echo "🎬 Iniciando tests..."
npm run test:headed
`;
await fs.writeFile('quick-start.sh', quickStart);
console.log('✅ Script quick-start.sh creado');
// 6. Crear archivo gitignore para testing
console.log('📝 Configurando .gitignore...');
const gitignore = `# Playwright
test-results/
playwright-report/
playwright/.cache/
# Screenshots y videos
screenshots/*.png
videos/*.webm
# Reportes y logs
*.json
*.log
# Node modules
node_modules/
# Environment
.env.local
`;
await fs.writeFile('.gitignore', gitignore);
console.log('✅ .gitignore configurado');
// 7. Mensaje final
console.log(`
🎉 ¡Configuración completada!
📋 Próximos pasos:
1. Asegúrate de que los servidores estén corriendo:
Frontend: cd ../frontend && npm run dev
Backend: cd .. && python main.py
2. Ejecutar tests básicos:
npm test
3. Ejecutar ejemplo interactivo:
npm run example
4. Generar código de test:
npm run codegen:app
5. Monitoreo continuo:
npm run monitor
📚 Ver README.md para más información y ejemplos.
🔧 Archivos creados:
- .env (configuración)
- .gitignore (exclusiones)
- quick-start.sh (inicio rápido)
Happy testing! 🧪
`);
} catch (error) {
console.error('❌ Error durante la configuración:', error);
process.exit(1);
}
}
setup();