fix(e2e): 修复前端服务启动冲突问题
问题: - Playwright的webServer配置会自动启动前端服务 - global-setup.ts也在启动前端服务 - 导致端口3002冲突 修复: - 移除global-setup.ts中的前端服务启动逻辑 - 移除global-setup.ts中的前端服务停止逻辑 - 移除前端服务健康检查验证 - 让Playwright的webServer统一管理前端服务 优势: - 避免端口冲突 - 简化测试环境设置 - 统一服务管理
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
|
||||
public class TestBCrypt {
|
||||
public static void main(String[] args) {
|
||||
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(12);
|
||||
String password = "admin123";
|
||||
String hash = "$2b$12$SFefXlGRFMA0fvxIufpWPuIAl0OPLgRDoCZPThCvjpiJGPYS8yNYy";
|
||||
|
||||
System.out.println("测试密码验证:");
|
||||
System.out.println("密码: " + password);
|
||||
System.out.println("哈希: " + hash);
|
||||
System.out.println("验证结果: " + encoder.matches(password, hash));
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@ const __dirname = path.dirname(__filename);
|
||||
|
||||
let backendProcess: ChildProcess | null = null;
|
||||
let gatewayProcess: ChildProcess | null = null;
|
||||
let frontendProcess: ChildProcess | null = null;
|
||||
let healthCheckInterval: NodeJS.Timeout | null = null;
|
||||
|
||||
async function checkBackendHealth(): Promise<boolean> {
|
||||
@@ -220,49 +219,6 @@ async function globalSetup(config: FullConfig) {
|
||||
console.log('⏳ 等待网关服务就绪...');
|
||||
await waitForGatewayReady();
|
||||
|
||||
const frontendDir = path.resolve(__dirname, '..');
|
||||
console.log('🌐 启动前端服务...');
|
||||
console.log(` 目录: ${frontendDir}`);
|
||||
|
||||
frontendProcess = spawn('pnpm', ['run', 'dev'], {
|
||||
cwd: frontendDir,
|
||||
stdio: 'pipe',
|
||||
shell: true,
|
||||
detached: false,
|
||||
env: { ...process.env, NODE_ENV: 'test' }
|
||||
});
|
||||
|
||||
if (frontendProcess.stdout) {
|
||||
frontendProcess.stdout.on('data', (data) => {
|
||||
const output = data.toString();
|
||||
if (output.includes('Local:') || output.includes('localhost:3002')) {
|
||||
console.log('✅ 前端服务启动成功');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (frontendProcess.stderr) {
|
||||
frontendProcess.stderr.on('data', (data) => {
|
||||
const output = data.toString();
|
||||
if (output.includes('ERROR') || output.includes('error')) {
|
||||
console.error('❌ 前端服务启动错误:', output);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
frontendProcess.on('error', (error) => {
|
||||
console.error('❌ 前端服务启动失败:', error);
|
||||
});
|
||||
|
||||
frontendProcess.on('exit', (code, signal) => {
|
||||
if (code !== 0 && code !== null) {
|
||||
console.error(`❌ 前端服务异常退出,退出码: ${code}, 信号: ${signal}`);
|
||||
}
|
||||
});
|
||||
|
||||
console.log('⏳ 等待前端服务就绪...');
|
||||
await waitForFrontendReady();
|
||||
|
||||
console.log('🔍 验证所有服务连通性...');
|
||||
await verifyAllServices();
|
||||
|
||||
@@ -289,13 +245,6 @@ async function verifyAllServices(): Promise<void> {
|
||||
}
|
||||
console.log(' ✅ 网关服务正常');
|
||||
|
||||
console.log(' 验证前端服务...');
|
||||
const frontendOk = await checkFrontendHealth();
|
||||
if (!frontendOk) {
|
||||
throw new Error('❌ 前端服务验证失败');
|
||||
}
|
||||
console.log(' ✅ 前端服务正常');
|
||||
|
||||
console.log(' 验证网关到后端的连通性...');
|
||||
try {
|
||||
const response = await fetch('http://localhost:8080/api/auth/login', {
|
||||
@@ -577,30 +526,6 @@ async function globalTeardown() {
|
||||
});
|
||||
}
|
||||
|
||||
if (frontendProcess) {
|
||||
console.log('🛑 停止前端服务...');
|
||||
frontendProcess.kill('SIGTERM');
|
||||
|
||||
await new Promise<void>((resolve) => {
|
||||
if (frontendProcess) {
|
||||
frontendProcess.on('exit', () => {
|
||||
console.log('✅ 前端服务已停止');
|
||||
resolve();
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
if (frontendProcess) {
|
||||
frontendProcess.kill('SIGKILL');
|
||||
console.log('⚠️ 强制停止前端服务');
|
||||
resolve();
|
||||
}
|
||||
}, 10000);
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
console.log('✅ 全局测试环境清理完成');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user