Main module for a test runner worker.
worker : Ports Msg -> Maybe Test -> Platform.Program Flags Model Msg
Create a test runner worker.
Some specific ports(ish) are required as arguments,
as well as the "master" test concatenating all tests (CF SeededRunners.fromTest
).
The main Elm module calling this one will typically look like the example below. In that code, {{ user_imports }} and {{ tests }} are to be replaced by the list of needed imports from user code and the list of tests to run.
port module Runner exposing (main)
{{ user_imports }}
import Test
import ElmTestRunner.Runner exposing (Flags, Model, Msg)
import Json.Encode exposing (Value)
port askTestsCount : (Value -> msg) -> Sub msg
port sendTestsCount : { kind : String, testsCount : Int } -> Cmd msg
port receiveRunTest : (Int -> msg) -> Sub msg
port sendResult : { id : Int, result : Value } -> Cmd msg
main : Program Flags Model Msg
main =
[ {{ tests }} ]
|> Test.concat
|> ElmTestRunner.Runner.worker
{ askTestsCount = askTestsCount
, sendTestsCount = sendTestsCount
, receiveRunTest = receiveRunTest
, sendResult = sendResult
}
It can later be spawned as a Node worker with a tiny bit of JS similar to:
const { parentPort } = require("worker_threads");
const { Elm } = require("./Runner.elm.js");
// Start the Elm app
const flags = { initialSeed: ..., fuzzRuns: ... };
const app = Elm.Runner.init({ flags: flags });
// Communication between Elm runner worker and Supervisor via port
app.ports.outgoing.subscribe((msg) => parentPort.postMessage(msg));
parentPort.on("message", (msg) => app.ports.incoming.send(msg));
{ askTestsCount : (Json.Encode.Value -> msg) -> Platform.Sub.Sub msg
, sendTestsCount : { kind : String
, testsCount : Basics.Int } -> Platform.Cmd.Cmd msg
, receiveRunTest : (Basics.Int -> msg) -> Platform.Sub.Sub msg
, sendResult : { id : Basics.Int
, result : Json.Encode.Value } -> Platform.Cmd.Cmd msg
}
Ports required by the worker program to function.
{ initialSeed : Basics.Int
, fuzzRuns : Basics.Int
, filter : Maybe String
}
The initial random seed and the number of fuzz runs are passed as flags.
{ ports : Ports Msg
, testRunners : ElmTestRunner.SeededRunners.SeededRunners
}
Main model. Exposed for usage in type definitions.
Internal messages.