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));
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.
It can later be spawned as a Node worker with a tiny bit of JS similar to: