Coder Social home page Coder Social logo

ex_unit_notifier's Introduction

ExUnit Notifier

Build Status Hex version Hex docs Hex downloads License Last Updated

screenshot

Show desktop notifications for ExUnit runs. Works very well with automatic test runners such as mix-test.watch. (Yes, TDD is awesome!)

Currently notifications on OS X and Linux are supported.

Installation

First, add ExUnitNotifier to your mix.exs dependencies:

def deps do
  [
    {:ex_unit_notifier, "~> 1.3", only: :test}
  ]
end

Then, update your dependencies:

$ mix deps.get

For macOS

Follow installation instruction of terminal-notifier if you need to install a particular version.

Otherwise, install current version via Homebrew:

$ brew install terminal-notifier

For GNU/Linux

Install notify-send:

$ sudo apt install libnotify-bin

Usage

Add ExUnitNotifier to your ExUnit configuration in test/test_helper.exs file.

ExUnit.configure formatters: [ExUnit.CLIFormatter, ExUnitNotifier]
ExUnit.start

Now run mix test and you'll see notifications popping up :)

Notification Types

Notifications will be sent from the first available notifier that is deemed available in the order specified below:

  • terminal-notifier (ExUnitNotifier.Notifiers.TerminalNotifier)
  • notify-send (ExUnitNotifier.Notifiers.NotifySend)
  • tmux (ExUnitNotifier.Notifiers.TmuxNotifier)
  • Terminal Title if non of the above match (ExUnitNotifier.Notifiers.TerminalTitle)

To force a specific type of notifier to be used, specify the notifier using the following configuration:

config :ex_unit_notifier, notifier: ExUnitNotifier.Notifiers.TerminalNotifier

You can use one of the available notifiers found in lib/ex_unit_notifier/notifiers, or you can write your own.

Notification Options

For notify-send users, it is possible to clear the notifications from notifications center history using the following configuration, defaults to false:

config :ex_unit_notifier, clear_history: true

Copyright and License

Copyright (c) 2016 Navin Peiris

Source code is released under the MIT license.

ex_unit_notifier's People

Contributors

benjamin-thomas avatar ciaran avatar denispeplin avatar kianmeng avatar navinpeiris avatar pojiro avatar rauann avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ex_unit_notifier's Issues

Notifications Break in Tmux

Terminal Notifier breaks in tmux. Change ExUnitNotifier.Notifiers.TerminalNotifier.available?/0 to check for TMUX in the environment. If TMUX is set then we are in TMUX and the notifier should not be available.

Add Notifications for Windows

On Windows the following PowerShell script can be used for creating a tray notification:

Invoke-Notification.ps1

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

Function Invoke-Notification {
    <#
    .Synopsis
        Display a balloon tip message in the system tray.

    .Description
        This function displays a user-defined message as a balloon popup in the system tray. This function
        requires Windows Vista or later.

    .Parameter Title
        The title for the message balloon.

    .Parameter Message
        The message text you want to display.  Recommended to keep it short and simple.

    .Parameter MessageType
        The type of message. This value determines what type of icon to display. Valid values are:
        Info,Error,Warning,None

    .Parameter SysTrayIcon
        The path to a file that you will use as the system tray icon. Default is the PowerShell ISE icon.

    .Parameter Duration
        The number of seconds to display the balloon popup. The default is 1000.

    .Inputs
        None

    .Outputs
        None

    .Notes
         NAME:      Invoke-BalloonTip
         VERSION:   1.1
         AUTHOR:    Marduk Bolaños
         HISTORY:   Based on the original by Boe Prox.
    #>

    [CmdletBinding()]
    Param (
        [Parameter(HelpMessage="The message title")]
        [string]$Title="Attention $env:username",

        [Parameter(Mandatory=$True,HelpMessage="The message text to display. Keep it short and simple.")]
        [string]$Message,

        [Parameter(HelpMessage="The message type: Info,Error,Warning,None")]
        [System.Windows.Forms.ToolTipIcon]$MessageType="Info",
     
        [Parameter(HelpMessage="The path to a file to use its icon in the system tray")]
        [string]$SysTrayIconPath='C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe',     

        [Parameter(HelpMessage="The number of milliseconds to display the message.")]
        [int]$Duration=1000
    )

    Add-Type -AssemblyName System.Windows.Forms

    If (-NOT $global:balloon) {
        $global:balloon = New-Object System.Windows.Forms.NotifyIcon
    }

    $balloon.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($SysTrayIconPath)
    $balloon.BalloonTipIcon  = [System.Windows.Forms.ToolTipIcon]$MessageType
    $balloon.BalloonTipText  = $Message
    $balloon.BalloonTipTitle = $Title
    $balloon.Visible = $true
    $balloon.ShowBalloonTip($Duration)

    Write-Verbose "Ending function"
}

