A Lamdera package. It is not on package.elm-lang.org: the Lamdera compiler provides it, from static.lamdera.com, so lamdera install works and elm install does not.
Setting up the simulation
Configure the simulation before starting it
import Backend
import Effect.Test
import Frontend
import Test exposing (Test)
config =
{ frontendApp = Frontend.appFunctions
, backendApp = Backend.appFunctions
, handleHttpRequest = always NetworkError_
, handlePortToJs = always Nothing
, handleFileRequest = always Nothing
, domain = unsafeUrl "https://my-app.lamdera.app"
}
test : Test
test =
Effect.Test.start "myButton is clickable"
|> Effect.Test.connectFrontend
sessionId0
myDomain
{ width = 1920, height = 1080 }
(\( state, frontendActions ) ->
state
|> frontendActions.clickButton { htmlId = "myButton" }
)
|> Effect.Test.toTestAdd a frontend client to the simulation!
import Effect.Test
import Test exposing (Test)
testApp =
Effect.Test.testApp
Frontend.appFunctions
Backend.appFunctions
(always NetworkError_)
(always Nothing)
(always Nothing)
(unsafeUrl "https://my-app.lamdera.app")
test : Test
test =
testApp "myButton is clickable"
|> Effect.Test.connectFrontend
sessionId0
myDomain
{ width = 1920, height = 1080 }
(\( state, frontendActions ) ->
state
|> frontendActions.clickButton { htmlId = "myButton" }
)
|> Effect.Test.toTestWho made this http request?
Control the simulation
FrontendActions contains the possible functions we can call on the client we just connected.
import Effect.Test
import Test exposing (Test)
testApp =
Effect.Test.testApp
Frontend.appFunctions
Backend.appFunctions
(always NetworkError_)
(always Nothing)
(always Nothing)
(unsafeUrl "https://my-app.lamdera.app")
test : Test
test =
testApp "myButton is clickable"
|> Effect.Test.connectFrontend
sessionId0
myDomain
{ width = 1920, height = 1080 }
(\( state, frontendActions ) ->
-- frontendActions is a record we can use on this specific frontend we just connected
state
|> frontendActions.clickButton { htmlId = "myButton" }
)
|> Effect.Test.toTestNormally you won't send data directly to the backend and instead use connectFrontend followed by things like clickButton or inputText to cause the frontend to send data to the backend.
If you do need to send data directly, then you can use this though.
Simulate the passage of time.
This will trigger any subscriptions like Browser.onAnimationFrame or Time.every along the way.
If you need to simulate a large passage of time and are finding that it's taking too long to run, try fastForward instead.
Similar to simulateTime but this will not trigger any Browser.onAnimationFrame or Time.every subscriptions.
This is useful if you need to move the clock forward a week and it would take too long to simulate it perfectly.
Sometimes you need to decide what should happen next based on some simulation state. In order to do that you can write something like this:
state
|> TF.andThen
(\state2 ->
case List.filterMap isLoginEmail state2.httpRequests |> List.head of
Just loginEmail ->
TF.continueWith state2
|> testApp.connectFrontend
sessionIdFromEmail
(loginEmail.loginUrl)
(\( state3, clientIdFromEmail ) ->
...
)
Nothing ->
TF.continueWith state2 |> TF.checkState (\_ -> Err "Should have gotten a login email")
)Sometimes you need to decide what should happen next based on some simulation state. In order to do that you can write something like this:
state
|> TF.andThen
(\state2 ->
case List.filterMap isLoginEmail state2.httpRequests |> List.head of
Just loginEmail ->
TF.continueWith state2
|> testApp.connectFrontend
sessionIdFromEmail
(loginEmail.loginUrl)
(\( state3, clientIdFromEmail ) ->
...
)
Nothing ->
TF.continueWith state2 |> TF.checkState (\_ -> Err "Should have gotten a login email")
)Test the simulation
Get all snapshots from a test. This can be used with Effect.Snapshot.uploadSnapshots to perform visual regression testing.
Miscellaneous
View your end-to-end tests in a elm reactor style app.
Setup a test.