diff --git a/bower.json b/bower.json index f1482da..3b14e33 100644 --- a/bower.json +++ b/bower.json @@ -18,6 +18,6 @@ "purescript-console": "^4.0.0", "purescript-foldable-traversable": "^4.0.0", "purescript-exceptions": "^4.0.0", - "purescript-spec": "^3.0.0" + "purescript-spec": "^4.0.0" } } diff --git a/src/Test/Spec/Mocha.purs b/src/Test/Spec/Mocha.purs index 26a1215..191ac73 100644 --- a/src/Test/Spec/Mocha.purs +++ b/src/Test/Spec/Mocha.purs @@ -4,11 +4,14 @@ module Test.Spec.Mocha ( ) where import Prelude -import Effect.Aff (Aff, Error, runAff_) -import Effect (Effect) + import Data.Either (either) 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 @@ -31,19 +34,24 @@ foreign import describe -> Effect Unit registerGroup - :: Group (Aff Unit) + :: ∀ m + . Tree m (Item Aff Unit) -> Effect Unit -registerGroup (It only name test) = - itAsync only name cb - where - cb onSuccess onError = - runAff_ (either onError (const onSuccess)) test -registerGroup (Pending name) = itPending name -registerGroup (Describe only name groups) = - describe only name (traverse_ registerGroup groups) +registerGroup tree = + case tree of + Leaf name (Just (Item { isFocused, example })) -> + itAsync isFocused name cb + where + cb onSuccess onError = + runAff_ (either onError (const onSuccess)) (example (\a -> a unit)) + Leaf name Nothing -> + itPending name + Node a t -> + traverse_ registerGroup t runMocha - :: forall e - . Spec Unit + :: ∀ a + . SpecT Aff Unit Effect a -> Effect Unit -runMocha spec = traverse_ registerGroup (collect spec) +runMocha spec = + traverse_ registerGroup =<< collect spec