$cmd, $params = $args
& $cmd @params

The script can be executed with:

powershell.exe .\path\to\Invoke-Notification.ps1 Invoke-Notification Title Message

Caveats

  • Notifications have to be enabled. In an enterprise environment they might be disabled by a company-wide policy.
  • The user may have to change the ExecutionPolicy to e.g. RemoteSigned. However, I tried this script with the default policy, Restricted, and it works. So it shouldn't be necessary to change it.

tmux notifier overwrites user's tmux confg

To perform a notification, TmuxNotifier manually alters the user's tmux configuration value "window-status-style" with a fixed value of red or green. This is not raising an alert of any kind, it is manually changing the user's configuration. It causes several issues:

  • Most obviously, if the user's config already uses red or green in their status bar, the notification is either not visible or incorrect.
  • There is no way for the user to clear the notification other than killing the window or manually reconfiguring the value. (Tmux alerts are by default cleared by activating the window.)
  • It's surprising to developers, because tmux already has several configurable notification mechanisms.
  • It doesn't work with other terminal handlers, e.g. GNUscreen
  • It doesn't work over SSH or other environments where TMUX_PANE isn't propagated.

The tmux notifier doesn't seem necessary at all. ExUnit already provides an exit code for success or failure, and it is trivial to cause a terminal bell for failure (e.g. mix test || echo -e \\a) which is already handled as a notification by tmux and other systems.

Simply removing the tmux notifier fixes all the above issues.

ExUnitNotifier.handle_event/2 is undefined or private

Today I just installed

  1. add dependency {:ex_unit_notifier, "~> 0.1", only: :test}
  2. add to test_helper.exs ExUnit.configure formatters: [ExUnit.CLIFormatter, ExUnitNotifier]
  3. add to config/test.exs config :ex_unit_notifier, notifier: ExUnitNotifier.Notifiers.NotifySend neither it's working with default
  4. mix test.watch

I'm using:

  • erlang 19.3
  • elixir 1.3

and got this

11:55:00.139 [error] GenEvent handler ExUnitNotifier installed in #PID<0.1123.0> terminating
** (UndefinedFunctionError) function ExUnitNotifier.handle_event/2 is undefined or private. Did you mean one of:

      * handle_cast/2
      * handle_info/2

Only notify on status change

The gist of this feature request, have an option to only notify if test status changes. For instance if a test starts breaking, more tests break, or tests all pass after a fix.

This way of working is superior to me. They I don't get distracted when status has not changed. Tests just run in the background.

I would be happy to contribute some code, if you would like this feature.

Related, but unsure if possible, is to notify when test code does not compile. Will be happy to have a look at that as well.

Allow options to be added to notifiers

Terminal notifier has some options that could be useful when testing. I personally would like to have the notifier use the SOUND option. It would be nice to be able to have two different sounds when the notifier signals failure or success.

Hangs when run on a phoenix project

I started a fresh phoenix project on a Mac. The following are my dependencies:

  defp deps do
    [{:phoenix, "~> 1.2.1"},
     {:phoenix_pubsub, "~> 1.0"},
     {:phoenix_ecto, "~> 3.0"},
     {:postgrex, ">= 0.0.0"},
     {:phoenix_html, "~> 2.6"},
     {:phoenix_live_reload, "~> 1.0", only: :dev},
     {:gettext, "~> 0.11"},
     {:cowboy, "~> 1.0"},
     {:distillery, "~> 0.10"},
     {:excoveralls, "~> 0.5", only: :test},
     {:credo, "~> 0.4", only: [:dev, :test]},
     {:dogma, "~> 0.1", only: :dev},
     {:mix_test_watch, "~> 0.2", only: :dev},
     {:ex_unit_notifier, "~> 0.1", only: :test}]
  end

As soon as I add

ExUnit.configure formatters: [ExUnit.CLIFormatter, ExUnitNotifier]

above the ExUnit.start line to test/test_helper.exs the tests start to run (I get 4 dots), but then there's no notification and the tests hang. Commenting out the above line, the tests run fine.

Uncommented:

$ mix test
....

Commented out:

$ mix test
....

Finished in 0.1 seconds
4 tests, 0 failures

Randomized with seed 717882

I do have terminal-notifier installed and on my path.

$ which terminal-notifier
/usr/local/bin/terminal-notifier
$ terminal-notifier --help
terminal-notifier (1.7.1) is a command-line tool to send OS X User Notifications.
# ... <help output removed> ...

Using elixir 1.3.2 / erlang 19

$ elixir -v
Erlang/OTP 19 [erts-8.0.2] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Elixir 1.3.2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.