update to work with spec v4

This commit is contained in:
John Carlo San Pedro 2019-08-28 17:38:30 +12:00 committed by Oskar Wickström
parent 4f5ea639e5
commit 67e729fe24
2 changed files with 24 additions and 16 deletions

View File

@ -18,6 +18,6 @@
"purescript-console": "^4.0.0", "purescript-console": "^4.0.0",
"purescript-foldable-traversable": "^4.0.0", "purescript-foldable-traversable": "^4.0.0",
"purescript-exceptions": "^4.0.0", "purescript-exceptions": "^4.0.0",
"purescript-spec": "^3.0.0" "purescript-spec": "^4.0.0"
} }
} }

View File

@ -4,11 +4,14 @@ module Test.Spec.Mocha (
) where ) where
import Prelude import Prelude
import Effect.Aff (Aff, Error, runAff_)
import Effect (Effect)
import Data.Either (either) import Data.Either (either)
import Data.Foldable (traverse_) import Data.Foldable (traverse_)
import Test.Spec (Spec, Group(..), collect) import Data.Maybe (Maybe(..))
import Effect (Effect)
import Effect.Aff (Aff, Error, runAff_)
import Test.Spec (SpecT, collect)
import Test.Spec.Tree (Item(..), Tree(..))
foreign import data MOCHA :: Type foreign import data MOCHA :: Type
@ -31,19 +34,24 @@ foreign import describe
-> Effect Unit -> Effect Unit
registerGroup registerGroup
:: Group (Aff Unit) :: ∀ m
. Tree m (Item Aff Unit)
-> Effect Unit -> Effect Unit
registerGroup (It only name test) = registerGroup tree =
itAsync only name cb case tree of
where Leaf name (Just (Item { isFocused, example })) ->
cb onSuccess onError = itAsync isFocused name cb
runAff_ (either onError (const onSuccess)) test where
registerGroup (Pending name) = itPending name cb onSuccess onError =
registerGroup (Describe only name groups) = runAff_ (either onError (const onSuccess)) (example (\a -> a unit))
describe only name (traverse_ registerGroup groups) Leaf name Nothing ->
itPending name
Node a t ->
traverse_ registerGroup t
runMocha runMocha
:: forall e :: ∀ a
. Spec Unit . SpecT Aff Unit Effect a
-> Effect Unit -> Effect Unit
runMocha spec = traverse_ registerGroup (collect spec) runMocha spec =
traverse_ registerGroup =<< collect spec