UNPKG

@nestjsvn/swagger-sse

Version:

OpenAPI documentation and interactive Swagger UI for NestJS Server-Sent Events endpoints

98 lines (97 loc) 4.84 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const setup_1 = require("./setup"); const test_controllers_1 = require("./test-controllers"); describe('SSE Plugin Flow Diagnostic', () => { let context; beforeAll(async () => { context = await setup_1.E2ETestSetup.createContext('sse-plugin-flow-diagnostic', { controllers: [test_controllers_1.TestEventsController], }); }); afterAll(async () => { await setup_1.E2ETestSetup.cleanup('sse-plugin-flow-diagnostic'); }); it('should trace the complete SSE plugin execution flow', async () => { // Enable console logging to see plugin messages context.page.on('console', (msg) => { if (msg.text().includes('SSE Plugin')) { console.log('BROWSER:', msg.text()); } }); await context.page.goto(`${context.baseUrl}/api-docs`); await context.page.waitForSelector('.swagger-ui', { timeout: 10000 }); console.log('=== Step 1: Check initial plugin state ==='); const initialState = await context.page.evaluate(() => { return { hasSwaggerUI: typeof window.ui !== 'undefined', sseConnectionsExists: typeof window.sseConnections !== 'undefined', sseConnectionsSize: window.sseConnections ? window.sseConnections.size : 'N/A', }; }); console.log('Initial state:', initialState); console.log('=== Step 2: Expand endpoint ==='); await context.page.click('.opblock .opblock-summary'); await context.page.waitForTimeout(1000); console.log('=== Step 3: Click Try it out ==='); await context.page.waitForSelector('.btn.try-out__btn', { timeout: 5000 }); await context.page.click('.btn.try-out__btn'); await context.page.waitForTimeout(1000); console.log('=== Step 4: Check execute button state ==='); const executeButtonState = await context.page.evaluate(() => { const executeBtn = document.querySelector('.execute-wrapper .btn.execute'); return { exists: !!executeBtn, text: executeBtn?.textContent?.trim(), disabled: executeBtn?.disabled, className: executeBtn?.className, }; }); console.log('Execute button state:', executeButtonState); console.log('=== Step 5: Check path detection ==='); const pathInfo = await context.page.evaluate(() => { const pathElement = document.querySelector('.opblock-summary-path'); const path = pathElement?.textContent?.trim(); // Simulate the isSseEndpoint check (since it's not globally available) const isSSE = path && (path.includes('/events/') || path.includes('/dashboard/') || path.includes('/test-events/') || path.includes('/mobile-test/')); return { pathElement: !!pathElement, path, isSSE, }; }); console.log('Path info:', pathInfo); console.log('=== Step 6: Click Execute and monitor ==='); // Set up a promise to wait for SSE interface creation const sseInterfacePromise = context.page.waitForSelector('[data-testid="sse-connect-btn"]', { timeout: 10000 }).catch(() => null); // Click execute await context.page.click('.execute-wrapper .btn.execute'); console.log('Execute button clicked'); // Wait for either SSE interface or timeout const sseInterface = await sseInterfacePromise; console.log('=== Step 7: Check final state ==='); const finalState = await context.page.evaluate(() => { return { hasSSEInterface: !!document.querySelector('.sse-interface'), hasConnectBtn: !!document.querySelector('[data-testid="sse-connect-btn"]'), hasStatus: !!document.querySelector('[data-testid="sse-status"]'), hasEventLog: !!document.querySelector('[data-testid="sse-event-log"]'), responsesWrapper: !!document.querySelector('.responses-wrapper'), responsesWrapperChildren: Array.from(document.querySelectorAll('.responses-wrapper > *')).map(el => ({ tagName: el.tagName, className: el.className, hasSSEInterface: el.classList.contains('sse-interface'), })), }; }); console.log('Final state:', JSON.stringify(finalState, null, 2)); console.log('SSE Interface found:', !!sseInterface); // This test always passes - it's just for diagnostics expect(true).toBe(true); }); });