An approach to functional tests Phoenix extension library

Girls and boys,

I am developing Drab, an extension to Phoenix which allows you to manipulate browser UI directly from Elixir. Inside it, I use Channels to communicate with the client, as well as some other Phoenix function, like Token. Drab cannot live without Phoenix, there is no way to run it standalone. There are two parts of the project: server-side Elixir and client-side JS library.

The project is slowly going from sandbox to beta, so now it is a time to consider the way how to do the tests. Most of the Drab functionality is about communicating to the browser and getting replies back from there (or vice-versa). Therefore, unit tests can not cover a lot. I need functional (end-to-end) tests.

I am planning to use phantomjs for this, as I have a good experience using this browser in the Rails world.

What I need from the community, is to help me to choose the approach for end-to-end tests. For functional testing, I need Phoenix with Drab to be running. For now, I’ve found this options:

  • Include Phoenix app in the Drab:
    Create the Phoenix application inside Drab, just for tests, and limit the Hex package to Drab libraries and templates.

  • Create standalone Phoenix app and put Drab under umbrella with it
    This option I like the most, as Drab and Phoenix app will be separated. And it is simple. But what if someone want to include Drab to his application without using hex, but directly from github?

There is also a third option:

  • Go standalone
    Remove dependency of Phoenix and add websockets functionality to Drab, so it will not need Channels anymore. The issue is that it is a plenty of work, and I would feel like re-inventing the wheel. Phoenix Channels and Tokens are great, why not to use it?

Please share your opinion, thanks in advance :slight_smile:

2 Likes

I create the applications entirely within the test directory for testing end-to-end things like that, so I’d just do that. :slight_smile:

3 Likes

Thanks for the tip, I will probalby do like this. This is the most elegant way to archive my goals.

Have you got any issues building Phoenix App in test/? Is your app you mentioned public, so I could take a look? :slight_smile: I am curious how you’ve dealt with mix.exs for your app and phoenix.

1 Like

I only have one mix.exs. ^.^

It is in my work project, the testing phoenix thing is just a custom endpoint module and so forth. Remember, it is easy to build a phoenix application, even with no templates or so, it is mostly just a set of Plugs after all. :slight_smile:

2 Likes

You probably only need the phoenix endpoint:

Application.put_env(:drab, MyApp.Endpoint, http: [port: 4567], server: true, secret_key_base: "something long")

defmodule MyApp.Endpoint do
  use Phoenix.Endpoint, otp_app: :drab

  socket ...
  plug :i_am_only_using_websockets
  defp i_am_only_using_websockets(_, _) do
    raise "oops"
  end
end

MyApp.Endpoint.start_link

There is probably more configuration you need to set on Application.put_env(...) but you can grab that from config/test.exs (or config/dev.exs) from a brand new Phoenix app. Then you just copy in the other files that you need, such as the UserSocket.

4 Likes