Skip to content

Commit

Permalink
Add test for promise value
Browse files Browse the repository at this point in the history
  • Loading branch information
davesnx committed Dec 16, 2024
1 parent 6457a13 commit add4a3c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 26 deletions.
34 changes: 34 additions & 0 deletions packages/reactDom/test/test_RSC_html.ml
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,45 @@ let with_sleepy_promise () =
'>window.srr_stream.push()</script>"
[ "<div><section><article>Deep Server Content</article></section></div>"; stream_close_script ]

let client_with_promise_props () =
let delayed_value ~ms value =
let%lwt () = Lwt_unix.sleep (Int.to_float ms /. 100.0) in
Lwt.return value
in
let app () =
React.Upper_case_component
(fun () ->
React.List
[|
React.createElement "div" [] [ React.string "Server Content" ];
React.Client_component
{
props =
[ ("promise", React.Promise (delayed_value ~ms:200 "||| Resolved |||", fun res -> `String res)) ];
client = React.string "Client with Props";
import_module = "./client-with-props.js";
import_name = "ClientWithProps";
};
|])
in
assert_async_payload (app ())
~shell:
"<div>Server Content</div>Client with Props<script data-payload='0:[[\"$\",\"div\",null,{\"children\":[\"Server \
Content\"]}],[\"$\",\"$2\",null,{\"promise\":\"$@1\"}]]\n\
'>window.srr_stream.push()</script>"
[
"<script data-payload='2:I[\"./client-with-props.js\",[],\"ClientWithProps\"]\n\
'>window.srr_stream.push()</script>";
"<script data-payload='1:I\"||| Resolved |||\"\n'>window.srr_stream.push()</script>";
stream_close_script;
]

let tests =
[
test "null_element" null_element;
test "upper_case_component" upper_case_component;
test "async_component_without_promise" async_component_without_promise;
test "suspense_without_promise" suspense_without_promise;
test "with_sleepy_promise" with_sleepy_promise;
test "client_with_promise_props" client_with_promise_props;
]
26 changes: 0 additions & 26 deletions packages/reactDom/test/test_RSC_model.ml
Original file line number Diff line number Diff line change
Expand Up @@ -411,32 +411,6 @@ let client_with_server_children () =
"0:\"$1\"\n";
]

let client_with_server_children () =
let server_child () = React.createElement "div" [] [ React.string "Server Component Inside Client" ] in
let app () =
React.Upper_case_component
(fun () ->
React.List
[|
React.createElement "div" [] [ React.string "Server Content" ];
React.Client_component
{
props = [ ("children", React.Element (React.Upper_case_component server_child)) ];
client = React.string "Client with Server Children";
import_module = "./client-with-server-children.js";
import_name = "ClientWithServerChildren";
};
|])
in
let%lwt stream = ReactServerDOM.render_to_model (app ()) in
assert_stream stream
[
"2:I[\"./client-with-server-children.js\",[],\"ClientWithServerChildren\"]\n";
"3:[\"$\",\"div\",null,{\"children\":\"Server Component Inside Client\"}]\n";
"1:[[\"$\",\"div\",null,{\"children\":\"Server Content\"}],[\"$\",\"$2\",null,{\"children\":\"$3\"}]]\n";
"0:\"$1\"\n";
]

let tests =
[
test "null_element" null_element;
Expand Down

0 comments on commit add4a3c

Please sign in to comment.