@@ -727,9 +727,22 @@ describe('Zod v4', () => {
727727
728728 const reader = response . body ?. getReader ( ) ;
729729
730- // The responses may come in any order or together in one chunk
731- const { value } = await reader ! . read ( ) ;
732- const text = new TextDecoder ( ) . decode ( value ) ;
730+ // Read from the SSE stream until we have both responses or timeout
731+ // On Node v26.7.0+, SSE events may arrive in separate chunks, so we need to
732+ // keep reading until we have all expected responses or timeout
733+ let text = '' ;
734+ const startTime = Date . now ( ) ;
735+ const timeout = 5000 ; // 5 second timeout
736+
737+ while ( Date . now ( ) - startTime < timeout ) {
738+ const { value, done } = await reader ! . read ( ) ;
739+ if ( done ) break ;
740+ text += new TextDecoder ( ) . decode ( value ) ;
741+ // Check if we have both responses
742+ if ( text . includes ( '"id":"req-1"' ) && text . includes ( '"id":"req-2"' ) ) {
743+ break ;
744+ }
745+ }
733746
734747 // Check that both responses were sent on the same stream
735748 expect ( text ) . toContain ( '"id":"req-1"' ) ;
@@ -1481,9 +1494,21 @@ describe('Zod v4', () => {
14811494 await mcpServer . server . sendLoggingMessage ( { level : 'info' , data : 'First notification from MCP server' } ) ;
14821495
14831496 // Read the notification from the SSE stream
1497+ // On Node v26.7.0+, SSE events may arrive in separate chunks, so we need to
1498+ // keep reading until we get the expected notification
14841499 const reader = sseResponse . body ?. getReader ( ) ;
1485- const { value } = await reader ! . read ( ) ;
1486- const text = new TextDecoder ( ) . decode ( value ) ;
1500+ let text = '' ;
1501+ const startTime = Date . now ( ) ;
1502+ const timeout = 5000 ;
1503+
1504+ while ( Date . now ( ) - startTime < timeout ) {
1505+ const { value, done } = await reader ! . read ( ) ;
1506+ if ( done ) break ;
1507+ text += new TextDecoder ( ) . decode ( value ) ;
1508+ if ( text . includes ( 'First notification from MCP server' ) ) {
1509+ break ;
1510+ }
1511+ }
14871512
14881513 // Verify the notification was sent with an event ID
14891514 expect ( text ) . toContain ( 'id: ' ) ;
@@ -1515,8 +1540,17 @@ describe('Zod v4', () => {
15151540
15161541 // Read the replayed notification
15171542 const reconnectReader = reconnectResponse . body ?. getReader ( ) ;
1518- const reconnectData = await reconnectReader ! . read ( ) ;
1519- const reconnectText = new TextDecoder ( ) . decode ( reconnectData . value ) ;
1543+ let reconnectText = '' ;
1544+ const reconnectStartTime = Date . now ( ) ;
1545+
1546+ while ( Date . now ( ) - reconnectStartTime < 5000 ) {
1547+ const { value, done } = await reconnectReader ! . read ( ) ;
1548+ if ( done ) break ;
1549+ reconnectText += new TextDecoder ( ) . decode ( value ) ;
1550+ if ( reconnectText . includes ( 'Second notification from MCP server' ) ) {
1551+ break ;
1552+ }
1553+ }
15201554
15211555 // Verify we received the second notification that was sent after our stored eventId
15221556 expect ( reconnectText ) . toContain ( 'Second notification from MCP server' ) ;
0 commit comments