elm-pages 3.0.0-beta.14 → 3.0.0-beta.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/codegen/elm-pages-codegen.js +4 -7
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_runner.js +1 -1
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_supervisor.js +1 -1
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/js/node_runner.js +1 -1
- package/generator/review/elm-stuff/tests-0.19.1/js/node_supervisor.js +1 -1
- package/generator/src/compatibility-key.js +1 -1
- package/generator/src/error-formatter.js +7 -3
- package/generator/src/render.js +8 -17
- package/generator/src/request-cache.js +34 -4
- package/generator/static-code/hmr.js +16 -2
- package/package.json +1 -1
- package/src/ApiRoute.elm +1 -4
- package/src/BackendTask/Env.elm +10 -8
- package/src/BackendTask/File.elm +10 -10
- package/src/BackendTask/Glob.elm +2 -2
- package/src/BackendTask/Http.elm +49 -13
- package/src/BackendTask/Port.elm +50 -46
- package/src/BackendTask.elm +5 -5
- package/src/Exception.elm +70 -12
- package/src/Form.elm +3 -2
- package/src/Pages/Generate.elm +299 -102
- package/src/Pages/Internal/Platform/Cli.elm +17 -37
- package/src/Pages/Internal/Platform/CompatibilityKey.elm +1 -1
- package/src/Pages/Internal/Platform/GeneratorApplication.elm +17 -41
- package/src/Pages/Internal/Platform/StaticResponses.elm +11 -25
- package/src/Pages/Script.elm +2 -2
- package/src/Pages/StaticHttpRequest.elm +1 -23
- package/src/Server/Request.elm +3 -2
- package/src/MultiDict.elm +0 -49
- package/src/PairingHeap.elm +0 -137
- package/src/Parser/Extra/String.elm +0 -33
- package/src/Parser/Extra.elm +0 -69
- package/src/ProgramTest/ComplexQuery.elm +0 -360
- package/src/ProgramTest/EffectSimulation.elm +0 -122
- package/src/ProgramTest/Failure.elm +0 -367
- package/src/ProgramTest/HtmlHighlighter.elm +0 -116
- package/src/ProgramTest/HtmlParserHacks.elm +0 -58
- package/src/ProgramTest/HtmlRenderer.elm +0 -73
- package/src/ProgramTest/Program.elm +0 -30
- package/src/ProgramTest/StringLines.elm +0 -26
- package/src/ProgramTest/TestHtmlHacks.elm +0 -132
- package/src/ProgramTest/TestHtmlParser.elm +0 -201
- package/src/ProgramTest.elm +0 -2339
- package/src/Query/Extra.elm +0 -55
- package/src/SimulatedEffect/Cmd.elm +0 -69
- package/src/SimulatedEffect/Http.elm +0 -330
- package/src/SimulatedEffect/Navigation.elm +0 -69
- package/src/SimulatedEffect/Ports.elm +0 -62
- package/src/SimulatedEffect/Process.elm +0 -24
- package/src/SimulatedEffect/Sub.elm +0 -48
- package/src/SimulatedEffect/Task.elm +0 -252
- package/src/SimulatedEffect/Time.elm +0 -25
- package/src/SimulatedEffect.elm +0 -42
- package/src/String/Extra.elm +0 -6
- package/src/Test/Http.elm +0 -145
- package/src/TestResult.elm +0 -35
- package/src/TestState.elm +0 -305
- package/src/Url/Extra.elm +0 -100
- package/src/Vendored/Diff.elm +0 -321
- package/src/Vendored/Failure.elm +0 -217
- package/src/Vendored/FormatMonochrome.elm +0 -44
- package/src/Vendored/Highlightable.elm +0 -53
package/src/Query/Extra.elm
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
module Query.Extra exposing (oneOf)
|
|
2
|
-
|
|
3
|
-
import Html
|
|
4
|
-
import Test.Html.Query as Query
|
|
5
|
-
import Test.Html.Selector as Selector
|
|
6
|
-
import Test.Runner
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
{-| This is a hack for the fact that elm-html-test does not provide a way to force a `Query.Single` into an error state.
|
|
10
|
-
-}
|
|
11
|
-
fail : String -> Query.Single msg -> Query.Single msg
|
|
12
|
-
fail message _ =
|
|
13
|
-
Html.text ("ERROR: " ++ message)
|
|
14
|
-
|> Query.fromHtml
|
|
15
|
-
|> Query.find [ Selector.text "SHOULD NOT HAVE ERROR" ]
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
{-| Determines whether the given `Query.Single` is an error (failed to match a node)
|
|
19
|
-
-}
|
|
20
|
-
isFailed : Query.Single msg -> Bool
|
|
21
|
-
isFailed single =
|
|
22
|
-
case single |> Query.has [] |> Test.Runner.getFailureReason of
|
|
23
|
-
Just _ ->
|
|
24
|
-
True
|
|
25
|
-
|
|
26
|
-
Nothing ->
|
|
27
|
-
False
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
{-| TODO: Is it strange that this takes a `List (Single -> Single)`? Is it safer or more sensible to take `List (List Selector)` and then implicily only work with `Query.find`?
|
|
31
|
-
-}
|
|
32
|
-
oneOf : List (Query.Single msg -> Query.Single msg) -> Query.Single msg -> Query.Single msg
|
|
33
|
-
oneOf options single =
|
|
34
|
-
if isFailed single then
|
|
35
|
-
-- the input single is an error, so just return that
|
|
36
|
-
single
|
|
37
|
-
|
|
38
|
-
else
|
|
39
|
-
case options of
|
|
40
|
-
[] ->
|
|
41
|
-
fail "Query.Extra.oneOf was given an empty list of options" single
|
|
42
|
-
|
|
43
|
-
[ last ] ->
|
|
44
|
-
-- this is the last option, so if it fails, we want to return that failure
|
|
45
|
-
-- TODO: if the all failed, give a better error message about everything that failed
|
|
46
|
-
single |> last
|
|
47
|
-
|
|
48
|
-
next :: rest1 :: rest ->
|
|
49
|
-
if isFailed (next single) then
|
|
50
|
-
-- this option failed, so try the remaining ones
|
|
51
|
-
oneOf (rest1 :: rest) single
|
|
52
|
-
|
|
53
|
-
else
|
|
54
|
-
-- this option passed, so return success
|
|
55
|
-
next single
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
module SimulatedEffect.Cmd exposing
|
|
2
|
-
( none, batch
|
|
3
|
-
, map
|
|
4
|
-
)
|
|
5
|
-
|
|
6
|
-
{-| This module parallels [elm/core's `Platform.Cmd` module](https://package.elm-lang.org/packages/elm/core/1.0.2/Platform-Cmd).
|
|
7
|
-
|
|
8
|
-
The functions here produce `SimulatedEffect`s instead of `Cmd`s, which are meant to be used
|
|
9
|
-
to help you implement the function to provide when using [`ProgramTest.withSimulatedEffects`](ProgramTest#withSimulatedEffects).
|
|
10
|
-
|
|
11
|
-
@docs none, batch
|
|
12
|
-
|
|
13
|
-
@docs map
|
|
14
|
-
|
|
15
|
-
-}
|
|
16
|
-
|
|
17
|
-
import ProgramTest exposing (SimulatedEffect)
|
|
18
|
-
import SimulatedEffect
|
|
19
|
-
import SimulatedEffect.Task as Task
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
{-| Tell the runtime that there are no commands.
|
|
23
|
-
-}
|
|
24
|
-
none : SimulatedEffect msg
|
|
25
|
-
none =
|
|
26
|
-
SimulatedEffect.None
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
{-| When you need the runtime system to perform a couple commands, you can batch them together.
|
|
30
|
-
-}
|
|
31
|
-
batch : List (SimulatedEffect msg) -> SimulatedEffect msg
|
|
32
|
-
batch =
|
|
33
|
-
SimulatedEffect.Batch
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
{-| Transform the messages produced by a command.
|
|
37
|
-
-}
|
|
38
|
-
map : (a -> msg) -> SimulatedEffect a -> SimulatedEffect msg
|
|
39
|
-
map f effect =
|
|
40
|
-
case effect of
|
|
41
|
-
SimulatedEffect.None ->
|
|
42
|
-
SimulatedEffect.None
|
|
43
|
-
|
|
44
|
-
SimulatedEffect.Batch effects ->
|
|
45
|
-
SimulatedEffect.Batch (List.map (map f) effects)
|
|
46
|
-
|
|
47
|
-
SimulatedEffect.Task t ->
|
|
48
|
-
t
|
|
49
|
-
|> Task.map f
|
|
50
|
-
|> Task.mapError f
|
|
51
|
-
|> SimulatedEffect.Task
|
|
52
|
-
|
|
53
|
-
SimulatedEffect.PortEffect portName value ->
|
|
54
|
-
SimulatedEffect.PortEffect portName value
|
|
55
|
-
|
|
56
|
-
SimulatedEffect.PushUrl url ->
|
|
57
|
-
SimulatedEffect.PushUrl url
|
|
58
|
-
|
|
59
|
-
SimulatedEffect.ReplaceUrl url ->
|
|
60
|
-
SimulatedEffect.ReplaceUrl url
|
|
61
|
-
|
|
62
|
-
SimulatedEffect.Back n ->
|
|
63
|
-
SimulatedEffect.Back n
|
|
64
|
-
|
|
65
|
-
SimulatedEffect.Load url ->
|
|
66
|
-
SimulatedEffect.Load url
|
|
67
|
-
|
|
68
|
-
SimulatedEffect.Reload skipCache ->
|
|
69
|
-
SimulatedEffect.Reload skipCache
|
|
@@ -1,330 +0,0 @@
|
|
|
1
|
-
module SimulatedEffect.Http exposing
|
|
2
|
-
( get, post, request
|
|
3
|
-
, Header, header
|
|
4
|
-
, Body, emptyBody, stringBody, jsonBody
|
|
5
|
-
, Expect, expectString, expectJson, expectWhatever, Error
|
|
6
|
-
, expectStringResponse, Response
|
|
7
|
-
, task, Resolver, stringResolver
|
|
8
|
-
)
|
|
9
|
-
|
|
10
|
-
{-| This module parallels [elm/http's `Http` module](https://package.elm-lang.org/packages/elm/http/2.0.0/Http).
|
|
11
|
-
_Pull requests are welcome to add any functions that are missing._
|
|
12
|
-
|
|
13
|
-
The functions here produce `SimulatedEffect`s instead of `Cmd`s, which are meant to be used
|
|
14
|
-
to help you implement the function to provide when using [`ProgramTest.withSimulatedEffects`](ProgramTest#withSimulatedEffects).
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
# Requests
|
|
18
|
-
|
|
19
|
-
@docs get, post, request
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
# Header
|
|
23
|
-
|
|
24
|
-
@docs Header, header
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
# Body
|
|
28
|
-
|
|
29
|
-
@docs Body, emptyBody, stringBody, jsonBody
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
# Expect
|
|
33
|
-
|
|
34
|
-
@docs Expect, expectString, expectJson, expectWhatever, Error
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
# Elaborate Expectations
|
|
38
|
-
|
|
39
|
-
@docs expectStringResponse, Response
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
# Tasks
|
|
43
|
-
|
|
44
|
-
@docs task, Resolver, stringResolver
|
|
45
|
-
|
|
46
|
-
-}
|
|
47
|
-
|
|
48
|
-
import Http
|
|
49
|
-
import Json.Decode exposing (Decoder)
|
|
50
|
-
import Json.Encode
|
|
51
|
-
import ProgramTest exposing (SimulatedEffect, SimulatedTask)
|
|
52
|
-
import SimulatedEffect
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
{-| Create a `GET` request.
|
|
56
|
-
-}
|
|
57
|
-
get :
|
|
58
|
-
{ url : String
|
|
59
|
-
, expect : Expect msg
|
|
60
|
-
}
|
|
61
|
-
-> SimulatedEffect msg
|
|
62
|
-
get r =
|
|
63
|
-
request
|
|
64
|
-
{ method = "GET"
|
|
65
|
-
, headers = []
|
|
66
|
-
, url = r.url
|
|
67
|
-
, body = emptyBody
|
|
68
|
-
, expect = r.expect
|
|
69
|
-
, timeout = Nothing
|
|
70
|
-
, tracker = Nothing
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
{-| Create a `POST` request.
|
|
75
|
-
-}
|
|
76
|
-
post :
|
|
77
|
-
{ url : String
|
|
78
|
-
, body : Body
|
|
79
|
-
, expect : Expect msg
|
|
80
|
-
}
|
|
81
|
-
-> SimulatedEffect msg
|
|
82
|
-
post r =
|
|
83
|
-
request
|
|
84
|
-
{ method = "POST"
|
|
85
|
-
, headers = []
|
|
86
|
-
, url = r.url
|
|
87
|
-
, body = r.body
|
|
88
|
-
, expect = r.expect
|
|
89
|
-
, timeout = Nothing
|
|
90
|
-
, tracker = Nothing
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
{-| Create a custom request.
|
|
95
|
-
-}
|
|
96
|
-
request :
|
|
97
|
-
{ method : String
|
|
98
|
-
, headers : List Header
|
|
99
|
-
, url : String
|
|
100
|
-
, body : Body
|
|
101
|
-
, expect : Expect msg
|
|
102
|
-
, timeout : Maybe Float
|
|
103
|
-
, tracker : Maybe String
|
|
104
|
-
}
|
|
105
|
-
-> SimulatedEffect msg
|
|
106
|
-
request r =
|
|
107
|
-
let
|
|
108
|
-
(Expect onResult) =
|
|
109
|
-
r.expect
|
|
110
|
-
in
|
|
111
|
-
SimulatedEffect.HttpTask
|
|
112
|
-
{ method = r.method
|
|
113
|
-
, url = r.url
|
|
114
|
-
, headers =
|
|
115
|
-
case r.body of
|
|
116
|
-
EmptyBody ->
|
|
117
|
-
r.headers
|
|
118
|
-
|
|
119
|
-
StringBody body ->
|
|
120
|
-
header "Content-Type" body.contentType :: r.headers
|
|
121
|
-
, body =
|
|
122
|
-
case r.body of
|
|
123
|
-
EmptyBody ->
|
|
124
|
-
""
|
|
125
|
-
|
|
126
|
-
StringBody body ->
|
|
127
|
-
body.content
|
|
128
|
-
, onRequestComplete = onResult >> SimulatedEffect.Succeed
|
|
129
|
-
}
|
|
130
|
-
|> SimulatedEffect.Task
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
{-| An HTTP header for configuring requests.
|
|
134
|
-
-}
|
|
135
|
-
type alias Header =
|
|
136
|
-
( String, String )
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
{-| Create a `Header`.
|
|
140
|
-
-}
|
|
141
|
-
header : String -> String -> Header
|
|
142
|
-
header =
|
|
143
|
-
Tuple.pair
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
{-| Represents the body of a `Request`.
|
|
147
|
-
-}
|
|
148
|
-
type Body
|
|
149
|
-
= EmptyBody
|
|
150
|
-
| StringBody
|
|
151
|
-
{ contentType : String
|
|
152
|
-
, content : String
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
{-| Create an empty body for your `Request`.
|
|
157
|
-
-}
|
|
158
|
-
emptyBody : Body
|
|
159
|
-
emptyBody =
|
|
160
|
-
EmptyBody
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
{-| Put some JSON value in the body of your `Request`. This will automatically
|
|
164
|
-
add the `Content-Type: application/json` header.
|
|
165
|
-
-}
|
|
166
|
-
jsonBody : Json.Encode.Value -> Body
|
|
167
|
-
jsonBody value =
|
|
168
|
-
StringBody
|
|
169
|
-
{ contentType = "application/json"
|
|
170
|
-
, content = Json.Encode.encode 0 value
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
{-| Put some string in the body of your `Request`.
|
|
175
|
-
-}
|
|
176
|
-
stringBody : String -> String -> Body
|
|
177
|
-
stringBody contentType content =
|
|
178
|
-
StringBody
|
|
179
|
-
{ contentType = contentType
|
|
180
|
-
, content = content
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
{-| Logic for interpreting a response body.
|
|
185
|
-
-}
|
|
186
|
-
type Expect msg
|
|
187
|
-
= Expect (Http.Response String -> msg)
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
{-| Expect the response body to be a `String`.
|
|
191
|
-
-}
|
|
192
|
-
expectString : (Result Http.Error String -> msg) -> Expect msg
|
|
193
|
-
expectString onResult =
|
|
194
|
-
Expect <|
|
|
195
|
-
\response ->
|
|
196
|
-
case response of
|
|
197
|
-
Http.BadUrl_ s ->
|
|
198
|
-
onResult (Err <| Http.BadUrl s)
|
|
199
|
-
|
|
200
|
-
Http.Timeout_ ->
|
|
201
|
-
onResult (Err Http.Timeout)
|
|
202
|
-
|
|
203
|
-
Http.NetworkError_ ->
|
|
204
|
-
onResult (Err Http.NetworkError)
|
|
205
|
-
|
|
206
|
-
Http.BadStatus_ metadata body ->
|
|
207
|
-
onResult (Err <| Http.BadStatus metadata.statusCode)
|
|
208
|
-
|
|
209
|
-
Http.GoodStatus_ _ body ->
|
|
210
|
-
onResult (Ok body)
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
{-| Expect a Response with a String body.
|
|
214
|
-
-}
|
|
215
|
-
expectStringResponse : (Result x a -> msg) -> (Response String -> Result x a) -> Expect msg
|
|
216
|
-
expectStringResponse toMsg onResponse =
|
|
217
|
-
Expect (onResponse >> toMsg)
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
{-| Expect the response body to be JSON.
|
|
221
|
-
-}
|
|
222
|
-
expectJson : (Result Http.Error a -> msg) -> Decoder a -> Expect msg
|
|
223
|
-
expectJson onResult decoder =
|
|
224
|
-
Expect <|
|
|
225
|
-
\response ->
|
|
226
|
-
case response of
|
|
227
|
-
Http.BadUrl_ s ->
|
|
228
|
-
onResult (Err <| Http.BadUrl s)
|
|
229
|
-
|
|
230
|
-
Http.Timeout_ ->
|
|
231
|
-
onResult (Err Http.Timeout)
|
|
232
|
-
|
|
233
|
-
Http.NetworkError_ ->
|
|
234
|
-
onResult (Err Http.NetworkError)
|
|
235
|
-
|
|
236
|
-
Http.BadStatus_ metadata _ ->
|
|
237
|
-
onResult (Err <| Http.BadStatus metadata.statusCode)
|
|
238
|
-
|
|
239
|
-
Http.GoodStatus_ _ body ->
|
|
240
|
-
case Json.Decode.decodeString decoder body of
|
|
241
|
-
Err jsonError ->
|
|
242
|
-
onResult (Err <| Http.BadBody <| Json.Decode.errorToString jsonError)
|
|
243
|
-
|
|
244
|
-
Ok value ->
|
|
245
|
-
onResult (Ok value)
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
{-| Expect the response body to be whatever.
|
|
249
|
-
-}
|
|
250
|
-
expectWhatever : (Result Error () -> msg) -> Expect msg
|
|
251
|
-
expectWhatever onResult =
|
|
252
|
-
Expect <|
|
|
253
|
-
\response ->
|
|
254
|
-
case response of
|
|
255
|
-
Http.BadUrl_ s ->
|
|
256
|
-
onResult (Err <| Http.BadUrl s)
|
|
257
|
-
|
|
258
|
-
Http.Timeout_ ->
|
|
259
|
-
onResult (Err Http.Timeout)
|
|
260
|
-
|
|
261
|
-
Http.NetworkError_ ->
|
|
262
|
-
onResult (Err Http.NetworkError)
|
|
263
|
-
|
|
264
|
-
Http.BadStatus_ metadata _ ->
|
|
265
|
-
onResult (Err <| Http.BadStatus metadata.statusCode)
|
|
266
|
-
|
|
267
|
-
Http.GoodStatus_ _ _ ->
|
|
268
|
-
onResult (Ok ())
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
{-| -}
|
|
272
|
-
type alias Error =
|
|
273
|
-
Http.Error
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
{-| -}
|
|
277
|
-
type alias Response body =
|
|
278
|
-
Http.Response body
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
{-| Just like [`request`](#request), but it creates a `Task`.
|
|
282
|
-
-}
|
|
283
|
-
task :
|
|
284
|
-
{ method : String
|
|
285
|
-
, headers : List Header
|
|
286
|
-
, url : String
|
|
287
|
-
, body : Body
|
|
288
|
-
, resolver : Resolver x a
|
|
289
|
-
, timeout : Maybe Float
|
|
290
|
-
}
|
|
291
|
-
-> SimulatedTask x a
|
|
292
|
-
task r =
|
|
293
|
-
SimulatedEffect.HttpTask
|
|
294
|
-
{ method = r.method
|
|
295
|
-
, url = r.url
|
|
296
|
-
, headers = r.headers
|
|
297
|
-
, body =
|
|
298
|
-
case r.body of
|
|
299
|
-
EmptyBody ->
|
|
300
|
-
""
|
|
301
|
-
|
|
302
|
-
StringBody body ->
|
|
303
|
-
body.content
|
|
304
|
-
, onRequestComplete =
|
|
305
|
-
case r.resolver of
|
|
306
|
-
StringResolver f ->
|
|
307
|
-
f
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
{-| Describes how to resolve an HTTP task.
|
|
312
|
-
-}
|
|
313
|
-
type Resolver x a
|
|
314
|
-
= StringResolver (Response String -> SimulatedTask x a)
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
{-| Turn a response with a `String` body into a result.
|
|
318
|
-
-}
|
|
319
|
-
stringResolver : (Response String -> Result x a) -> Resolver x a
|
|
320
|
-
stringResolver f =
|
|
321
|
-
let
|
|
322
|
-
fromResult result =
|
|
323
|
-
case result of
|
|
324
|
-
Err x ->
|
|
325
|
-
SimulatedEffect.Fail x
|
|
326
|
-
|
|
327
|
-
Ok a ->
|
|
328
|
-
SimulatedEffect.Succeed a
|
|
329
|
-
in
|
|
330
|
-
StringResolver (f >> fromResult)
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
module SimulatedEffect.Navigation exposing
|
|
2
|
-
( pushUrl, replaceUrl, back
|
|
3
|
-
, load, reload, reloadAndSkipCache
|
|
4
|
-
)
|
|
5
|
-
|
|
6
|
-
{-| This module parallels [elm/browsers's `Browser.Navigation` module](https://package.elm-lang.org/packages/elm/browser/1.0.1/Browser-Navigation).
|
|
7
|
-
_Pull requests are welcome to add any functions that are missing._
|
|
8
|
-
|
|
9
|
-
The functions here produce `SimulatedEffect`s instead of `Cmd`s, which are meant to be used
|
|
10
|
-
to help you implement the function to provide when using [`ProgramTest.withSimulatedEffects`](ProgramTest#withSimulatedEffects).
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
# Navigate within Page
|
|
14
|
-
|
|
15
|
-
@docs pushUrl, replaceUrl, back
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
# Navigate to other Pages
|
|
19
|
-
|
|
20
|
-
@docs load, reload, reloadAndSkipCache
|
|
21
|
-
|
|
22
|
-
-}
|
|
23
|
-
|
|
24
|
-
import ProgramTest exposing (SimulatedEffect)
|
|
25
|
-
import SimulatedEffect
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
{-| Change the URL, but do not trigger a page load.
|
|
29
|
-
This will add a new entry to the browser history.
|
|
30
|
-
-}
|
|
31
|
-
pushUrl : String -> SimulatedEffect msg
|
|
32
|
-
pushUrl =
|
|
33
|
-
SimulatedEffect.PushUrl
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
{-| Change the URL, but do not trigger a page load.
|
|
37
|
-
This _will not_ add a new entry to the browser history.
|
|
38
|
-
-}
|
|
39
|
-
replaceUrl : String -> SimulatedEffect msg
|
|
40
|
-
replaceUrl =
|
|
41
|
-
SimulatedEffect.ReplaceUrl
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
{-| Go back some number of pages.
|
|
45
|
-
-}
|
|
46
|
-
back : Int -> SimulatedEffect msg
|
|
47
|
-
back =
|
|
48
|
-
SimulatedEffect.Back
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
{-| Leave the current page and load the given URL.
|
|
52
|
-
-}
|
|
53
|
-
load : String -> SimulatedEffect msg
|
|
54
|
-
load =
|
|
55
|
-
SimulatedEffect.Load
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
{-| Reload the current page.
|
|
59
|
-
-}
|
|
60
|
-
reload : SimulatedEffect msg
|
|
61
|
-
reload =
|
|
62
|
-
SimulatedEffect.Reload False
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
{-| Reload the current page without using the browser cache.
|
|
66
|
-
-}
|
|
67
|
-
reloadAndSkipCache : SimulatedEffect msg
|
|
68
|
-
reloadAndSkipCache =
|
|
69
|
-
SimulatedEffect.Reload True
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
module SimulatedEffect.Ports exposing (send, subscribe)
|
|
2
|
-
|
|
3
|
-
{-| This module provides functions that allow you to create `SimulatedEffect`s
|
|
4
|
-
that parallel [Elm ports](https://guide.elm-lang.org/interop/ports.html) used in your real program.
|
|
5
|
-
This is meant to be used
|
|
6
|
-
to help you implement the function to provide when using
|
|
7
|
-
[`ProgramTest.withSimulatedEffects`](ProgramTest#withSimulatedEffects)
|
|
8
|
-
and [`ProgramTest.withSimulatedSubscriptions`](ProgramTest#withSimulatedSubscriptions).
|
|
9
|
-
|
|
10
|
-
For a detailed example, see the [“Testing programs with ports” guidebook](https://elm-program-test.netlify.com/ports.html).
|
|
11
|
-
|
|
12
|
-
@docs send, subscribe
|
|
13
|
-
|
|
14
|
-
-}
|
|
15
|
-
|
|
16
|
-
import Json.Decode
|
|
17
|
-
import Json.Encode
|
|
18
|
-
import ProgramTest exposing (SimulatedEffect, SimulatedSub)
|
|
19
|
-
import SimulatedEffect
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
{-| Creates a `SimulatedEffect` that parallels using an outgoing Elm port.
|
|
23
|
-
|
|
24
|
-
For example, if your production code uses a port like this:
|
|
25
|
-
|
|
26
|
-
port logMessage : String -> Cmd msg
|
|
27
|
-
|
|
28
|
-
logMessage "hello"
|
|
29
|
-
|
|
30
|
-
Then the corresponding `SimulatedEffect` would be:
|
|
31
|
-
|
|
32
|
-
SimulatedEffect.Ports.send "logMessage" (Json.Encode.string "hello")
|
|
33
|
-
|
|
34
|
-
-}
|
|
35
|
-
send : String -> Json.Encode.Value -> SimulatedEffect msg
|
|
36
|
-
send =
|
|
37
|
-
SimulatedEffect.PortEffect
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
{-| Creates a `SimulatedSub` that parallels using an incoming Elm port.
|
|
41
|
-
|
|
42
|
-
For example, if your production code uses a port like this:
|
|
43
|
-
|
|
44
|
-
port activeUsers : (List String -> msg) -> Sub msg
|
|
45
|
-
|
|
46
|
-
subscriptions : Model -> Sub Msg
|
|
47
|
-
subscriptions model =
|
|
48
|
-
activeUsers OnActiveUsersLoaded
|
|
49
|
-
|
|
50
|
-
Then the corresponding `SimulatedSub` would be:
|
|
51
|
-
|
|
52
|
-
simulatedSubscriptions : Model -> SimulatedSub Msg
|
|
53
|
-
simulatedSubscriptions model =
|
|
54
|
-
SimulatedEffect.Ports.subscribe
|
|
55
|
-
"activeUsers"
|
|
56
|
-
(Json.Decode.list Json.Decode.string)
|
|
57
|
-
OnActiveUsersLoaded
|
|
58
|
-
|
|
59
|
-
-}
|
|
60
|
-
subscribe : String -> Json.Decode.Decoder a -> (a -> msg) -> SimulatedSub msg
|
|
61
|
-
subscribe portName decoder toMsg =
|
|
62
|
-
SimulatedEffect.PortSub portName (Json.Decode.map toMsg decoder)
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
module SimulatedEffect.Process exposing (sleep)
|
|
2
|
-
|
|
3
|
-
{-| This module parallels [elm/core's `Process` module](https://package.elm-lang.org/packages/elm/core/1.0.2/Process).
|
|
4
|
-
_Pull requests are welcome to add any functions that are missing._
|
|
5
|
-
|
|
6
|
-
The functions here produce `SimulatedEffect`s instead of `Cmd`s, which are meant to be used
|
|
7
|
-
to help you implement the function to provide when using [`ProgramTest.withSimulatedEffects`](ProgramTest#withSimulatedEffects).
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
# Processes
|
|
11
|
-
|
|
12
|
-
@docs sleep
|
|
13
|
-
|
|
14
|
-
-}
|
|
15
|
-
|
|
16
|
-
import ProgramTest exposing (SimulatedTask)
|
|
17
|
-
import SimulatedEffect
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
{-| Block progress on the current process for the given number of milliseconds.
|
|
21
|
-
-}
|
|
22
|
-
sleep : Float -> SimulatedTask x ()
|
|
23
|
-
sleep delay =
|
|
24
|
-
SimulatedEffect.SleepTask delay SimulatedEffect.Succeed
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
module SimulatedEffect.Sub exposing
|
|
2
|
-
( none, batch
|
|
3
|
-
, map
|
|
4
|
-
)
|
|
5
|
-
|
|
6
|
-
{-| This module parallels [elm/core's `Platform.Sub` module](https://package.elm-lang.org/packages/elm/core/1.0.2/Platform-Sub).
|
|
7
|
-
|
|
8
|
-
The functions here produce `SimulatedSub`s instead of `Sub`s, which are meant to be used
|
|
9
|
-
to help you implement the function to provide when using [`ProgramTest.withSimulatedSubscriptions`](ProgramTest#withSimulatedSubscriptions).
|
|
10
|
-
|
|
11
|
-
@docs none, batch
|
|
12
|
-
|
|
13
|
-
@docs map
|
|
14
|
-
|
|
15
|
-
-}
|
|
16
|
-
|
|
17
|
-
import Json.Decode
|
|
18
|
-
import ProgramTest exposing (SimulatedEffect, SimulatedSub)
|
|
19
|
-
import SimulatedEffect
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
{-| Tell the runtime that there are no subscriptions.
|
|
23
|
-
-}
|
|
24
|
-
none : SimulatedSub msg
|
|
25
|
-
none =
|
|
26
|
-
SimulatedEffect.NoneSub
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
{-| When you need to subscribe to multiple things, you can create a `batch` of subscriptions.
|
|
30
|
-
-}
|
|
31
|
-
batch : List (SimulatedSub msg) -> SimulatedSub msg
|
|
32
|
-
batch =
|
|
33
|
-
SimulatedEffect.BatchSub
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
{-| Transform the messages produced by a subscription.
|
|
37
|
-
-}
|
|
38
|
-
map : (a -> msg) -> SimulatedSub a -> SimulatedSub msg
|
|
39
|
-
map f effect =
|
|
40
|
-
case effect of
|
|
41
|
-
SimulatedEffect.NoneSub ->
|
|
42
|
-
SimulatedEffect.NoneSub
|
|
43
|
-
|
|
44
|
-
SimulatedEffect.BatchSub effects ->
|
|
45
|
-
SimulatedEffect.BatchSub (List.map (map f) effects)
|
|
46
|
-
|
|
47
|
-
SimulatedEffect.PortSub name decoder ->
|
|
48
|
-
SimulatedEffect.PortSub name (Json.Decode.map f decoder)
|