Fix compiler errors in test.

This commit is contained in:
Dillon Kearns 2021-04-16 08:04:15 -07:00
parent 20b65f5915
commit d0f3af3a1c
2 changed files with 38 additions and 82 deletions

View File

@ -1,48 +0,0 @@
module Example exposing (..)
import Expect
import Pages.Directory as Directory
import Pages.PagePath as PagePath
import Test exposing (..)
suite : Test
suite =
describe "includes"
[ test "directory with single file" <|
\() ->
quickStart
|> Directory.includes (Directory.withIndex () [ quickStart ] [ "docs" ])
|> Expect.equal True
, test "directory with two files" <|
\() ->
quickStart
|> Directory.includes (Directory.withIndex () [ performance, quickStart ] [ "docs" ])
|> Expect.equal True
, test "file in different directory" <|
\() ->
notInDocsDir
|> Directory.includes (Directory.withIndex () [ performance, quickStart, notInDocsDir ] [ "docs" ])
|> Expect.equal False
, test "index file is in the directory of the same name" <|
\() ->
docsIndex
|> Directory.includes (Directory.withIndex () [ performance, quickStart, notInDocsDir, docsIndex ] [ "docs" ])
|> Expect.equal True
]
quickStart =
PagePath.build () [ "docs", "quick-start" ]
performance =
PagePath.build () [ "docs", "performance" ]
docsIndex =
PagePath.build () [ "docs" ]
notInDocsDir =
PagePath.build () [ "notInDocsDir" ]

View File

