import { expect, test } from "@playwright/test"; test.describe("WebSocket E2E Tests", () => { test("should connect to WebSocket server", async ({ page }) => { // Create a simple test page that can test Socket.IO functionality await page.setContent(`
Socket.IO Test
`); // Execute the Socket.IO connection test await page.evaluate(() => { (window as any).connectSocketIO(); }); // Wait for connection result await page.waitForFunction( () => (window as any).testResults.connected !== undefined ); const results = await page.evaluate(() => (window as any).testResults); expect(results.connected).toBe(true); }); test("should handle Socket.IO connection", async ({ page }) => { // Test Socket.IO connection using a script that loads socket.io-client await page.setContent(`
Socket.IO Test
`); // Execute the Socket.IO connection test await page.evaluate(() => { (window as any).testSocketIO(); }); // Wait for connection result await page.waitForFunction( () => (window as any).testResults.connected !== undefined, { timeout: 5000 } ); const results = await page.evaluate(() => (window as any).testResults); expect(results.connected).toBe(true); }); test("should handle room operations via Socket.IO", async ({ page }) => { await page.setContent(`
Room Operations Test
`); // Execute the room operations test await page.evaluate(() => { (window as any).testRoomOperations(); }); // Wait for events await page.waitForFunction( () => (window as any).testResults.events.length >= 2, { timeout: 5000 } ); const results = await page.evaluate(() => (window as any).testResults); expect(results.connected).toBe(true); expect(results.events).toContainEqual({ type: "joined", data: { room: "testRoom" } }); expect(results.events).toContainEqual({ type: "left", data: { room: "testRoom" } }); }); test("should receive taskUpdate events", async ({ page }) => { // Test that client can listen for taskUpdate events // Note: This test validates WebSocket event subscription, not actual event emission // which depends on service logic and may not occur in e2e test environment await page.setContent(`
Task Update Test
`); // Execute the test await page.evaluate(() => { (window as any).testTaskUpdates(); }); // Wait for test completion await page.waitForFunction( () => (window as any).testResults.completed === true ); const results = await page.evaluate(() => (window as any).testResults); expect(results.connected).toBe(true); // Event reception is optional - just validate connection and subscription capability console.log("TaskUpdate events received:", results.events.length); }); test("should receive fileUpdate events", async ({ page }) => { await page.setContent(`
File Update Test
`); // Execute the file update test await page.evaluate(() => { (window as any).testFileUpdates(); }); // Wait for connection and disconnection await page.waitForFunction( () => (window as any).testResults.connected === true, { timeout: 5000 } ); await page.waitForFunction( () => (window as any).testSocket && (window as any).testSocket.disconnected === true, { timeout: 5000 } ); const results = await page.evaluate(() => (window as any).testResults); expect(results.connected).toBe(true); // File events are optional - just validate connection capability console.log( "No fileUpdate event received - this may be expected if watcher is not active" ); }); test("should receive watcherUpdate events", async ({ page }) => { await page.setContent(`
Watcher Update Test
`); // Execute the watcher update test await page.evaluate(() => { (window as any).testWatcherUpdates(); }); // Wait for connection and disconnection await page.waitForFunction( () => (window as any).testResults.connected === true, { timeout: 5000 } ); await page.waitForFunction( () => (window as any).testSocket && (window as any).testSocket.disconnected === true, { timeout: 5000 } ); const results = await page.evaluate(() => (window as any).testResults); expect(results.connected).toBe(true); // Watcher events are optional - just validate connection capability console.log( "No watcherUpdate event received - this may be expected if watcher is not active" ); }); });