mpizenberg/elm-test-runner/1.0.0

NOTE: the latest version is 6.0.1

ElmTestRunner.Reporter

Main module for a test reporter.

Create a main test reporter

worker : Ports Msg -> 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 : (Int -> msg) -> Sub msg


port incomingResult : (Value -> msg) -> Sub msg


port signalFinished : 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((code) => finishCallback(code));
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 : (Int -> msg) -> Sub msg
, incomingResult : (Value -> msg) -> Sub msg
, stdout : String -> Cmd msg
, signalFinished : Int -> 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 : Int
, fuzzRuns : Int
, mode : 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
, nbTests : Int
, testResults : Array TestResult
}

Main model. Exposed for usage in type definitions.

type Msg

Internal messages.