@ -1,5 +1,6 @@
module StaticHttpRequestsTests exposing (all) module StaticHttpRequestsTests exposing (all)
import BuildError
import Codec import Codec
import Dict import Dict
import Expect import Expect
@ -15,6 +16,7 @@ import Pages.Internal.Platform.ToJsPayload as ToJsPayload exposing (ToJsPayload)
import Pages.Internal.StaticHttpBody as StaticHttpBody import Pages.Internal.StaticHttpBody as StaticHttpBody
import Pages.Manifest as Manifest import Pages.Manifest as Manifest
import Pages.PagePath as PagePath import Pages.PagePath as PagePath
import Pages.ProgramConfig exposing (ProgramConfig)
import Pages.StaticHttp as StaticHttp import Pages.StaticHttp as StaticHttp
import Pages.StaticHttp.Request as Request import Pages.StaticHttp.Request as Request
import PagesHttp import PagesHttp
@ -362,7 +364,7 @@ all =
"This is a raw text file." "This is a raw text file."
|> ProgramTest.expectOutgoingPortValues |> ProgramTest.expectOutgoingPortValues
"toJsPort" "toJsPort"
(Codec.decoder (ToJsPayload.toJsCodec canonicalSiteUrl)) (Codec.decoder ToJsPayload.toJsCodec)
(expectErrorsPort (expectErrorsPort
"""-- STATIC HTTP DECODING ERROR ----------------------------------------------------- elm-pages """-- STATIC HTTP DECODING ERROR ----------------------------------------------------- elm-pages
@ -501,7 +503,7 @@ String was not uppercased"""
"""{ "stargazer_count": 86 }""" """{ "stargazer_count": 86 }"""
|> ProgramTest.expectOutgoingPortValues |> ProgramTest.expectOutgoingPortValues
"toJsPort" "toJsPort"
(Codec.decoder (ToJsPayload.toJsCodec canonicalSiteUrl)) (Codec.decoder ToJsPayload.toJsCodec)
(expectErrorsPort (expectErrorsPort
"""-- STATIC HTTP DECODING ERROR ----------------------------------------------------- elm-pages """-- STATIC HTTP DECODING ERROR ----------------------------------------------------- elm-pages
@ -546,7 +548,7 @@ I encountered some errors while decoding this JSON:
""" "continuation-url" """ """ "continuation-url" """
|> ProgramTest.expectOutgoingPortValues |> ProgramTest.expectOutgoingPortValues
"toJsPort" "toJsPort"
(Codec.decoder (ToJsPayload.toJsCodec canonicalSiteUrl)) (Codec.decoder ToJsPayload.toJsCodec)
(expectErrorsPort (expectErrorsPort
"""-- MISSING SECRET ----------------------------------------------------- elm-pages """-- MISSING SECRET ----------------------------------------------------- elm-pages
@ -575,7 +577,7 @@ So maybe MISSING should be API_KEY"""
) )
|> ProgramTest.expectOutgoingPortValues |> ProgramTest.expectOutgoingPortValues
"toJsPort" "toJsPort"
(Codec.decoder (ToJsPayload.toJsCodec canonicalSiteUrl)) (Codec.decoder ToJsPayload.toJsCodec)
(expectErrorsPort """-- STATIC HTTP ERROR ----------------------------------------------------- elm-pages (expectErrorsPort """-- STATIC HTTP ERROR ----------------------------------------------------- elm-pages
I got an error making an HTTP request to this URL: https://api.github.com/repos/dillonkearns/elm-pages I got an error making an HTTP request to this URL: https://api.github.com/repos/dillonkearns/elm-pages
@ -794,7 +796,11 @@ Found an unhandled HTML tag in markdown doc."""
] ]
start : List ( List String, StaticHttp.Request a ) -> ProgramTest (Model PathKey String) Msg (Effect PathKey) type Route
= Route String
start : List ( List String, StaticHttp.Request a ) -> ProgramTest (Model Route) Msg Effect
start pages = start pages =
startWithHttpCache (Ok ()) [] pages startWithHttpCache (Ok ()) [] pages
@ -803,7 +809,7 @@ startWithHttpCache :
Result String () Result String ()
-> List ( Request.Request, String ) -> List ( Request.Request, String )
-> List ( List String, StaticHttp.Request a ) -> List ( List String, StaticHttp.Request a )
-> ProgramTest (Model PathKey String) Msg (Effect PathKey) -> ProgramTest (Model Route) Msg Effect
startWithHttpCache = startWithHttpCache =
startLowLevel (StaticHttp.succeed []) startLowLevel (StaticHttp.succeed [])
@ -821,34 +827,34 @@ startLowLevel :
-> Result String () -> Result String ()
-> List ( Request.Request, String ) -> List ( Request.Request, String )
-> List ( List String, StaticHttp.Request a ) -> List ( List String, StaticHttp.Request a )
-> ProgramTest (Model PathKey String) Msg (Effect PathKey) -> ProgramTest (Model Route) Msg Effect
startLowLevel generateFiles documentBodyResult staticHttpCache pages = startLowLevel generateFiles documentBodyResult staticHttpCache pages =
let let
contentCache = contentCache =
ContentCache.init Nothing ContentCache.init Nothing
--config : { toJsPort : a -> Cmd msg, fromJsPort : Sub b, manifest : Manifest.Config PathKey, generateFiles : StaticHttp.Request (List (Result String { path : List String, content : String })), init : c -> ((), Cmd d), urlToRoute : { e | path : f } -> f, update : g -> h -> ((), Cmd i), view : j -> { k | path : PagePath.PagePath key } -> StaticHttp.Request { view : l -> m -> { title : String, body : Html.Html n }, head : List o }, subscriptions : p -> q -> r -> Sub s, canonicalSiteUrl : String, pathKey : PathKey, onPageChange : Maybe (t -> ()) } config : ProgramConfig Msg () Route () () ()
config : Config PathKey Msg () String ()
config = config =
{ toJsPort = toJsPort { toJsPort = toJsPort
, fromJsPort = fromJsPort , fromJsPort = fromJsPort
, manifest = manifest
, generateFiles = generateFiles , generateFiles = generateFiles
, init = \_ -> ( (), Cmd.none ) , init = \_ _ _ -> ( (), Cmd.none )
, getStaticRoutes = , getStaticRoutes =
StaticHttp.get (Secrets.succeed "https://my-cms.com/posts") StaticHttp.get (Secrets.succeed "https://my-cms.com/posts")
(Decode.field "posts" (Decode.list Decode.string)) (Decode.field "posts" (Decode.list (Decode.string |> Decode.map Route)))
, urlToRoute = .path , urlToRoute = .path >> Route
, update = \_ _ -> ( (), Cmd.none ) , update = \_ _ _ _ -> ( (), Cmd.none )
, staticData = \route -> StaticHttp.succeed ()
, site = , site =
\routes ->
{ staticData = StaticHttp.succeed () { staticData = StaticHttp.succeed ()
, canonicalUrl = \_ -> "canonical-site-url" , canonicalUrl = \_ -> "canonical-site-url"
, manifest = \_ -> manifest , manifest = \_ -> manifest
, head = \_ -> [] , head = \_ -> []
, generateFiles = StaticHttp.succeed [] , generateFiles = generateFiles
} }
, view = , view =
\_ page -> \page ->
let let
thing = thing =
pages pages
@ -872,8 +878,8 @@ startLowLevel generateFiles documentBodyResult staticHttpCache pages =
Debug.todo <| "Couldn't find page: " ++ Debug.toString page ++ "\npages: " ++ Debug.toString pages Debug.todo <| "Couldn't find page: " ++ Debug.toString page ++ "\npages: " ++ Debug.toString pages
, subscriptions = \_ _ _ -> Sub.none , subscriptions = \_ _ _ -> Sub.none
, canonicalSiteUrl = canonicalSiteUrl , canonicalSiteUrl = canonicalSiteUrl
, pathKey = PathKey , routeToPath = \(Route route) -> route |> String.split "/"
, routeToPath = \route -> route |> String.split "/" , sharedStaticData = StaticHttp.succeed ()
--, onPageChange = Just (\_ -> ()) --, onPageChange = Just (\_ -> ())
, onPageChange = Nothing , onPageChange = Nothing
@ -930,14 +936,14 @@ flags jsonString =
Debug.todo "Invalid JSON value." Debug.todo "Invalid JSON value."
simulateEffects : Effect PathKey -> ProgramTest.SimulatedEffect Msg simulateEffects : Effect -> ProgramTest.SimulatedEffect Msg
simulateEffects effect = simulateEffects effect =
case effect of case effect of
Effect.NoEffect -> Effect.NoEffect ->
SimulatedEffect.Cmd.none SimulatedEffect.Cmd.none
Effect.SendJsData value -> Effect.SendJsData value ->
SimulatedEffect.Ports.send "toJsPort" (value |> Codec.encoder (ToJsPayload.toJsCodec canonicalSiteUrl)) SimulatedEffect.Ports.send "toJsPort" (value |> Codec.encoder ToJsPayload.toJsCodec)
-- toJsPort value |> Cmd.map never -- toJsPort value |> Cmd.map never
Effect.Batch list -> Effect.Batch list ->
@ -993,11 +999,12 @@ simulateEffects effect =
SimulatedEffect.Cmd.none SimulatedEffect.Cmd.none
expectErrorsPort : String -> List (ToJsPayload pathKey) -> Expect.Expectation expectErrorsPort : String -> List ToJsPayload -> Expect.Expectation
expectErrorsPort expectedPlainString actualPorts = expectErrorsPort expectedPlainString actualPorts =
case actualPorts of case actualPorts of
[ ToJsPayload.Errors actualRichTerminalString ] -> [ ToJsPayload.Errors actualRichTerminalString ] ->
actualRichTerminalString actualRichTerminalString
|> BuildError.errorsToString
|> normalizeErrorExpectEqual expectedPlainString |> normalizeErrorExpectEqual expectedPlainString
[] -> [] ->
@ -1039,11 +1046,7 @@ fromJsPort =
Sub.none Sub.none
type PathKey manifest : Manifest.Config
= PathKey
manifest : Manifest.Config PathKey
manifest = manifest =
{ backgroundColor = Nothing { backgroundColor = Nothing
, categories = [] , categories = []
@ -1070,12 +1073,12 @@ expectSuccess expectedRequests previous =
expectSuccessNew expectedRequests [] previous expectSuccessNew expectedRequests [] previous
expectSuccessNew : List ( String, List ( Request.Request, String ) ) -> List (ToJsPayload.ToJsSuccessPayload PathKey -> Expect.Expectation) -> ProgramTest model msg effect -> Expect.Expectation expectSuccessNew : List ( String, List ( Request.Request, String ) ) -> List (ToJsPayload.ToJsSuccessPayload -> Expect.Expectation) -> ProgramTest model msg effect -> Expect.Expectation
expectSuccessNew expectedRequests expectations previous = expectSuccessNew expectedRequests expectations previous =
previous previous
|> ProgramTest.expectOutgoingPortValues |> ProgramTest.expectOutgoingPortValues
"toJsPort" "toJsPort"
(Codec.decoder (ToJsPayload.toJsCodec canonicalSiteUrl)) (Codec.decoder ToJsPayload.toJsCodec)
(\value -> (\value ->
case value of case value of
(ToJsPayload.Success portPayload) :: _ -> (ToJsPayload.Success portPayload) :: _ ->
@ -1115,11 +1118,12 @@ expectError expectedErrors previous =
previous previous
|> ProgramTest.expectOutgoingPortValues |> ProgramTest.expectOutgoingPortValues
"toJsPort" "toJsPort"
(Codec.decoder (ToJsPayload.toJsCodec canonicalSiteUrl)) (Codec.decoder ToJsPayload.toJsCodec)
(\value -> (\value ->
case value of case value of
[ ToJsPayload.Success portPayload ] -> [ ToJsPayload.Success portPayload ] ->
portPayload.errors portPayload.errors
|> List.map BuildError.errorToString
|> normalizeErrorsExpectEqual expectedErrors |> normalizeErrorsExpectEqual expectedErrors
[ _ ] -> [ _ ] ->