Skip to content

Commit fb066be

Browse files
committed
fix: Add formatSSEEvent method for cross-engine test compatibility
The SSE format test was failing on Lucee because savecontent doesn't capture writeOutput from nested method calls. Added formatSSEEvent() method that returns the formatted string directly, which streamEvent() now uses internally. Tests now call formatSSEEvent() directly instead of relying on savecontent to capture writeOutput.
1 parent b7c8bfb commit fb066be

2 files changed

Lines changed: 18 additions & 21 deletions

File tree

system/util/StreamingService.cfc

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,19 @@ component accessors="true" {
3535
return this;
3636
}
3737

38+
/**
39+
* Format an SSE event as a string
40+
* Returns the properly formatted SSE event string without writing to output
41+
*
42+
* @eventType The type of event (e.g., bundleStart, specEnd)
43+
* @data The data payload to serialize as JSON
44+
*
45+
* @return string The formatted SSE event string
46+
*/
47+
string function formatSSEEvent( required string eventType, required any data ){
48+
return "event: #arguments.eventType##chr( 10 )#data: #serializeJSON( arguments.data )##chr( 10 )##chr( 10 )#";
49+
}
50+
3851
/**
3952
* Stream an SSE event to the client
4053
* Errors are caught and logged to prevent client disconnects from interrupting test execution.
@@ -44,8 +57,7 @@ component accessors="true" {
4457
*/
4558
function streamEvent( required string eventType, required any data ){
4659
try {
47-
writeOutput( "event: #arguments.eventType##chr( 10 )#" );
48-
writeOutput( "data: #serializeJSON( arguments.data )##chr( 10 )##chr( 10 )#" );
60+
writeOutput( formatSSEEvent( arguments.eventType, arguments.data ) );
4961
// Only flush if enabled (disabled during unit testing to prevent response commit)
5062
if ( isNull( variables.flushEnabled ) || variables.flushEnabled ) {
5163
cfflush( );

tests/specs/streaming/StreamingServiceTest.cfc

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,10 @@ component extends="testbox.system.BaseSpec" {
5151
} );
5252

5353
describe( "SSE event format", function(){
54-
it( "streamEvent produces correct SSE format string", function(){
55-
// Disable flushing to prevent response commit during testing
56-
variables.streamingService.setFlushEnabled( false );
57-
58-
// Capture the actual output from streamEvent using savecontent
54+
it( "formatSSEEvent produces correct SSE format string", function(){
5955
var eventType = "testEvent";
6056
var data = { "key" : "value" };
61-
var output = "";
62-
63-
savecontent variable="output" {
64-
variables.streamingService.streamEvent( eventType, data );
65-
}
57+
var output = variables.streamingService.formatSSEEvent( eventType, data );
6658

6759
// Verify SSE format: event: <type>\ndata: <json>\n\n
6860
expect( output ).toInclude( "event: testEvent" );
@@ -71,21 +63,14 @@ component extends="testbox.system.BaseSpec" {
7163
expect( right( output, 2 ) ).toBe( chr( 10 ) & chr( 10 ) );
7264
} );
7365

74-
it( "streamEvent serializes complex data to JSON correctly", function(){
75-
// Disable flushing to prevent response commit during testing
76-
variables.streamingService.setFlushEnabled( false );
77-
66+
it( "formatSSEEvent serializes complex data to JSON correctly", function(){
7867
var testData = {
7968
"id" : "test-123",
8069
"name" : "Test Spec",
8170
"nested" : { "foo" : "bar" },
8271
"arrayVal" : [ 1, 2, 3 ]
8372
};
84-
var output = "";
85-
86-
savecontent variable="output" {
87-
variables.streamingService.streamEvent( "testEvent", testData );
88-
}
73+
var output = variables.streamingService.formatSSEEvent( "testEvent", testData );
8974

9075
expect( output ).toInclude( """id""" );
9176
expect( output ).toInclude( """test-123""" );

0 commit comments

Comments
 (0)