Add a toString in the build error decoder for the test assertions.

This commit is contained in:
Dillon Kearns 2021-04-16 09:20:28 -07:00
parent d04d670669
commit fbc161c77b
2 changed files with 23 additions and 35 deletions

View File

@ -9,6 +9,7 @@ import Json.Encode
import Pages.ImagePath as ImagePath
import Pages.Manifest as Manifest
import Pages.PagePath as PagePath
import TerminalText
type ToJsPayload
@ -88,20 +89,13 @@ toJsCodec =
errorCodec : Codec (List BuildError)
errorCodec =
Codec.object (\_ _ -> [])
Codec.object (\errorString _ -> errorString)
|> Codec.field "errorString"
identity
(Codec.string
|> Codec.map
(\_ ->
[ { title = "TODO"
, message = []
, fatal = True
, path = ""
}
]
)
BuildError.errorsToString
(Codec.build (BuildError.errorsToString >> Json.Encode.string)
(Decode.string
|> Decode.map (\value -> [ { title = value, path = "Intentionally empty", message = [], fatal = False } ])
)
)
|> Codec.field "errorsJson"
identity
@ -112,23 +106,6 @@ errorCodec =
|> Codec.buildObject
stubManifest : Manifest.Config
stubManifest =
{ backgroundColor = Nothing
, categories = []
, displayMode = Manifest.Standalone
, orientation = Manifest.Portrait
, description = "elm-pages - A statically typed site generator."
, iarcRatingId = Nothing
, name = "elm-pages docs"
, themeColor = Nothing
, startUrl = PagePath.external ""
, shortName = Just "elm-pages"
, sourceIcon = ImagePath.external ""
, icons = []
}
successCodec : Codec ToJsSuccessPayload
successCodec =
Codec.object ToJsSuccessPayload

View File

@ -61,10 +61,10 @@ all =
--, StaticHttp.succeed 86
)
]
|> ProgramTest.simulateHttpOk
"GET"
"https://my-cms.com/posts"
"""{ "posts": ["post-1"] }"""
--|> ProgramTest.simulateHttpOk
-- "GET"
-- "https://my-cms.com/posts"
-- """{ "posts": ["post-1"] }"""
|> ProgramTest.simulateHttpOk
"GET"
"https://api.github.com/repos/dillonkearns/elm-pages"
@ -1008,7 +1008,8 @@ expectErrorsPort expectedPlainString actualPorts =
case actualPorts of
[ ToJsPayload.Errors actualRichTerminalString ] ->
actualRichTerminalString
|> BuildError.errorsToString
|> List.map .title
|> String.join "\n"
|> normalizeErrorExpectEqual expectedPlainString
[] ->
@ -1026,7 +1027,17 @@ normalizeErrorExpectEqual expectedPlainString actualRichTerminalString =
|> Maybe.withDefault Regex.never
)
(\_ -> "")
|> Expect.equal expectedPlainString
|> normalizeNewlines
|> Expect.equal
(expectedPlainString |> normalizeNewlines)
normalizeNewlines : String -> String
normalizeNewlines string =
string
|> Regex.replace
(Regex.fromString "(\n)+" |> Maybe.withDefault Regex.never)
(\_ -> "\n")
normalizeErrorsExpectEqual : List String -> List String -> Expect.Expectation