@@ -6,12 +6,12 @@ import packageJson from '../src/shared/packageJson';
66import * as incremental from '../src/worker/handleIncrementalRenderRequest' ;
77import {
88 createVmBundle ,
9- createSecondaryVmBundle ,
109 createIncrementalVmBundle ,
1110 createIncrementalSecondaryVmBundle ,
1211 BUNDLE_TIMESTAMP ,
1312 SECONDARY_BUNDLE_TIMESTAMP ,
1413 waitFor ,
14+ resetForTest ,
1515} from './helper' ;
1616import type { ResponseResult } from '../src/shared/utils' ;
1717
@@ -238,6 +238,10 @@ describe('incremental render NDJSON endpoint', () => {
238238 return { promise, receivedChunks } ;
239239 } ;
240240
241+ beforeEach ( async ( ) => {
242+ await resetForTest ( TEST_NAME ) ;
243+ } ) ;
244+
241245 afterEach ( ( ) => {
242246 jest . restoreAllMocks ( ) ;
243247 } ) ;
@@ -711,60 +715,6 @@ describe('incremental render NDJSON endpoint', () => {
711715 expect ( response . data ) . toBe ( 'first update' ) ; // Should resolve with the first setAsyncValue call
712716 } ) ;
713717
714- test ( 'incremental updates work with multiple bundles using runOnOtherBundle' , async ( ) => {
715- await createIncrementalVmBundle ( TEST_NAME ) ;
716- await createIncrementalSecondaryVmBundle ( TEST_NAME ) ;
717- const SERVER_BUNDLE_TIMESTAMP = String ( BUNDLE_TIMESTAMP ) ;
718- const SECONDARY_BUNDLE_TIMESTAMP_STR = String ( SECONDARY_BUNDLE_TIMESTAMP ) ;
719-
720- // Create the HTTP request
721- const req = createHttpRequest ( SERVER_BUNDLE_TIMESTAMP ) ;
722-
723- // Set up response handling
724- const responsePromise = setupResponseHandler ( req , true ) ;
725-
726- // Send the initial object that gets values from both bundles
727- const initialObject = {
728- ...createInitialObject ( SERVER_BUNDLE_TIMESTAMP ) ,
729- renderingRequest : `
730- runOnOtherBundle(${ SECONDARY_BUNDLE_TIMESTAMP } , 'ReactOnRails.getAsyncValue()').then((secondaryValue) => ({
731- mainBundleValue: ReactOnRails.getAsyncValue(),
732- secondaryBundleValue: JSON.parse(secondaryValue),
733- }));
734- ` ,
735- dependencyBundleTimestamps : [ SECONDARY_BUNDLE_TIMESTAMP_STR ] ,
736- } ;
737- req . write ( `${ JSON . stringify ( initialObject ) } \n` ) ;
738-
739- // Send update chunks to both bundles
740- const updateMainBundle = {
741- bundleTimestamp : SERVER_BUNDLE_TIMESTAMP ,
742- updateChunk : 'ReactOnRails.setAsyncValue("main bundle updated")' ,
743- } ;
744- req . write ( `${ JSON . stringify ( updateMainBundle ) } \n` ) ;
745-
746- const updateSecondaryBundle = {
747- bundleTimestamp : SECONDARY_BUNDLE_TIMESTAMP_STR ,
748- updateChunk : 'ReactOnRails.setAsyncValue("secondary bundle updated")' ,
749- } ;
750- req . write ( `${ JSON . stringify ( updateSecondaryBundle ) } \n` ) ;
751-
752- // End the request
753- req . end ( ) ;
754-
755- // Wait for the response
756- const response = await responsePromise ;
757-
758- // Verify the response
759- expect ( response . statusCode ) . toBe ( 200 ) ;
760- const responseData = JSON . parse ( response . data || '{}' ) as {
761- mainBundleValue : unknown ;
762- secondaryBundleValue : unknown ;
763- } ;
764- expect ( responseData . mainBundleValue ) . toBe ( 'main bundle updated' ) ;
765- expect ( responseData . secondaryBundleValue ) . toBe ( 'secondary bundle updated' ) ;
766- } ) ;
767-
768718 test ( 'streaming functionality with incremental updates' , async ( ) => {
769719 await createIncrementalVmBundle ( TEST_NAME ) ;
770720 const SERVER_BUNDLE_TIMESTAMP = String ( BUNDLE_TIMESTAMP ) ;
@@ -804,99 +754,12 @@ describe('incremental render NDJSON endpoint', () => {
804754 req . write ( `${ JSON . stringify ( updateChunk ) } \n` ) ;
805755 }
806756
807- // No need to get stream values again since we're already streaming
808-
809- // End the request
810- req . end ( ) ;
811-
812- // Wait for the response
813- const response = await responsePromise ;
814-
815- // Verify the response
816- expect ( response . statusCode ) . toBe ( 200 ) ;
817- // Since we're returning a stream, the response should indicate streaming
818- expect ( streamedData . length ) . toBeGreaterThan ( 0 ) ;
819- } ) ;
820-
821- test ( 'error handling in incremental render updates' , async ( ) => {
822- await createIncrementalVmBundle ( TEST_NAME ) ;
823- const SERVER_BUNDLE_TIMESTAMP = String ( BUNDLE_TIMESTAMP ) ;
824-
825- // Create the HTTP request
826- const req = createHttpRequest ( SERVER_BUNDLE_TIMESTAMP ) ;
827-
828- // Set up response handling
829- const responsePromise = setupResponseHandler ( req , true ) ;
830-
831- // Send the initial object
832- const initialObject = {
833- ...createInitialObject ( SERVER_BUNDLE_TIMESTAMP ) ,
834- renderingRequest : 'ReactOnRails.getAsyncValue()' ,
835- } ;
836- req . write ( `${ JSON . stringify ( initialObject ) } \n` ) ;
837-
838- // Send a malformed update chunk (missing bundleTimestamp)
839- const malformedChunk = {
840- updateChunk : 'ReactOnRails.setAsyncValue("should not work")' ,
841- } ;
842- req . write ( `${ JSON . stringify ( malformedChunk ) } \n` ) ;
843-
844- // Send a valid update chunk after the malformed one
845- const validChunk = {
846- bundleTimestamp : SERVER_BUNDLE_TIMESTAMP ,
847- updateChunk : 'ReactOnRails.setAsyncValue("valid update")' ,
848- } ;
849- req . write ( `${ JSON . stringify ( validChunk ) } \n` ) ;
850-
851- // Send a chunk with invalid JavaScript
852- const invalidJSChunk = {
853- bundleTimestamp : SERVER_BUNDLE_TIMESTAMP ,
854- updateChunk : 'this is not valid javascript syntax !!!' ,
855- } ;
856- req . write ( `${ JSON . stringify ( invalidJSChunk ) } \n` ) ;
857-
858- // End the request
859- req . end ( ) ;
860-
861- // Wait for the response
862- const response = await responsePromise ;
863-
864- // Verify the response - should still work despite errors
865- expect ( response . statusCode ) . toBe ( 200 ) ;
866- expect ( response . data ) . toBe ( '"valid update"' ) ; // Should resolve with the valid update
867- } ) ;
868-
869- test ( 'update chunks with non-existent bundle timestamp' , async ( ) => {
870- await createIncrementalVmBundle ( TEST_NAME ) ;
871- const SERVER_BUNDLE_TIMESTAMP = String ( BUNDLE_TIMESTAMP ) ;
872- const NON_EXISTENT_TIMESTAMP = '9999999999999' ;
873-
874- // Create the HTTP request
875- const req = createHttpRequest ( SERVER_BUNDLE_TIMESTAMP ) ;
876-
877- // Set up response handling
878- const responsePromise = setupResponseHandler ( req , true ) ;
879-
880- // Send the initial object
881- const initialObject = {
882- ...createInitialObject ( SERVER_BUNDLE_TIMESTAMP ) ,
883- renderingRequest : 'ReactOnRails.getAsyncValue()' ,
884- } ;
885- req . write ( `${ JSON . stringify ( initialObject ) } \n` ) ;
886-
887- // Send update chunk with non-existent bundle timestamp
888- const updateChunk = {
889- bundleTimestamp : NON_EXISTENT_TIMESTAMP ,
890- updateChunk : 'ReactOnRails.setAsyncValue("should not work")' ,
891- } ;
892- req . write ( `${ JSON . stringify ( updateChunk ) } \n` ) ;
893-
894- // Send a valid update chunk
895- const validChunk = {
757+ // End the stream to signal completion
758+ const endStreamChunk = {
896759 bundleTimestamp : SERVER_BUNDLE_TIMESTAMP ,
897- updateChunk : 'ReactOnRails.setAsyncValue("valid update" )' ,
760+ updateChunk : 'ReactOnRails.endStream( )' ,
898761 } ;
899- req . write ( `${ JSON . stringify ( validChunk ) } \n` ) ;
762+ req . write ( `${ JSON . stringify ( endStreamChunk ) } \n` ) ;
900763
901764 // End the request
902765 req . end ( ) ;
@@ -906,7 +769,8 @@ describe('incremental render NDJSON endpoint', () => {
906769
907770 // Verify the response
908771 expect ( response . statusCode ) . toBe ( 200 ) ;
909- expect ( response . data ) . toBe ( '"valid update"' ) ; // Should resolve with the valid update
772+ // Since we're returning a stream, the response should indicate streaming
773+ expect ( streamedData . length ) . toBeGreaterThan ( 0 ) ;
910774 } ) ;
911775
912776 test ( 'complex multi-bundle streaming scenario' , async ( ) => {
0 commit comments