-
-
Notifications
You must be signed in to change notification settings - Fork 140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to test requests and websockets? [depends on Dream client] #83
Comments
There is some (not much) support for in-process no-network testing, see section Testing. In particular, dream/test/expect/middleware/router.ml Lines 83 to 99 in 500f4d0
These are expect tests, so they just print to STDOUT/STDERR, and There is nothing else besides that, but I do have a notes item to look into this. I'd appreciate it very much if you would let me know what type of testing you'd like to do, and/or provide me with a link to some implementation of it (in JS or elsewhere). I'd then see how it should be supported in Dream or at least in OCaml. There is nothing for testing WebSockets conveniently at the moment, a definite gap. To test them immediately, you'd need to do end-to-end tests with an external tool. |
That's what I was thinking about and what I was afraid of... Basically what I would want is to be able to start a I know how to do it with external tools, but it's a bit of overhead and not as fun as being able to do directly. For other tests, I like the phoenix tests (https://hexdocs.pm/phoenix/testing_controllers.html) describe "index" do
test "lists all posts", %{conn: conn} do
conn = get(conn, Routes.post_path(conn, :index))
assert html_response(conn, 200) =~ "Listing Posts"
end
end (I don't think They also have nice tests for setup do
{:ok, _, socket} =
UserSocket
|> socket("user_id", %{some: :assign})
|> subscribe_and_join(RoomChannel, "room:lobby")
%{socket: socket}
end
test "ping replies with status ok", %{socket: socket} do
ref = push(socket, "ping", %{"hello" => "there"})
assert_reply ref, :ok, %{"hello" => "there"}
end Of course this is not for a general websocket connection, but you get the point. |
Another example: If I want to write a unit test around something that manages the current clients connected to websockets ( |
I started creating Hyper last year, the client counterpart to Dream. It likely can address parts of this issue. |
In particular, the client's requesting functions are I expect this would eventually be useful for the users' Dream (and Hyper) testing. |
Upgrade to the upcoming (0.10.0 ?) h2 API
Is there any recommended way or documentation on how to tests controllers and websockets?
I could use external tools, for example connect to the server with javascript and initiate websockets there, but it would be nice if we could do this from ocaml directly and use
dune
to run the testsThe text was updated successfully, but these errors were encountered: