-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
107 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
(env | ||
(dev | ||
(flags | ||
(:standard -w -27)))) | ||
|
||
(dirs packages demo mocked-hash-js) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,40 @@ | ||
let assert_string left right = | ||
Alcotest.check Alcotest.string "should be equal" right left | ||
|
||
let assert_list ty left right = | ||
Alcotest.check (Alcotest.list ty) "should be equal" right left | ||
|
||
let make ~delay = | ||
let () = React.use (Lwt_unix.sleep delay) in | ||
React.createElement "div" [||] | ||
[ | ||
React.createElement "span" [||] | ||
[ React.string "Hello"; React.string "Hello" ]; | ||
[ React.string "Hello"; React.float delay ]; | ||
] | ||
|
||
let cleanup switch abort = | ||
let free () = Lwt.return () in | ||
Lwt_switch.add_hook (Some switch) free; | ||
Lwt.async (fun () -> | ||
abort (); | ||
failwith "All is broken"); | ||
Lwt.return () | ||
let assert_stream (stream : string Lwt_stream.t) expected = | ||
let open Lwt.Infix in | ||
Lwt_stream.to_list stream >>= fun content -> | ||
if content = [] then Lwt.return @@ Alcotest.fail "stream should not be empty" | ||
else Lwt.return @@ assert_list Alcotest.string content expected | ||
|
||
let suspense_one switch () = | ||
let _pipe, abort = ReactDOM.renderToLwtStream (make ~delay:0.1) in | ||
let test_silly_stream _switch () : unit Lwt.t = | ||
let stream, push = Lwt_stream.create () in | ||
push (Some "first"); | ||
push (Some "secondo"); | ||
push None; | ||
assert_stream stream [ "first"; "secondo" ] | ||
|
||
assert_string "asdf" | ||
"<div data-reactroot=\"\"><span>Hello<!-- -->Hello</span></div>"; | ||
cleanup switch abort | ||
let suspense_one _switch () : unit Lwt.t = | ||
let timer = React.Upper_case_component (fun () -> make ~delay:0.1) in | ||
let stream, _abort = ReactDOM.renderToLwtStream timer in | ||
assert_stream stream [ "Hello"; "1." ] | ||
|
||
let case title fn = Alcotest_lwt.test_case title `Quick fn | ||
let tests = ("renderToLwtStream", [ case "suspense_one" suspense_one ]) | ||
|
||
let tests = | ||
( "renderToLwtStream", | ||
[ | ||
case "test_silly_stream" test_silly_stream; | ||
case "suspense_one" suspense_one; | ||
] ) |