From 67e729fe24137c2050606078d35b5de4e9ff1883 Mon Sep 17 00:00:00 2001 From: John Carlo San Pedro Date: Wed, 28 Aug 2019 17:38:30 +1200 Subject: [PATCH] update to work with spec v4 --- bower.json | 2 +- src/Test/Spec/Mocha.purs | 38 +++++++++++++++++++++++--------------- 2 files changed, 24 insertions(+), 16 deletions(-) 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