From 2ff031d779dba98f98cdf9a20a5b6b7f81f952c7 Mon Sep 17 00:00:00 2001 From: Aaron VonderHaar Date: Mon, 29 May 2017 21:11:39 -0700 Subject: [PATCH 1/2] elm-format-0.7.0-exp --- examples/RandomGif.elm | 2 +- examples/WebsocketChat.elm | 2 +- examples/tests/Main.elm | 4 +- examples/tests/RandomGifTests.elm | 4 +- examples/tests/Tests.elm | 2 +- examples/tests/WebsocketChatTests.elm | 2 +- src/DefaultDict.elm | 2 +- src/PairingHeap.elm | 8 +- src/Test/Http.elm | 10 +- src/Test/WebSocket.elm | 2 +- src/TestContext.elm | 14 +- src/TestContextInternal.elm | 479 +++++++++++++------------- src/TestContextWithMocks.elm | 20 +- src/Testable/EffectManager.elm | 12 +- src/Testable/Task.elm | 24 +- tests/EffectManagerTests.elm | 14 +- tests/FlagsTests.elm | 2 +- tests/HttpTests.elm | 2 +- tests/MockTaskTests.elm | 8 +- tests/ModelTests.elm | 2 +- tests/PortCmdTests.elm | 6 +- tests/PortSubTests.elm | 6 +- tests/TaskTests.elm | 4 +- tests/Test/EffectManager.elm | 8 +- tests/Testable/TaskTests.elm | 4 +- tests/Tests.elm | 2 +- tests/TimeTests.elm | 4 +- tests/ViewTests.elm | 4 +- 28 files changed, 326 insertions(+), 327 deletions(-) diff --git a/examples/RandomGif.elm b/examples/RandomGif.elm index ffcc8ae..13b344b 100644 --- a/examples/RandomGif.elm +++ b/examples/RandomGif.elm @@ -3,7 +3,7 @@ module RandomGif exposing (..) -- From section 5 of the Elm Architecture Tutorial https://github.com/evancz/elm-architecture-tutorial#example-5-random-gif-viewer import Html exposing (..) -import Html.Attributes exposing (style, src) +import Html.Attributes exposing (src, style) import Html.Events exposing (onClick) import Http import Json.Decode as Json diff --git a/examples/WebsocketChat.elm b/examples/WebsocketChat.elm index bcab4a8..b2bb893 100644 --- a/examples/WebsocketChat.elm +++ b/examples/WebsocketChat.elm @@ -1,4 +1,4 @@ -module WebsocketChat exposing (program, Msg(..)) +module WebsocketChat exposing (Msg(..), program) import Html exposing (Html) import WebSocket diff --git a/examples/tests/Main.elm b/examples/tests/Main.elm index 7d62c1a..d5c13f6 100644 --- a/examples/tests/Main.elm +++ b/examples/tests/Main.elm @@ -1,8 +1,8 @@ port module Main exposing (..) -import Tests -import Test.Runner.Node exposing (run, TestProgram) import Json.Encode exposing (Value) +import Test.Runner.Node exposing (TestProgram, run) +import Tests main : TestProgram diff --git a/examples/tests/RandomGifTests.elm b/examples/tests/RandomGifTests.elm index 09d55e4..8d15450 100644 --- a/examples/tests/RandomGifTests.elm +++ b/examples/tests/RandomGifTests.elm @@ -1,12 +1,12 @@ module RandomGifTests exposing (..) -import TestContext exposing (..) import Expect exposing (Expectation) import RandomGif import Test exposing (..) -import Test.Http import Test.Html.Query as Query import Test.Html.Selector exposing (..) +import Test.Http +import TestContext exposing (..) program : TestContext RandomGif.Model RandomGif.Msg diff --git a/examples/tests/Tests.elm b/examples/tests/Tests.elm index edf0e62..12e849e 100644 --- a/examples/tests/Tests.elm +++ b/examples/tests/Tests.elm @@ -1,7 +1,7 @@ module Tests exposing (..) -import Test exposing (..) import RandomGifTests +import Test exposing (..) import WebsocketChatTests diff --git a/examples/tests/WebsocketChatTests.elm b/examples/tests/WebsocketChatTests.elm index be43a43..79ea45a 100644 --- a/examples/tests/WebsocketChatTests.elm +++ b/examples/tests/WebsocketChatTests.elm @@ -1,8 +1,8 @@ module WebsocketChatTests exposing (all) import Test exposing (..) -import TestContext exposing (..) import Test.WebSocket +import TestContext exposing (..) import WebsocketChat exposing (Msg(..)) diff --git a/src/DefaultDict.elm b/src/DefaultDict.elm index 826f57b..2d00f23 100644 --- a/src/DefaultDict.elm +++ b/src/DefaultDict.elm @@ -1,4 +1,4 @@ -module DefaultDict exposing (DefaultDict, empty, insert, update, get, toList, toDict) +module DefaultDict exposing (DefaultDict, empty, get, insert, toDict, toList, update) import Dict exposing (Dict) diff --git a/src/PairingHeap.elm b/src/PairingHeap.elm index 0a5bc17..e7bd992 100644 --- a/src/PairingHeap.elm +++ b/src/PairingHeap.elm @@ -1,12 +1,12 @@ module PairingHeap exposing ( PairingHeap + , deleteMin , empty , findMin - , merge - , insert - , deleteMin , fromList + , insert + , merge , toSortedList ) @@ -139,4 +139,4 @@ toSortedList heap = [] Heap k v _ -> - ( k, v ) :: (toSortedList (deleteMin heap)) + ( k, v ) :: toSortedList (deleteMin heap) diff --git a/src/Test/Http.elm b/src/Test/Http.elm index 42d23fa..c08fc5b 100644 --- a/src/Test/Http.elm +++ b/src/Test/Http.elm @@ -1,18 +1,18 @@ module Test.Http exposing ( badStatus - , expectRequest , expectGet - , resolveRequest - , resolveGet + , expectRequest , rejectGet + , resolveGet + , resolveRequest ) import Dict exposing (Dict) import Expect exposing (Expectation) import Http -import Testable.Task exposing (fromPlatformTask, Task(..), ProcessId(..)) import TestContextInternal as Internal exposing (TestContext(..)) +import Testable.Task exposing (ProcessId(..), Task(..), fromPlatformTask) type alias RequestMatcher = @@ -56,7 +56,7 @@ expectRequest { method, url } = |> List.sortBy (\( a, b ) -> ( b, a )) |> List.map (\( a, b ) -> " - " ++ a ++ " " ++ b) |> String.join "\n" - |> ((++) "pending HTTP requests:\n") + |> (++) "pending HTTP requests:\n" , "╷" , "│ to include (Test.Http.expectRequest)" , "╵" diff --git a/src/Test/WebSocket.elm b/src/Test/WebSocket.elm index a0f36a9..978cb9b 100644 --- a/src/Test/WebSocket.elm +++ b/src/Test/WebSocket.elm @@ -3,8 +3,8 @@ module Test.WebSocket exposing (acceptConnection, acceptMessage) import DefaultDict import Dict import Fifo -import Testable.Task exposing (ProcessId(..)) import TestContextInternal as Internal exposing (TestContext(..)) +import Testable.Task exposing (ProcessId(..)) acceptConnection : String -> TestContext msg model -> TestContext msg model diff --git a/src/TestContext.elm b/src/TestContext.elm index 285d4f9..bdd3e89 100644 --- a/src/TestContext.elm +++ b/src/TestContext.elm @@ -1,20 +1,20 @@ module TestContext exposing ( TestContext - , start - , startWithFlags - , update - , send - , expectCmd , advanceTime + , done + , expectCmd , expectModel , expectView - , done + , send + , start + , startWithFlags + , update ) import Expect exposing (Expectation) -import TestContextInternal as Internal import Test.Html.Query +import TestContextInternal as Internal import Time exposing (Time) diff --git a/src/TestContextInternal.elm b/src/TestContextInternal.elm index cdc431e..3f48919 100644 --- a/src/TestContextInternal.elm +++ b/src/TestContextInternal.elm @@ -1,29 +1,28 @@ module TestContextInternal exposing - ( TestContext(..) - , MockTask - , toTask - , mockTask - , start - , startWithFlags - , update - , expectMockTask - , resolveMockTask - , send - , expectCmd + ( MockTask + , TestContext(..) , advanceTime - , expectModel - , expectView , done -- private to elm-testable + , drainWorkQueue , error , expect + , expectCmd + , expectMockTask + , expectModel + , expectView + , mockTask , processTask - , drainWorkQueue + , resolveMockTask + , send + , start + , startWithFlags + , toTask + , update , withContext ) -import Native.TestContext import DefaultDict exposing (DefaultDict) import Dict exposing (Dict) import Expect exposing (Expectation) @@ -32,11 +31,12 @@ import Html exposing (Html) import Http import Json.Encode import Mapper exposing (Mapper) +import Native.TestContext import PairingHeap exposing (PairingHeap) import Set exposing (Set) -import Testable.EffectManager as EffectManager exposing (EffectManager) -import Testable.Task exposing (fromPlatformTask, Task(..), ProcessId(..)) import Test.Html.Query +import Testable.EffectManager as EffectManager exposing (EffectManager) +import Testable.Task exposing (ProcessId(..), Task(..), fromPlatformTask) import Time exposing (Time) import WebSocket.LowLevel @@ -174,7 +174,7 @@ extractCmds = Task t -> { acc - | tasks = (fromPlatformTask t) :: acc.tasks + | tasks = fromPlatformTask t :: acc.tasks } done { ports, effectManagers, tasks } = @@ -183,8 +183,8 @@ extractCmds = , tasks = List.reverse tasks } in - extractBag Native.TestContext.extractCmd reduce init - >> done + extractBag Native.TestContext.extractCmd reduce init + >> done extractSubs : @@ -223,8 +223,8 @@ extractSubs = , effectManagers = Dict.map (\_ -> List.reverse) effectManagers } in - extractBag Native.TestContext.extractSub reduce init - >> done + extractBag Native.TestContext.extractSub reduce init + >> done extractSubPortName : ((value -> msg) -> Sub msg) -> String @@ -296,34 +296,34 @@ start_ flags realProgram = context (EffectManager.extractEffectManagers ()) in - TestContext - { program = program - , model = model - , outgoingPortValues = Dict.empty - , mockTasks = Dict.empty - , pendingHttpRequests = Dict.empty - , futureTasks = PairingHeap.empty - , now = 0 - , sequence = 0 - , nextProcessId = 1 - , killedProcesses = Set.empty - , processMailboxes = DefaultDict.empty Fifo.empty - , workQueue = Fifo.empty - , effectManagerStates = Dict.empty - - -- websockets - , pendingWebSocketConnections = Dict.empty - , pendingWebSocketMessages = DefaultDict.empty Fifo.empty - - -- reporting - , taskTranscript = [] - , msgTranscript = [] - } - |> initEffectManagers - |> dispatchEffects - (Tuple.second program.init) - (program.subscriptions model) - |> drainWorkQueue + TestContext + { program = program + , model = model + , outgoingPortValues = Dict.empty + , mockTasks = Dict.empty + , pendingHttpRequests = Dict.empty + , futureTasks = PairingHeap.empty + , now = 0 + , sequence = 0 + , nextProcessId = 1 + , killedProcesses = Set.empty + , processMailboxes = DefaultDict.empty Fifo.empty + , workQueue = Fifo.empty + , effectManagerStates = Dict.empty + + -- websockets + , pendingWebSocketConnections = Dict.empty + , pendingWebSocketMessages = DefaultDict.empty Fifo.empty + + -- reporting + , taskTranscript = [] + , msgTranscript = [] + } + |> initEffectManagers + |> dispatchEffects + (Tuple.second program.init) + (program.subscriptions model) + |> drainWorkQueue drainWorkQueue : TestContext model msg -> TestContext model msg @@ -375,8 +375,8 @@ processMessage home message = |> Testable.Task.mapError never |> Testable.Task.andThen (NewEffectManagerState "onSelfMsg" home) in - TestContext context - |> processTask (ProcessId 0) newStateTask + TestContext context + |> processTask (ProcessId 0) newStateTask enqueueMessage : String -> EffectManager.Message -> TestContext model msg -> TestContext model msg @@ -387,14 +387,14 @@ enqueueMessage home message = _ = debug "enqueueMessage" ( home, message ) in - TestContext - { context - | processMailboxes = - context.processMailboxes - |> DefaultDict.update home (Fifo.insert ( context.sequence, message )) - , workQueue = - Fifo.insert home context.workQueue - } + TestContext + { context + | processMailboxes = + context.processMailboxes + |> DefaultDict.update home (Fifo.insert ( context.sequence, message )) + , workQueue = + Fifo.insert home context.workQueue + } dispatchEffects : Cmd msg -> Sub msg -> TestContext model msg -> TestContext model msg @@ -428,19 +428,19 @@ dispatchEffects cmd sub = (EffectManager.extractEffectManagers ()) fxs in - TestContext - { context - | outgoingPortValues = - Dict.merge - (\home old d -> d) - (\home old new d -> Dict.insert home (old ++ new) d) - (\home new d -> Dict.insert home new d) - context.outgoingPortValues - cmds.ports - context.outgoingPortValues - } - |> applyEffects - |> flip (List.foldl (processTask (ProcessId -2))) cmds.tasks + TestContext + { context + | outgoingPortValues = + Dict.merge + (\home old d -> d) + (\home old new d -> Dict.insert home (old ++ new) d) + (\home new d -> Dict.insert home new d) + context.outgoingPortValues + cmds.ports + context.outgoingPortValues + } + |> applyEffects + |> flip (List.foldl (processTask (ProcessId -2))) cmds.tasks {-| This is a workaround for @@ -473,106 +473,106 @@ processTask pid task = , taskTranscript = ( context_.sequence + 1, task ) :: context_.taskTranscript } in - case task of - Success msg -> - TestContext context - |> update msg - - Failure x -> - never x - - IgnoredTask -> - TestContext context - - MockTask label mapper -> - TestContext - { context - | mockTasks = - context.mockTasks - |> Dict.insert label (Pending mapper) - } - - ToApp msg next -> - TestContext context - |> update (EffectManager.unwrapAppMsg msg) - |> processTask_preventTailCallOptimization pid next + case task of + Success msg -> + TestContext context + |> update msg - ToEffectManager home selfMsg next -> - TestContext context - |> enqueueMessage home (EffectManager.Self selfMsg) - |> processTask_preventTailCallOptimization pid next + Failure x -> + never x - NewEffectManagerState junk home newState -> - TestContext - { context - | effectManagerStates = Dict.insert home newState context.effectManagerStates - } - - Core_NativeScheduler_sleep delay next -> - TestContext - { context - | futureTasks = - context.futureTasks - |> PairingHeap.insert (context.now + delay) ( pid, next () ) - } + IgnoredTask -> + TestContext context - Core_NativeScheduler_spawn task next -> - let - spawnedProcessId = - ProcessId context.nextProcessId - in - TestContext { context | nextProcessId = context.nextProcessId + 1 } - -- ??? which order should these be processed in? - -- ??? ideally nothing should depened on the order, but maybe we should - -- ??? simulate the same order that the Elm runtime would result in? - |> processTask spawnedProcessId (task |> Testable.Task.map never) - |> processTask_preventTailCallOptimization pid (next spawnedProcessId) - - Core_NativeScheduler_kill (ProcessId processId) next -> - TestContext { context | killedProcesses = Set.insert processId context.killedProcesses } - |> processTask_preventTailCallOptimization pid next - - Core_Time_now next -> - TestContext context - |> processTask_preventTailCallOptimization pid (next context.now) - - Core_Time_setInterval delay recurringTask -> - let - step () = - Core_NativeScheduler_sleep delay (\() -> recurringTask) - |> Testable.Task.andThen step - |> Testable.Task.mapError never - in - TestContext context - |> processTask_preventTailCallOptimization pid (step ()) - - Http_NativeHttp_toTask options next -> - TestContext - { context - | pendingHttpRequests = - context.pendingHttpRequests - |> Dict.insert - ( options.method, options.url ) - next - } + MockTask label mapper -> + TestContext + { context + | mockTasks = + context.mockTasks + |> Dict.insert label (Pending mapper) + } - WebSocket_NativeWebSocket_open url settings next -> - TestContext - { context - | pendingWebSocketConnections = - context.pendingWebSocketConnections - |> Dict.insert url next - } + ToApp msg next -> + TestContext context + |> update (EffectManager.unwrapAppMsg msg) + |> processTask_preventTailCallOptimization pid next - WebSocket_NativeWebSocket_send url string next -> - -- TODO: verify that the connection is open - TestContext - { context - | pendingWebSocketMessages = - context.pendingWebSocketMessages - |> DefaultDict.update url (Fifo.insert string) - } - |> processTask_preventTailCallOptimization pid (next Nothing) + ToEffectManager home selfMsg next -> + TestContext context + |> enqueueMessage home (EffectManager.Self selfMsg) + |> processTask_preventTailCallOptimization pid next + + NewEffectManagerState junk home newState -> + TestContext + { context + | effectManagerStates = Dict.insert home newState context.effectManagerStates + } + + Core_NativeScheduler_sleep delay next -> + TestContext + { context + | futureTasks = + context.futureTasks + |> PairingHeap.insert (context.now + delay) ( pid, next () ) + } + + Core_NativeScheduler_spawn task next -> + let + spawnedProcessId = + ProcessId context.nextProcessId + in + TestContext { context | nextProcessId = context.nextProcessId + 1 } + -- ??? which order should these be processed in? + -- ??? ideally nothing should depened on the order, but maybe we should + -- ??? simulate the same order that the Elm runtime would result in? + |> processTask spawnedProcessId (task |> Testable.Task.map never) + |> processTask_preventTailCallOptimization pid (next spawnedProcessId) + + Core_NativeScheduler_kill (ProcessId processId) next -> + TestContext { context | killedProcesses = Set.insert processId context.killedProcesses } + |> processTask_preventTailCallOptimization pid next + + Core_Time_now next -> + TestContext context + |> processTask_preventTailCallOptimization pid (next context.now) + + Core_Time_setInterval delay recurringTask -> + let + step () = + Core_NativeScheduler_sleep delay (\() -> recurringTask) + |> Testable.Task.andThen step + |> Testable.Task.mapError never + in + TestContext context + |> processTask_preventTailCallOptimization pid (step ()) + + Http_NativeHttp_toTask options next -> + TestContext + { context + | pendingHttpRequests = + context.pendingHttpRequests + |> Dict.insert + ( options.method, options.url ) + next + } + + WebSocket_NativeWebSocket_open url settings next -> + TestContext + { context + | pendingWebSocketConnections = + context.pendingWebSocketConnections + |> Dict.insert url next + } + + WebSocket_NativeWebSocket_send url string next -> + -- TODO: verify that the connection is open + TestContext + { context + | pendingWebSocketMessages = + context.pendingWebSocketMessages + |> DefaultDict.update url (Fifo.insert string) + } + |> processTask_preventTailCallOptimization pid (next Nothing) update : msg -> TestContext model msg -> TestContext model msg @@ -589,13 +589,13 @@ update msg = newSubs = context.program.subscriptions newModel in - TestContext - { context - | model = newModel - , msgTranscript = ( context.sequence, msg ) :: context.msgTranscript - } - |> dispatchEffects newCmds newSubs - |> drainWorkQueue + TestContext + { context + | model = newModel + , msgTranscript = ( context.sequence, msg ) :: context.msgTranscript + } + |> dispatchEffects newCmds newSubs + |> drainWorkQueue getPendingTask : String -> MockTask x a -> ActiveContext model msg -> Result String (Mapper (Task Never msg)) @@ -604,36 +604,36 @@ getPendingTask fnName mock context = label = mock |> getId in - case Dict.get label context.mockTasks of - Just (Pending mapper) -> - Ok mapper - - Just (Resolved previousValue) -> - listFailure - "pending mock tasks" - "none were initiated" - (context.mockTasks |> Dict.filter (\_ -> isPending) |> Dict.keys) - (toString >> (++) "mockTask ") - ("to include (TestContext." ++ fnName ++ ")") - label - [ "but mockTask " - ++ (toString label) - ++ " was previously resolved" - ++ " with value " - ++ previousValue - ] - |> Err + case Dict.get label context.mockTasks of + Just (Pending mapper) -> + Ok mapper + + Just (Resolved previousValue) -> + listFailure + "pending mock tasks" + "none were initiated" + (context.mockTasks |> Dict.filter (\_ -> isPending) |> Dict.keys) + (toString >> (++) "mockTask ") + ("to include (TestContext." ++ fnName ++ ")") + label + [ "but mockTask " + ++ toString label + ++ " was previously resolved" + ++ " with value " + ++ previousValue + ] + |> Err - Nothing -> - listFailure - "pending mock tasks" - "none were initiated" - (context.mockTasks |> Dict.filter (\_ -> isPending) |> Dict.keys) - (toString >> (++) "mockTask ") - ("to include (TestContext." ++ fnName ++ ")") - label - [] - |> Err + Nothing -> + listFailure + "pending mock tasks" + "none were initiated" + (context.mockTasks |> Dict.filter (\_ -> isPending) |> Dict.keys) + (toString >> (++) "mockTask ") + ("to include (TestContext." ++ fnName ++ ")") + label + [] + |> Err expectMockTask : MockTask x a -> TestContext model msg -> Expectation @@ -658,7 +658,7 @@ listFailure collectionName emptyIndicator actuals view expectationName expected actuals |> List.map (view >> (++) " - ") |> String.join "\n" - |> ((++) (collectionName ++ ":\n")) + |> (++) (collectionName ++ ":\n") , "╷" , "│ " ++ expectationName , "╵" @@ -682,21 +682,22 @@ resolveMockTask mock result = label = mock |> getId in - case getPendingTask "resolveMockTask" mock context of - Err message -> - error context message - - Ok mapper -> - Mapper.apply mapper result - |> (\next -> - TestContext - { context - | mockTasks = - Dict.insert label (Resolved <| toString result) context.mockTasks - } - |> processTask (ProcessId -3) next - -- TODO: drain work queue - ) + case getPendingTask "resolveMockTask" mock context of + Err message -> + error context message + + Ok mapper -> + Mapper.apply mapper result + |> (\next -> + TestContext + { context + | mockTasks = + Dict.insert label (Resolved <| toString result) context.mockTasks + } + |> processTask (ProcessId -3) next + -- TODO: drain work queue + |> identity + ) isPortSub : TestableSub msg -> Maybe ( String, Mapper msg ) @@ -726,15 +727,15 @@ send subPort value = portName = extractSubPortName subPort in - case Dict.get portName subs |> Maybe.withDefault [] of - [] -> - error context ("Not subscribed to port: " ++ portName) + case Dict.get portName subs |> Maybe.withDefault [] of + [] -> + error context ("Not subscribed to port: " ++ portName) - mappers -> - List.foldl - (\mapper c -> Mapper.apply mapper value |> flip update c) - (TestContext context) - mappers + mappers -> + List.foldl + (\mapper c -> Mapper.apply mapper value |> flip update c) + (TestContext context) + mappers {-| If `cmd` is a batch, then this will return True only if all Cmds in the batch @@ -750,17 +751,17 @@ hasPendingCmd cmd context = actual = context.outgoingPortValues in - if Dict.isEmpty expected then - Err ("The given Cmd " ++ toString cmd ++ " is not supported by expectCmd.\n(Only Cmd ports defined in port modules are supported.)") - else - Dict.merge - (\_ exp b -> b && exp == []) - (\_ exp act b -> b && List.all (flip List.member act) exp) - (\_ act b -> b) - expected - actual - True - |> Ok + if Dict.isEmpty expected then + Err ("The given Cmd " ++ toString cmd ++ " is not supported by expectCmd.\n(Only Cmd ports defined in port modules are supported.)") + else + Dict.merge + (\_ exp b -> b && exp == []) + (\_ exp act b -> b && List.all (flip List.member act) exp) + (\_ act b -> b) + expected + actual + True + |> Ok expectCmd : Cmd msg -> TestContext model msg -> Expectation diff --git a/src/TestContextWithMocks.elm b/src/TestContextWithMocks.elm index 01832b8..84356ad 100644 --- a/src/TestContextWithMocks.elm +++ b/src/TestContextWithMocks.elm @@ -1,26 +1,26 @@ module TestContextWithMocks exposing - ( TestContext - , MockTask - , toTask + ( MockTask + , TestContext + , advanceTime + , expectCmd + , expectMockTask + , expectModel , mockTask + , resolveMockTask + , send , start , startWithFlags - , expectModel + , toTask , update - , expectMockTask - , resolveMockTask - , send - , expectCmd - , advanceTime ) {-| This is a TestContext that allows mock Tasks. You probably want to use the `TestContext` module instead unless you are really sure of what you are doing. -} -import TestContextInternal as Internal import Expect exposing (Expectation) +import TestContextInternal as Internal import Time exposing (Time) diff --git a/src/Testable/EffectManager.elm b/src/Testable/EffectManager.elm index e79252b..0bc2562 100644 --- a/src/Testable/EffectManager.elm +++ b/src/Testable/EffectManager.elm @@ -1,19 +1,19 @@ module Testable.EffectManager exposing - ( EffectManager - , SelfMsg - , AppMsg - , MySub + ( AppMsg + , EffectManager + , Message(..) , MyCmd + , MySub + , SelfMsg , State - , Message(..) , extractEffectManager , extractEffectManagers , unwrapAppMsg ) -import Native.Testable.EffectManager import Dict exposing (Dict) +import Native.Testable.EffectManager type MyCmd diff --git a/src/Testable/Task.elm b/src/Testable/Task.elm index 3d71469..34f7425 100644 --- a/src/Testable/Task.elm +++ b/src/Testable/Task.elm @@ -1,11 +1,11 @@ module Testable.Task exposing - ( fromPlatformTask + ( ProcessId(..) , Task(..) - , ProcessId(..) + , andThen + , fromPlatformTask , map , mapError - , andThen ) {-| `Testable.Task` can be generated from a elm-lang/core Task and is used @@ -23,21 +23,19 @@ internally by elm-testable to inspect and simulate Tasks. -} -import Native.Testable.Task -import Time exposing (Time) -import Task as PlatformTask import Http import Mapper exposing (Mapper) +import Native.Testable.Task +import + -- This "unused" import is required because Native.Testable.Task needs + -- it at runtime: + Process +import Task as PlatformTask import Testable.EffectManager as EffectManager +import Time exposing (Time) import WebSocket.LowLevel --- This "unused" import is required because Native.Testable.Task needs --- it at runtime: - -import Process - - fromPlatformTask : PlatformTask.Task x a -> Task x a fromPlatformTask = Native.Testable.Task.fromPlatformTask @@ -94,7 +92,7 @@ task then gets run. succeed 2 |> andThen (\n -> succeed (n + 2)) == succeed 4 This is useful for chaining tasks together. Maybe you need to get a user from -your servers *and then* lookup their picture once you know their name. +your servers _and then_ lookup their picture once you know their name. -} andThen : (a -> Task x b) -> Task x a -> Task x b diff --git a/tests/EffectManagerTests.elm b/tests/EffectManagerTests.elm index b2ba532..9201978 100644 --- a/tests/EffectManagerTests.elm +++ b/tests/EffectManagerTests.elm @@ -1,10 +1,10 @@ module EffectManagerTests exposing (all) -import Test exposing (..) import Expect import Html -import TestContext exposing (TestContext) +import Test exposing (..) import Test.EffectManager +import TestContext exposing (TestContext) program : Cmd String -> Sub String -> Program Never String String @@ -43,14 +43,14 @@ all = \() -> program (Test.EffectManager.getState identity) - (Sub.none) + Sub.none |> TestContext.start |> TestContext.expectModel (Expect.equal "INIT;(INIT)") , test "it can process a Sub" <| \() -> program - (Cmd.none) + Cmd.none (Test.EffectManager.subState identity) |> TestContext.start |> TestContext.update "PING" @@ -60,14 +60,14 @@ all = \() -> program (Cmd.map (prefix "a") <| Test.EffectManager.getState identity) - (Sub.none) + Sub.none |> TestContext.start |> TestContext.expectModel (Expect.equal "INIT;a(INIT)") , test "it works with Sub.map" <| \() -> program - (Cmd.none) + Cmd.none (Sub.map (prefix "b") <| Test.EffectManager.subState identity) |> TestContext.start |> TestContext.update "PING" @@ -77,7 +77,7 @@ all = \() -> program (Test.EffectManager.updateSelf "UP") - (Sub.none) + Sub.none |> TestContext.start |> TestContext.update "GET" |> TestContext.expectModel diff --git a/tests/FlagsTests.elm b/tests/FlagsTests.elm index 1c99651..2923e84 100644 --- a/tests/FlagsTests.elm +++ b/tests/FlagsTests.elm @@ -1,8 +1,8 @@ module FlagsTests exposing (..) -import Test exposing (..) import Expect import Html +import Test exposing (..) import TestContext exposing (TestContext) diff --git a/tests/HttpTests.elm b/tests/HttpTests.elm index 3ec91d4..4c78c6e 100644 --- a/tests/HttpTests.elm +++ b/tests/HttpTests.elm @@ -5,9 +5,9 @@ import Html import Http import Json.Decode as Decode import Test exposing (..) -import TestContext exposing (TestContext) import Test.Http import Test.Util exposing (..) +import TestContext exposing (TestContext) type LoadingMsg diff --git a/tests/MockTaskTests.elm b/tests/MockTaskTests.elm index 98deedc..4a37999 100644 --- a/tests/MockTaskTests.elm +++ b/tests/MockTaskTests.elm @@ -1,12 +1,12 @@ module MockTaskTests exposing (all) -import Test exposing (..) import Expect exposing (Expectation) import Html import Process import Task -import TestContextWithMocks as TestContext exposing (TestContext) +import Test exposing (..) import Test.Util exposing (..) +import TestContextWithMocks as TestContext exposing (TestContext) cmdProgram : @@ -65,7 +65,7 @@ all = , test "can verify that a mock task is not pending" <| \() -> cmdProgram - (Cmd.none) + Cmd.none |> TestContext.expectMockTask singleMock |> expectFailure [ "pending mock tasks (none were initiated)" @@ -186,7 +186,7 @@ all = (singleMock |> TestContext.toTask |> Process.spawn |> Task.attempt (Result.map toString)) |> TestContext.resolveMockTask singleMock (Ok "spawned task") |> TestContext.expectModel - (List.filterMap (Result.toMaybe) + (List.filterMap Result.toMaybe >> expectNotInclude "spawned task" ) ] diff --git a/tests/ModelTests.elm b/tests/ModelTests.elm index 81ac563..80ec9d8 100644 --- a/tests/ModelTests.elm +++ b/tests/ModelTests.elm @@ -1,8 +1,8 @@ module ModelTests exposing (..) -import Test exposing (..) import Expect import Html +import Test exposing (..) import TestContext exposing (TestContext) diff --git a/tests/PortCmdTests.elm b/tests/PortCmdTests.elm index 48405ac..7b609ee 100644 --- a/tests/PortCmdTests.elm +++ b/tests/PortCmdTests.elm @@ -1,11 +1,11 @@ module PortCmdTests exposing (..) -import Test exposing (..) import Expect exposing (Expectation) import Html -import TestContext exposing (TestContext) -import Test.Ports as Ports import Task +import Test exposing (..) +import Test.Ports as Ports +import TestContext exposing (TestContext) testEqual : Gen a -> String -> (a -> a -> Expectation) -> Test diff --git a/tests/PortSubTests.elm b/tests/PortSubTests.elm index 534e663..6830462 100644 --- a/tests/PortSubTests.elm +++ b/tests/PortSubTests.elm @@ -1,11 +1,11 @@ module PortSubTests exposing (..) -import Test exposing (..) import Expect exposing (Expectation) import Html -import TestContext exposing (TestContext) +import Test exposing (..) import Test.Ports as Ports import Test.Util exposing (..) +import TestContext exposing (TestContext) subProgram : Sub String -> TestContext String String @@ -42,7 +42,7 @@ all = (Expect.equal "INIT;a1") , test "gives an error when not subscribed" <| \() -> - subProgram (Sub.none) + subProgram Sub.none |> TestContext.send Ports.stringSub "VALUE" |> TestContext.expectModel (always Expect.pass) |> expectFailure [ "Not subscribed to port: stringSub" ] diff --git a/tests/TaskTests.elm b/tests/TaskTests.elm index 88d25f8..426f24e 100644 --- a/tests/TaskTests.elm +++ b/tests/TaskTests.elm @@ -1,10 +1,10 @@ module TaskTests exposing (all) -import Test exposing (..) import Expect exposing (Expectation) import Html -import TestContext exposing (TestContext) import Task +import Test exposing (..) +import TestContext exposing (TestContext) testEqual : Gen a -> String -> (a -> a -> Expectation) -> Test diff --git a/tests/Test/EffectManager.elm b/tests/Test/EffectManager.elm index 223a458..76e3346 100644 --- a/tests/Test/EffectManager.elm +++ b/tests/Test/EffectManager.elm @@ -83,10 +83,10 @@ onEffects router cmds subs state = UpdateSelf msg -> Platform.sendToSelf router msg in - cmds - |> List.map task - |> Task.sequence - |> Task.map (always state) + cmds + |> List.map task + |> Task.sequence + |> Task.map (always state) onSelfMsg : Platform.Router msg SelfMsg -> SelfMsg -> State -> Task Never State diff --git a/tests/Testable/TaskTests.elm b/tests/Testable/TaskTests.elm index 1dd379e..527b277 100644 --- a/tests/Testable/TaskTests.elm +++ b/tests/Testable/TaskTests.elm @@ -1,11 +1,11 @@ module Testable.TaskTests exposing (all) -import Test exposing (..) import Expect exposing (Expectation) +import Process import Task as PlatformTask +import Test exposing (..) import Testable.Task exposing (..) import Time exposing (Time) -import Process expectSleepTask : Time -> (Task x a -> Expectation) -> Task x a -> Expectation diff --git a/tests/Tests.elm b/tests/Tests.elm index 2807ffd..0990933 100644 --- a/tests/Tests.elm +++ b/tests/Tests.elm @@ -1,6 +1,5 @@ module Tests exposing (all) -import Test exposing (..) import EffectManagerTests import FlagsTests import HttpTests @@ -9,6 +8,7 @@ import ModelTests import PortCmdTests import PortSubTests import TaskTests +import Test exposing (..) import Testable.TaskTests import TimeTests import ViewTests diff --git a/tests/TimeTests.elm b/tests/TimeTests.elm index 112d458..26e4d15 100644 --- a/tests/TimeTests.elm +++ b/tests/TimeTests.elm @@ -1,11 +1,11 @@ module TimeTests exposing (all) -import Test exposing (..) import Expect import Html import Process -import TestContext exposing (TestContext) import Task +import Test exposing (..) +import TestContext exposing (TestContext) import Time exposing (Time) diff --git a/tests/ViewTests.elm b/tests/ViewTests.elm index 6fd8d25..792c26d 100644 --- a/tests/ViewTests.elm +++ b/tests/ViewTests.elm @@ -1,10 +1,10 @@ module ViewTests exposing (all) -import Test exposing (..) import Html -import TestContext exposing (TestContext) +import Test exposing (..) import Test.Html.Query as Query import Test.Html.Selector as Selector +import TestContext exposing (TestContext) htmlProgram : TestContext (List String) String From 86e06e8da7267259368f9a358c65d42b4d0bd8da Mon Sep 17 00:00:00 2001 From: Aaron VonderHaar Date: Mon, 29 May 2017 21:54:00 -0700 Subject: [PATCH 2/2] Upgrade to latest elm-test --- elm-package.json | 4 ++-- examples/tests/Main.elm | 13 ------------- examples/tests/elm-package.json | 7 +++---- package.json | 5 ++--- src/TestContext.elm | 2 +- src/TestContextInternal.elm | 5 +++-- tests/Main.elm | 13 ------------- tests/PortCmdTests.elm | 3 ++- tests/TaskTests.elm | 3 ++- tests/Test/Util.elm | 3 ++- tests/elm-package.json | 7 +++---- 11 files changed, 20 insertions(+), 45 deletions(-) delete mode 100644 examples/tests/Main.elm delete mode 100644 tests/Main.elm diff --git a/elm-package.json b/elm-package.json index 65925f9..3476964 100644 --- a/elm-package.json +++ b/elm-package.json @@ -10,8 +10,8 @@ "native-modules": true, "dependencies": { "avh4/elm-fifo": "1.0.3 <= v < 2.0.0", - "eeue56/elm-html-test": "1.0.1 <= v < 2.0.0", - "elm-community/elm-test": "3.1.0 <= v < 4.0.0", + "eeue56/elm-html-test": "3.1.1 <= v < 4.0.0", + "elm-community/elm-test": "4.1.0 <= v < 5.0.0", "elm-lang/core": "5.0.0 <= v < 6.0.0", "elm-lang/html": "2.0.0 <= v < 3.0.0", "elm-lang/http": "1.0.0 <= v < 2.0.0", diff --git a/examples/tests/Main.elm b/examples/tests/Main.elm deleted file mode 100644 index d5c13f6..0000000 --- a/examples/tests/Main.elm +++ /dev/null @@ -1,13 +0,0 @@ -port module Main exposing (..) - -import Json.Encode exposing (Value) -import Test.Runner.Node exposing (TestProgram, run) -import Tests - - -main : TestProgram -main = - run emit Tests.all - - -port emit : ( String, Value ) -> Cmd msg diff --git a/examples/tests/elm-package.json b/examples/tests/elm-package.json index 0e18d7d..19b0570 100644 --- a/examples/tests/elm-package.json +++ b/examples/tests/elm-package.json @@ -12,13 +12,12 @@ "native-modules": true, "dependencies": { "avh4/elm-fifo": "1.0.3 <= v < 2.0.0", - "eeue56/elm-html-test": "1.0.1 <= v < 2.0.0", - "elm-community/elm-test": "3.1.0 <= v < 4.0.0", + "eeue56/elm-html-test": "3.1.1 <= v < 4.0.0", + "elm-community/elm-test": "4.1.0 <= v < 5.0.0", "elm-lang/core": "5.1.1 <= v < 6.0.0", "elm-lang/html": "2.0.0 <= v < 3.0.0", "elm-lang/http": "1.0.0 <= v < 2.0.0", - "elm-lang/websocket": "1.0.2 <= v < 2.0.0", - "rtfeldman/node-test-runner": "3.0.0 <= v < 4.0.0" + "elm-lang/websocket": "1.0.2 <= v < 2.0.0" }, "elm-version": "0.18.0 <= v < 0.19.0" } diff --git a/package.json b/package.json index 7005648..c10661e 100644 --- a/package.json +++ b/package.json @@ -38,10 +38,9 @@ }, "devDependencies": { "elm": "^0.18.0", - "elm-test": "^0.18.2", - "standard": "*" + "elm-test": "^0.18.3" }, "scripts": { - "test": "elm-make --yes && elm-test && (cd examples && elm-make --yes RandomGif.elm && elm-test) && standard --verbose" + "test": "elm-make --yes && elm-test 'tests/**/*Tests.elm' && (cd examples && elm-make --yes RandomGif.elm && elm-test)" } } diff --git a/src/TestContext.elm b/src/TestContext.elm index bdd3e89..96a14d3 100644 --- a/src/TestContext.elm +++ b/src/TestContext.elm @@ -61,7 +61,7 @@ expectModel check context = Internal.expectModel check context -expectView : TestContext model msg -> Test.Html.Query.Single +expectView : TestContext model msg -> Test.Html.Query.Single msg expectView context = Internal.expectView context diff --git a/src/TestContextInternal.elm b/src/TestContextInternal.elm index 3f48919..9d20cae 100644 --- a/src/TestContextInternal.elm +++ b/src/TestContextInternal.elm @@ -35,6 +35,7 @@ import Native.TestContext import PairingHeap exposing (PairingHeap) import Set exposing (Set) import Test.Html.Query +import Test.Runner import Testable.EffectManager as EffectManager exposing (EffectManager) import Testable.Task exposing (ProcessId(..), Task(..), fromPlatformTask) import Time exposing (Time) @@ -839,7 +840,7 @@ expect : String -> (ActiveContext model msg -> a) -> (a -> Expectation) -> TestC expect entryName get check context_ = case context_ of TestContext context -> - case Expect.getFailure (get context |> check) of + case Test.Runner.getFailure (get context |> check) of Nothing -> Expect.pass @@ -890,7 +891,7 @@ expectModel check context = expect "TestContext.expectModel" .model check context -expectView : TestContext model msg -> Test.Html.Query.Single +expectView : TestContext model msg -> Test.Html.Query.Single msg expectView context = case context of TestContext c -> diff --git a/tests/Main.elm b/tests/Main.elm deleted file mode 100644 index 7d62c1a..0000000 --- a/tests/Main.elm +++ /dev/null @@ -1,13 +0,0 @@ -port module Main exposing (..) - -import Tests -import Test.Runner.Node exposing (run, TestProgram) -import Json.Encode exposing (Value) - - -main : TestProgram -main = - run emit Tests.all - - -port emit : ( String, Value ) -> Cmd msg diff --git a/tests/PortCmdTests.elm b/tests/PortCmdTests.elm index 7b609ee..ece4b7f 100644 --- a/tests/PortCmdTests.elm +++ b/tests/PortCmdTests.elm @@ -5,6 +5,7 @@ import Html import Task import Test exposing (..) import Test.Ports as Ports +import Test.Runner import TestContext exposing (TestContext) @@ -16,7 +17,7 @@ testEqual ( a, b ) name testCase = , Test.test "when not equal" <| \() -> testCase a b - |> Expect.getFailure + |> Test.Runner.getFailure |> Maybe.map (always True) |> Maybe.withDefault False |> Expect.true ("Expected test case to fail when inputs are different: " ++ toString ( a, b )) diff --git a/tests/TaskTests.elm b/tests/TaskTests.elm index 426f24e..b2df681 100644 --- a/tests/TaskTests.elm +++ b/tests/TaskTests.elm @@ -4,6 +4,7 @@ import Expect exposing (Expectation) import Html import Task import Test exposing (..) +import Test.Runner import TestContext exposing (TestContext) @@ -15,7 +16,7 @@ testEqual ( a, b ) name testCase = , Test.test "when not equal" <| \() -> testCase a b - |> Expect.getFailure + |> Test.Runner.getFailure |> Maybe.map (always True) |> Maybe.withDefault False |> Expect.true ("Expected test case to fail when inputs are different: " ++ toString ( a, b )) diff --git a/tests/Test/Util.elm b/tests/Test/Util.elm index d77ec02..1170a43 100644 --- a/tests/Test/Util.elm +++ b/tests/Test/Util.elm @@ -1,12 +1,13 @@ module Test.Util exposing (..) import Expect exposing (Expectation) +import Test.Runner expectFailure : List String -> Expectation -> Expectation expectFailure expectedMessage expectation = expectation - |> Expect.getFailure + |> Test.Runner.getFailure |> expectJust (.message >> expectContains (String.join "\n" expectedMessage)) diff --git a/tests/elm-package.json b/tests/elm-package.json index 5d3f6ed..99e01bc 100644 --- a/tests/elm-package.json +++ b/tests/elm-package.json @@ -11,15 +11,14 @@ "native-modules": true, "dependencies": { "avh4/elm-fifo": "1.0.3 <= v < 2.0.0", - "eeue56/elm-html-test": "1.0.1 <= v < 2.0.0", - "elm-community/elm-test": "3.0.0 <= v < 4.0.0", + "eeue56/elm-html-test": "3.1.1 <= v < 4.0.0", + "elm-community/elm-test": "4.1.0 <= v < 5.0.0", "elm-community/json-extra": "2.0.0 <= v < 3.0.0", "elm-lang/core": "5.0.0 <= v < 6.0.0", "elm-lang/html": "2.0.0 <= v < 3.0.0", "elm-lang/http": "1.0.0 <= v < 2.0.0", "elm-lang/websocket": "1.0.2 <= v < 2.0.0", - "mgold/elm-random-pcg": "4.0.2 <= v < 5.0.0", - "rtfeldman/node-test-runner": "3.0.0 <= v < 4.0.0" + "mgold/elm-random-pcg": "4.0.2 <= v < 5.0.0" }, "elm-version": "0.18.0 <= v < 0.19.0" }