archan937

archan937

ExUnited - Easily spawn Elixir nodes (supervising, Mix configured, easy asserted / refuted) within ExUnit tests

Hi all,

ExUnited is a Hex package designed to easily facilitate spawning supervising local Elixir nodes within tests. Unfortunately, I was not able to properly setup a spawned node for supervisioning with the Erlang :slave.start_link/1 function. So I have written ExUnited to accomplish that, along with supporting Mix.Config configurations, additional loaded code, and a developer friendly way of writing assertions and refutations in the context of a spawned node which really improved the readability of the tests and more.

Features

  • Spawn nodes for testing purposes
  • Spin up “partially connected” vs “fully connected” nodes
  • Run in “verbose” mode which prints a colorized STDOUT of the nodes
  • Specify extra “code paths” which will be included ( config.exs included)
  • Support child supervisioning within a spawned node
  • Exclude certain dependencies for spawned nodes
  • Easily assert and refute within the context of spawned nodes

Example

defmodule MyNodeClusterTest do
  use ExUnited.Case

  setup do
    {:ok, spawned} =
      ExUnited.spawn(
        david: [code_paths: ["test/nodes/beckham"], supervise: [David]]
      )

    on_exit(fn ->
      ExUnited.teardown()
    end)

    spawned
  end

  test "executes code in spawned node", spawned do
    assert :"captain@127.0.0.1" = Node.self()
    refute :"david@127.0.0.1" == Node.self()
    sentence = "The only time you run out of chances is when you stop taking them."

    as_node(:david, phrase: sentence) do
      assert :"david@127.0.0.1" = Node.self()
      refute :"captain@127.0.0.1" == Node.self()
      assert ^phrase = David.talk()

      foo = :bar
      refute match?(%{node: ^foo}, %{node: :foo})
    end
  end
end

See full example.

Enjoy the package! I would love to receive a shoutout and/or your feedback :wink:

First Post!

archan937

archan937

I just released ExUnited v0.1.1 containing the following enhancements:

  • Add :exclude option for individual spawned nodes
  • Exclude current project as dependency (instead, add “lib” to code paths)
  • Do not generate config files
  • Fix redundant prompt when in verbose mode

Where Next?

Popular in Announcing Top

tmbb
PhoenixWS - Websockets over Phoenix Channels Source code on Github here: GitHub - tmbb/phoenix_ws: Websockets implemented over Phoenix Ch...
New
josevalim
Yes, yet another parser combinator library! Most of the parser combinators in the ecosystem are either compile-time, often using AST tra...
159 19228 141
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
kelvinst
Hey everyone! Well, we made this lib a while ago and now we decided to finally go out and public with it! It’s a tool for creating and m...
New
kip
Image is an image processing library for Elixir. It is based upon the fabulous vix library that provides a libvips wrapper for Elixir. I...
622 18474 194
New
ahamez
Hi everyone, I’ve been working on this protobuf library for 3 years. We use it in the company I work for, EasyMile, to communicate with ...
New
nikokozak
Hello all, I’ve been working on Svonix - a library for quickly integrating Svelte components into Phoenix views. It’s a much-needed succ...
New
archan937
It is a well-know topic within the Elixir community: “To mock or not to mock? :)” Every alchemist probably has his / her own opinion con...
New
zachdaniel
Ash Framework What is Ash? Ash Framework is a declarative, resource-oriented application development framework for Elixir. A resource can...
New
New

Other popular topics Top

malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36128 110
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 47930 226
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New

We're in Beta

About us Mission Statement