Skip to content

Commit ae833ad

Browse files
committed
Update Pro tests to expect wrapped console scripts
1 parent d55a50d commit ae833ad

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

react_on_rails_pro/spec/dummy/spec/helpers/react_on_rails_pro_helper_spec.rb

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -295,13 +295,13 @@ def response; end
295295
let(:chunks) do
296296
[
297297
{ html: "<div>Chunk 1: Stream React Server Components</div>",
298-
consoleReplayScript: "<script>console.log.apply(console, " \
299-
"['Chunk 1: Console Message'])</script>" },
298+
consoleReplayScript: "console.log.apply(console, " \
299+
"['Chunk 1: Console Message'])" },
300300
{ html: "<div>Chunk 2: More content</div>",
301-
consoleReplayScript: "<script>console.log.apply(console, " \
301+
consoleReplayScript: "console.log.apply(console, " \
302302
"['Chunk 2: Console Message']);\n" \
303303
"console.error.apply(console, " \
304-
"['Chunk 2: Console Error']);</script>" },
304+
"['Chunk 2: Console Error']);" },
305305
{ html: "<div>Chunk 3: Final content</div>", consoleReplayScript: "" }
306306
]
307307
end
@@ -373,7 +373,14 @@ def mock_request_and_response(mock_chunks = chunks, count: 1)
373373
mock_request_and_response
374374
initial_result = stream_react_component(component_name, props: props, **component_options)
375375
expect(initial_result).to include(react_component_div_with_initial_chunk)
376-
expect(initial_result).to include(chunks.first[:consoleReplayScript])
376+
# consoleReplayScript is now wrapped in a script tag with id="consoleReplayLog"
377+
wrapped_first_console_script = if chunks.first[:consoleReplayScript].present?
378+
"<script id=\"consoleReplayLog\">" \
379+
"#{chunks.first[:consoleReplayScript]}</script>"
380+
else
381+
""
382+
end
383+
expect(initial_result).to include(wrapped_first_console_script) if wrapped_first_console_script.present?
377384
expect(initial_result).not_to include("More content", "Final content")
378385
expect(chunks_read.count).to eq(1)
379386
end
@@ -386,9 +393,16 @@ def mock_request_and_response(mock_chunks = chunks, count: 1)
386393
expect(fiber).to be_alive
387394

388395
second_result = fiber.resume
389-
# regex that matches the html and consoleReplayScript and allows for any amount of whitespace between them
396+
# regex that matches the html and wrapped consoleReplayScript
397+
# Note: consoleReplayScript is now wrapped in a script tag with id="consoleReplayLog"
398+
wrapped_console_script = if chunks[1][:consoleReplayScript].present?
399+
"<script id=\"consoleReplayLog\">" \
400+
"#{chunks[1][:consoleReplayScript]}</script>"
401+
else
402+
""
403+
end
390404
expect(second_result).to match(
391-
/#{Regexp.escape(chunks[1][:html])}\s+#{Regexp.escape(chunks[1][:consoleReplayScript])}/
405+
/#{Regexp.escape(chunks[1][:html])}\s+#{Regexp.escape(wrapped_console_script)}/
392406
)
393407
expect(second_result).not_to include("Stream React Server Components", "Final content")
394408
expect(chunks_read.count).to eq(2)

0 commit comments

Comments
 (0)