mpizenberg / elm-test-runner / ElmTestRunner.Reporter

Main module for a test reporter.

Create a main test reporter

worker : Ports Msg -> Platform.Program Flags Model Msg

Create a tests reporter. Some specific ports(ish) are required as arguments, The main Elm module calling this one will typically look like the example below.

port module Reporter exposing (main)

import ElmTestRunner.Reporter exposing (Flags, Model, Msg)
import Json.Decode exposing (Value)

port restart : ({ kind : String, count : Int } -> msg) -> Sub msg

port incomingResult : ({ duration : Float, result : Value, logs : List String } -> msg) -> Sub msg

port signalFinished : { exitCode : Int, testsCount : Int } -> Cmd msg

port stdout : String -> Cmd msg

main : Program Flags Model Msg
main =
    ElmTestRunner.Reporter.worker
        { restart = restart
        , incomingResult = incomingResult
        , stdout = stdout
        , signalFinished = signalFinished
        }

It can later be called with a tiny bit of JS similar to:

// Start the Elm app
const { Elm } = require("./Reporter.elm.js");
const flags = {
  initialSeed: {{ initialSeed }},
  fuzzRuns: {{ fuzzRuns }},
  mode: "{{ reporter }}",
};
const app = Elm.Reporter.init({ flags: flags });

// Pipe the Elm stdout port to stdout
app.ports.stdout.subscribe((str) => process.stdout.write(str));

// Export function to set the callback function when reports are finished
let finishCallback = () => console.error("finishCallback not defined yet");
app.ports.signalFinished.subscribe(({exitCode}) => finishCallback(exitCode));
exports.setCallback = (callback) => { finishCallback = callback; };

// Export function to restart the Elm reporter
exports.restart = app.ports.restart.send;

// Export function to send results to Elm
exports.sendResult = app.ports.incomingResult.send;


type alias Ports msg =
{ restart : ({ kind : String
, testsCount : Basics.Int } -> msg) -> Platform.Sub.Sub msg
, incomingResult : ({ duration : Basics.Float
, result : Json.Decode.Value
, logs : List String } -> msg) -> Platform.Sub.Sub msg
, stdout : String -> Platform.Cmd.Cmd msg
, signalFinished : { exitCode : Basics.Int
, testsCount : Basics.Int } -> Platform.Cmd.Cmd msg 
}

Ports(ish) required by the worker program to function. They aren't necessarily exactly ports but will basically be wrapped by an actual port in the main Elm caller module.

Internal types for function signatures


type alias Flags =
{ initialSeed : Basics.Int
, fuzzRuns : Basics.Int
, mode : String
, verbosity : Basics.Int
, globs : List String
, paths : List String 
}

Arguments passed to the reporter at startup, such as the initial random seed, the number of fuzz runs, and the type of reporter requested: (default)Console|Json|Junit


type alias Model =
{ ports : Ports Msg
, reporter : Interface
, testsCount : Basics.Int
, testResults : Array ElmTestRunner.Result.TestResult
, kind : Result String ElmTestRunner.SeededRunners.Kind 
}

Main model. Exposed for usage in type definitions.


type Msg

Internal messages.