elm-pages 3.0.0-beta.10 → 3.0.0-beta.12
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/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateData.elmo +0 -0
- 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/elm-stuff/0.19.1/i.dat +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/o.dat +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm.json +1 -1
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Reporter.elm.js +1326 -121
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Runner.elm.js +15156 -13244
- 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/dead-code-review/elm.json +6 -5
- package/generator/dead-code-review/src/Pages/Review/DeadCodeEliminateData.elm +1 -0
- 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/elm-stuff/0.19.1/i.dat +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/o.dat +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm.json +1 -1
- package/generator/review/elm-stuff/tests-0.19.1/js/Reporter.elm.js +1326 -121
- package/generator/review/elm-stuff/tests-0.19.1/js/Runner.elm.js +14574 -12631
- 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/review/elm.json +6 -6
- package/generator/src/build.js +6 -9
- package/generator/src/cli.js +120 -42
- package/generator/src/codegen.js +11 -10
- package/generator/src/compatibility-key.js +1 -1
- package/generator/src/elm-codegen.js +3 -0
- package/generator/src/render-worker.js +1 -1
- package/generator/src/render.js +222 -37
- package/generator/src/request-cache.js +1 -0
- package/generator/src/rewrite-elm-json.js +3 -3
- package/package.json +12 -12
- package/src/ApiRoute.elm +147 -9
- package/src/DataSource/Env.elm +27 -3
- package/src/DataSource.elm +11 -22
- package/src/Form.elm +32 -32
- package/src/Head.elm +112 -8
- package/src/MultiDict.elm +49 -0
- package/src/Pages/Generate.elm +4 -1
- package/src/Pages/GeneratorProgramConfig.elm +15 -0
- package/src/Pages/Internal/Platform/CompatibilityKey.elm +1 -1
- package/src/Pages/Internal/Platform/GeneratorApplication.elm +455 -0
- package/src/Pages/Manifest.elm +24 -0
- package/src/Pages/Script.elm +100 -0
- package/src/PairingHeap.elm +137 -0
- package/src/Parser/Extra/String.elm +33 -0
- package/src/Parser/Extra.elm +69 -0
- package/src/ProgramTest/ComplexQuery.elm +360 -0
- package/src/ProgramTest/EffectSimulation.elm +122 -0
- package/src/ProgramTest/Failure.elm +367 -0
- package/src/ProgramTest/HtmlHighlighter.elm +116 -0
- package/src/ProgramTest/HtmlParserHacks.elm +58 -0
- package/src/ProgramTest/HtmlRenderer.elm +73 -0
- package/src/ProgramTest/Program.elm +30 -0
- package/src/ProgramTest/StringLines.elm +26 -0
- package/src/ProgramTest/TestHtmlHacks.elm +132 -0
- package/src/ProgramTest/TestHtmlParser.elm +201 -0
- package/src/ProgramTest.elm +2339 -0
- package/src/Query/Extra.elm +55 -0
- package/src/Result/Extra.elm +21 -0
- package/src/Server/Request.elm +2 -2
- package/src/SimulatedEffect/Cmd.elm +69 -0
- package/src/SimulatedEffect/Http.elm +330 -0
- package/src/SimulatedEffect/Navigation.elm +69 -0
- package/src/SimulatedEffect/Ports.elm +62 -0
- package/src/SimulatedEffect/Process.elm +24 -0
- package/src/SimulatedEffect/Sub.elm +48 -0
- package/src/SimulatedEffect/Task.elm +252 -0
- package/src/SimulatedEffect/Time.elm +25 -0
- package/src/SimulatedEffect.elm +42 -0
- package/src/String/Extra.elm +6 -0
- package/src/Test/Http.elm +145 -0
- package/src/TestResult.elm +35 -0
- package/src/TestState.elm +305 -0
- package/src/Url/Extra.elm +100 -0
- package/src/Vendored/Diff.elm +321 -0
- package/src/Vendored/Failure.elm +217 -0
- package/src/Vendored/FormatMonochrome.elm +44 -0
- package/src/Vendored/Highlightable.elm +53 -0
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
module SimulatedEffect.Task exposing
|
|
2
|
+
( perform, attempt
|
|
3
|
+
, andThen, succeed, fail, sequence
|
|
4
|
+
, map, map2, map3, map4, map5
|
|
5
|
+
, mapError, onError
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
{-| This module parallels [elm/core's `Task` module](https://package.elm-lang.org/packages/elm/core/1.0.2/Task).
|
|
9
|
+
_Pull requests are welcome to add any functions that are missing._
|
|
10
|
+
|
|
11
|
+
The functions here produce `SimulatedTasks`s instead of `Tasks`s
|
|
12
|
+
and `SimulatedEffect`s instead of `Cmd`s, which are meant to be used
|
|
13
|
+
to help you implement the function to provide when using [`ProgramTest.withSimulatedEffects`](ProgramTest#withSimulatedEffects).
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
# Tasks
|
|
17
|
+
|
|
18
|
+
@docs perform, attempt
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
# Chains
|
|
22
|
+
|
|
23
|
+
@docs andThen, succeed, fail, sequence
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
# Maps
|
|
27
|
+
|
|
28
|
+
@docs map, map2, map3, map4, map5
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
# Errors
|
|
32
|
+
|
|
33
|
+
@docs mapError, onError
|
|
34
|
+
|
|
35
|
+
-}
|
|
36
|
+
|
|
37
|
+
import ProgramTest exposing (SimulatedEffect, SimulatedTask)
|
|
38
|
+
import SimulatedEffect
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
{-| -}
|
|
42
|
+
perform : (a -> msg) -> SimulatedTask Never a -> SimulatedEffect msg
|
|
43
|
+
perform f task =
|
|
44
|
+
task
|
|
45
|
+
|> map f
|
|
46
|
+
|> mapError never
|
|
47
|
+
|> SimulatedEffect.Task
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
{-| This is very similar to [`perform`](#perform) except it can handle failures!
|
|
51
|
+
-}
|
|
52
|
+
attempt : (Result x a -> msg) -> SimulatedTask x a -> SimulatedEffect msg
|
|
53
|
+
attempt f task =
|
|
54
|
+
task
|
|
55
|
+
|> map (Ok >> f)
|
|
56
|
+
|> mapError (Err >> f)
|
|
57
|
+
|> SimulatedEffect.Task
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
{-| Chain together a task and a callback.
|
|
61
|
+
-}
|
|
62
|
+
andThen : (a -> SimulatedTask x b) -> SimulatedTask x a -> SimulatedTask x b
|
|
63
|
+
andThen f task =
|
|
64
|
+
case task of
|
|
65
|
+
SimulatedEffect.Succeed a ->
|
|
66
|
+
f a
|
|
67
|
+
|
|
68
|
+
SimulatedEffect.Fail x ->
|
|
69
|
+
SimulatedEffect.Fail x
|
|
70
|
+
|
|
71
|
+
SimulatedEffect.HttpTask request ->
|
|
72
|
+
SimulatedEffect.HttpTask
|
|
73
|
+
{ method = request.method
|
|
74
|
+
, url = request.url
|
|
75
|
+
, body = request.body
|
|
76
|
+
, headers = request.headers
|
|
77
|
+
, onRequestComplete = request.onRequestComplete >> andThen f
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
SimulatedEffect.SleepTask delay onResult ->
|
|
81
|
+
SimulatedEffect.SleepTask delay (onResult >> andThen f)
|
|
82
|
+
|
|
83
|
+
SimulatedEffect.NowTask onResult ->
|
|
84
|
+
SimulatedEffect.NowTask (onResult >> andThen f)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
{-| A task that succeeds immediately when run.
|
|
88
|
+
-}
|
|
89
|
+
succeed : a -> SimulatedTask x a
|
|
90
|
+
succeed =
|
|
91
|
+
SimulatedEffect.Succeed
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
{-| A task that fails immediately when run.
|
|
95
|
+
-}
|
|
96
|
+
fail : x -> SimulatedTask x a
|
|
97
|
+
fail =
|
|
98
|
+
SimulatedEffect.Fail
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
{-| Start with a list of tasks, and turn them into a single task that returns a
|
|
102
|
+
list.
|
|
103
|
+
-}
|
|
104
|
+
sequence : List (SimulatedTask x a) -> SimulatedTask x (List a)
|
|
105
|
+
sequence tasks =
|
|
106
|
+
List.foldr (map2 (::)) (succeed []) tasks
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
{-| Transform a task.
|
|
110
|
+
-}
|
|
111
|
+
map : (a -> b) -> SimulatedTask x a -> SimulatedTask x b
|
|
112
|
+
map f =
|
|
113
|
+
andThen (f >> SimulatedEffect.Succeed)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
{-| Put the results of two tasks together.
|
|
117
|
+
-}
|
|
118
|
+
map2 : (a -> b -> result) -> SimulatedTask x a -> SimulatedTask x b -> SimulatedTask x result
|
|
119
|
+
map2 func taskA taskB =
|
|
120
|
+
taskA
|
|
121
|
+
|> andThen
|
|
122
|
+
(\a ->
|
|
123
|
+
taskB
|
|
124
|
+
|> andThen (\b -> succeed (func a b))
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
{-| Put the results of three tasks together.
|
|
129
|
+
-}
|
|
130
|
+
map3 : (a -> b -> c -> result) -> SimulatedTask x a -> SimulatedTask x b -> SimulatedTask x c -> SimulatedTask x result
|
|
131
|
+
map3 func taskA taskB taskC =
|
|
132
|
+
taskA
|
|
133
|
+
|> andThen
|
|
134
|
+
(\a ->
|
|
135
|
+
taskB
|
|
136
|
+
|> andThen
|
|
137
|
+
(\b ->
|
|
138
|
+
taskC
|
|
139
|
+
|> andThen (\c -> succeed (func a b c))
|
|
140
|
+
)
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
{-| Put the results of four tasks together.
|
|
145
|
+
-}
|
|
146
|
+
map4 :
|
|
147
|
+
(a -> b -> c -> d -> result)
|
|
148
|
+
-> SimulatedTask x a
|
|
149
|
+
-> SimulatedTask x b
|
|
150
|
+
-> SimulatedTask x c
|
|
151
|
+
-> SimulatedTask x d
|
|
152
|
+
-> SimulatedTask x result
|
|
153
|
+
map4 func taskA taskB taskC taskD =
|
|
154
|
+
taskA
|
|
155
|
+
|> andThen
|
|
156
|
+
(\a ->
|
|
157
|
+
taskB
|
|
158
|
+
|> andThen
|
|
159
|
+
(\b ->
|
|
160
|
+
taskC
|
|
161
|
+
|> andThen
|
|
162
|
+
(\c ->
|
|
163
|
+
taskD
|
|
164
|
+
|> andThen (\d -> succeed (func a b c d))
|
|
165
|
+
)
|
|
166
|
+
)
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
{-| Put the results of five tasks together.
|
|
171
|
+
-}
|
|
172
|
+
map5 :
|
|
173
|
+
(a -> b -> c -> d -> e -> result)
|
|
174
|
+
-> SimulatedTask x a
|
|
175
|
+
-> SimulatedTask x b
|
|
176
|
+
-> SimulatedTask x c
|
|
177
|
+
-> SimulatedTask x d
|
|
178
|
+
-> SimulatedTask x e
|
|
179
|
+
-> SimulatedTask x result
|
|
180
|
+
map5 func taskA taskB taskC taskD taskE =
|
|
181
|
+
taskA
|
|
182
|
+
|> andThen
|
|
183
|
+
(\a ->
|
|
184
|
+
taskB
|
|
185
|
+
|> andThen
|
|
186
|
+
(\b ->
|
|
187
|
+
taskC
|
|
188
|
+
|> andThen
|
|
189
|
+
(\c ->
|
|
190
|
+
taskD
|
|
191
|
+
|> andThen
|
|
192
|
+
(\d ->
|
|
193
|
+
taskE
|
|
194
|
+
|> andThen (\e -> succeed (func a b c d e))
|
|
195
|
+
)
|
|
196
|
+
)
|
|
197
|
+
)
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
{-| Transform the error value.
|
|
202
|
+
-}
|
|
203
|
+
mapError : (x -> y) -> SimulatedTask x a -> SimulatedTask y a
|
|
204
|
+
mapError f task =
|
|
205
|
+
case task of
|
|
206
|
+
SimulatedEffect.Succeed a ->
|
|
207
|
+
SimulatedEffect.Succeed a
|
|
208
|
+
|
|
209
|
+
SimulatedEffect.Fail x ->
|
|
210
|
+
SimulatedEffect.Fail (f x)
|
|
211
|
+
|
|
212
|
+
SimulatedEffect.HttpTask request ->
|
|
213
|
+
SimulatedEffect.HttpTask
|
|
214
|
+
{ method = request.method
|
|
215
|
+
, url = request.url
|
|
216
|
+
, body = request.body
|
|
217
|
+
, headers = request.headers
|
|
218
|
+
, onRequestComplete = request.onRequestComplete >> mapError f
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
SimulatedEffect.SleepTask delay onResult ->
|
|
222
|
+
SimulatedEffect.SleepTask delay (onResult >> mapError f)
|
|
223
|
+
|
|
224
|
+
SimulatedEffect.NowTask onResult ->
|
|
225
|
+
SimulatedEffect.NowTask (onResult >> mapError f)
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
{-| Recover from a failure in a task.
|
|
229
|
+
-}
|
|
230
|
+
onError : (x -> SimulatedTask y a) -> SimulatedTask x a -> SimulatedTask y a
|
|
231
|
+
onError f task =
|
|
232
|
+
case task of
|
|
233
|
+
SimulatedEffect.Succeed a ->
|
|
234
|
+
SimulatedEffect.Succeed a
|
|
235
|
+
|
|
236
|
+
SimulatedEffect.Fail x ->
|
|
237
|
+
f x
|
|
238
|
+
|
|
239
|
+
SimulatedEffect.HttpTask request ->
|
|
240
|
+
SimulatedEffect.HttpTask
|
|
241
|
+
{ method = request.method
|
|
242
|
+
, url = request.url
|
|
243
|
+
, body = request.body
|
|
244
|
+
, headers = request.headers
|
|
245
|
+
, onRequestComplete = request.onRequestComplete >> onError f
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
SimulatedEffect.SleepTask delay onResult ->
|
|
249
|
+
SimulatedEffect.SleepTask delay (onResult >> onError f)
|
|
250
|
+
|
|
251
|
+
SimulatedEffect.NowTask onResult ->
|
|
252
|
+
SimulatedEffect.NowTask (onResult >> onError f)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module SimulatedEffect.Time exposing (now)
|
|
2
|
+
|
|
3
|
+
{-| This module parallels [elm/time's `Time` module](https://package.elm-lang.org/packages/elm/time/1.0.0/Time).
|
|
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
|
+
# Time
|
|
11
|
+
|
|
12
|
+
@docs now
|
|
13
|
+
|
|
14
|
+
-}
|
|
15
|
+
|
|
16
|
+
import ProgramTest exposing (SimulatedTask)
|
|
17
|
+
import SimulatedEffect
|
|
18
|
+
import Time
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
{-| Get the POSIX time at the moment when this task is run.
|
|
22
|
+
-}
|
|
23
|
+
now : SimulatedTask x Time.Posix
|
|
24
|
+
now =
|
|
25
|
+
SimulatedEffect.NowTask SimulatedEffect.Succeed
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
module SimulatedEffect exposing (HttpRequest, SimulatedEffect(..), SimulatedSub(..), SimulatedTask(..))
|
|
2
|
+
|
|
3
|
+
import Http
|
|
4
|
+
import Json.Decode
|
|
5
|
+
import Json.Encode
|
|
6
|
+
import Time
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
type SimulatedEffect msg
|
|
10
|
+
= None
|
|
11
|
+
| Batch (List (SimulatedEffect msg))
|
|
12
|
+
| Task (SimulatedTask msg msg)
|
|
13
|
+
| PortEffect String Json.Encode.Value
|
|
14
|
+
-- Navigation
|
|
15
|
+
| PushUrl String
|
|
16
|
+
| ReplaceUrl String
|
|
17
|
+
| Back Int
|
|
18
|
+
| Load String
|
|
19
|
+
| Reload Bool
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
type SimulatedTask x a
|
|
23
|
+
= Succeed a
|
|
24
|
+
| Fail x
|
|
25
|
+
| HttpTask (HttpRequest x a)
|
|
26
|
+
| SleepTask Float (() -> SimulatedTask x a)
|
|
27
|
+
| NowTask (Time.Posix -> SimulatedTask x a)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
type alias HttpRequest x a =
|
|
31
|
+
{ method : String
|
|
32
|
+
, url : String
|
|
33
|
+
, body : String
|
|
34
|
+
, headers : List ( String, String )
|
|
35
|
+
, onRequestComplete : Http.Response String -> SimulatedTask x a
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
type SimulatedSub msg
|
|
40
|
+
= NoneSub
|
|
41
|
+
| BatchSub (List (SimulatedSub msg))
|
|
42
|
+
| PortSub String (Json.Decode.Decoder msg)
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
module Test.Http exposing
|
|
2
|
+
( expectJsonBody, HttpRequest, hasHeader
|
|
3
|
+
, timeout, networkError, httpResponse
|
|
4
|
+
)
|
|
5
|
+
|
|
6
|
+
{-| Convenience functions for testing HTTP requests.
|
|
7
|
+
_Pull requests are welcome to add more useful functions._
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
## Expectations
|
|
11
|
+
|
|
12
|
+
These functions provide some convenient checks that can be used with [`ProgramTest.expectHttpRequest`](ProgramTest#expectHttpRequest).
|
|
13
|
+
|
|
14
|
+
@docs expectJsonBody, HttpRequest, hasHeader
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## Responses
|
|
18
|
+
|
|
19
|
+
These are ways to easily make `Http.Response` values for use with [`ProgramTest.simulateHttpResponse`](ProgramTest#simulateHttpResponse).
|
|
20
|
+
|
|
21
|
+
@docs timeout, networkError, httpResponse
|
|
22
|
+
|
|
23
|
+
-}
|
|
24
|
+
|
|
25
|
+
import Dict exposing (Dict)
|
|
26
|
+
import Expect exposing (Expectation)
|
|
27
|
+
import Http
|
|
28
|
+
import Json.Decode
|
|
29
|
+
import SimulatedEffect exposing (SimulatedTask)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
{-| -}
|
|
33
|
+
type alias HttpRequest x a =
|
|
34
|
+
{ method : String
|
|
35
|
+
, url : String
|
|
36
|
+
, body : String
|
|
37
|
+
, headers : List ( String, String )
|
|
38
|
+
, onRequestComplete : Http.Response String -> SimulatedTask x a
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
{-| A convenient way to check something about the request body of a pending HTTP request.
|
|
43
|
+
|
|
44
|
+
...
|
|
45
|
+
|> ProgramTest.expectHttpRequest "POST"
|
|
46
|
+
"https://example.com/ok"
|
|
47
|
+
(Test.Http.expectJsonBody
|
|
48
|
+
(Json.Decode.field "version" Json.Decode.string)
|
|
49
|
+
(Expect.equal "3.1.5")
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
-}
|
|
53
|
+
expectJsonBody :
|
|
54
|
+
Json.Decode.Decoder requestBody
|
|
55
|
+
-> (requestBody -> Expectation)
|
|
56
|
+
-> HttpRequest x a
|
|
57
|
+
-> Expectation
|
|
58
|
+
expectJsonBody decoder check request =
|
|
59
|
+
case Json.Decode.decodeString decoder request.body of
|
|
60
|
+
Err err ->
|
|
61
|
+
Expect.fail ("expectJsonBody: Failed to decode HTTP request body: " ++ Json.Decode.errorToString err)
|
|
62
|
+
|
|
63
|
+
Ok responseBody ->
|
|
64
|
+
check responseBody
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
{-| Assert that the given HTTP request has the specified header.
|
|
68
|
+
|
|
69
|
+
...
|
|
70
|
+
|> ProgramTest.expectHttpRequest "POST"
|
|
71
|
+
"https://example.com/ok"
|
|
72
|
+
(Test.Http.hasHeader "Content-Type" "application/json")
|
|
73
|
+
|
|
74
|
+
-}
|
|
75
|
+
hasHeader : String -> String -> HttpRequest x a -> Expectation
|
|
76
|
+
hasHeader key value { headers } =
|
|
77
|
+
let
|
|
78
|
+
key_ =
|
|
79
|
+
String.toLower key
|
|
80
|
+
|
|
81
|
+
value_ =
|
|
82
|
+
String.toLower value
|
|
83
|
+
|
|
84
|
+
matches ( k, v ) =
|
|
85
|
+
( String.toLower k, String.toLower v )
|
|
86
|
+
== ( key_, value_ )
|
|
87
|
+
in
|
|
88
|
+
if List.any matches headers then
|
|
89
|
+
Expect.pass
|
|
90
|
+
|
|
91
|
+
else
|
|
92
|
+
Expect.fail <|
|
|
93
|
+
String.join "\n"
|
|
94
|
+
[ "Expected HTTP header " ++ key ++ ": " ++ value
|
|
95
|
+
, "but got headers:"
|
|
96
|
+
, List.map (\( k, v ) -> " " ++ k ++ ": " ++ v) headers
|
|
97
|
+
|> String.join "\n"
|
|
98
|
+
]
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
{-| This is the same as `Http.Timeout_`,
|
|
102
|
+
but is exposed here so that your test doesn't need to import both `Http` and `Test.Http`.
|
|
103
|
+
-}
|
|
104
|
+
timeout : Http.Response body
|
|
105
|
+
timeout =
|
|
106
|
+
Http.Timeout_
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
{-| This is the same as `Http.NetworkError_`,
|
|
110
|
+
but is exposed here so that your test doesn't need to import both `Http` and `Test.Http`.
|
|
111
|
+
-}
|
|
112
|
+
networkError : Http.Response body
|
|
113
|
+
networkError =
|
|
114
|
+
Http.NetworkError_
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
{-| This is a more convenient way to create `Http.BadStatus_` and `Http.GoodStatus_` values.
|
|
118
|
+
|
|
119
|
+
Following the [logic in elm/http](https://github.com/elm/http/blob/2.0.0/src/Elm/Kernel/Http.js#L65),
|
|
120
|
+
this will produce `Http.GoodStatus_` if the given status code is in the 200 series, otherwise
|
|
121
|
+
it will produce `Http.BadStatus_`.
|
|
122
|
+
|
|
123
|
+
-}
|
|
124
|
+
httpResponse :
|
|
125
|
+
{ statusCode : Int
|
|
126
|
+
, headers : List ( String, String )
|
|
127
|
+
, body : body
|
|
128
|
+
}
|
|
129
|
+
-> Http.Response body
|
|
130
|
+
httpResponse response =
|
|
131
|
+
let
|
|
132
|
+
variant =
|
|
133
|
+
if response.statusCode >= 200 && response.statusCode < 300 then
|
|
134
|
+
Http.GoodStatus_
|
|
135
|
+
|
|
136
|
+
else
|
|
137
|
+
Http.BadStatus_
|
|
138
|
+
in
|
|
139
|
+
variant
|
|
140
|
+
{ url = ""
|
|
141
|
+
, statusCode = response.statusCode
|
|
142
|
+
, statusText = "TODO: if you need this, please report to https://github.com/avh4/elm-program-test/issues"
|
|
143
|
+
, headers = Dict.fromList response.headers
|
|
144
|
+
}
|
|
145
|
+
response.body
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module TestResult exposing (TestResult, andThen, fail)
|
|
2
|
+
|
|
3
|
+
import ProgramTest.Failure exposing (Failure)
|
|
4
|
+
import TestState exposing (TestState)
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
{-| TODO: what's a better name?
|
|
8
|
+
-}
|
|
9
|
+
type alias TestResult model msg effect =
|
|
10
|
+
Result
|
|
11
|
+
{ reason : Failure
|
|
12
|
+
}
|
|
13
|
+
(TestState model msg effect)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
fail : Failure -> TestState model msg effect -> TestResult model msg effect
|
|
17
|
+
fail failure state =
|
|
18
|
+
Err
|
|
19
|
+
{ reason = failure
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
andThen : (TestState model msg effect -> Result Failure (TestState model msg effect)) -> TestResult model msg effect -> TestResult model msg effect
|
|
24
|
+
andThen f testResult =
|
|
25
|
+
case testResult of
|
|
26
|
+
Ok state ->
|
|
27
|
+
case f state of
|
|
28
|
+
Err failure ->
|
|
29
|
+
fail failure state
|
|
30
|
+
|
|
31
|
+
Ok newState ->
|
|
32
|
+
Ok newState
|
|
33
|
+
|
|
34
|
+
Err _ ->
|
|
35
|
+
testResult
|