@@ -4,11 +4,14 @@ module Test.Spec.Mocha (
4
4
) where
5
5
6
6
import Prelude
7
- import Effect.Aff (Aff , Error , runAff_ )
8
- import Effect (Effect )
7
+
9
8
import Data.Either (either )
10
9
import Data.Foldable (traverse_ )
11
- import Test.Spec (Spec , Group (..), collect )
10
+ import Data.Maybe (Maybe (..))
11
+ import Effect (Effect )
12
+ import Effect.Aff (Aff , Error , runAff_ )
13
+ import Test.Spec (SpecT , collect )
14
+ import Test.Spec.Tree (Item (..), Tree (..))
12
15
13
16
foreign import data MOCHA :: Type
14
17
@@ -31,19 +34,24 @@ foreign import describe
31
34
-> Effect Unit
32
35
33
36
registerGroup
34
- :: Group (Aff Unit )
37
+ :: ∀ m
38
+ . Tree m (Item Aff Unit )
35
39
-> Effect Unit
36
- registerGroup (It only name test) =
37
- itAsync only name cb
38
- where
39
- cb onSuccess onError =
40
- runAff_ (either onError (const onSuccess)) test
41
- registerGroup (Pending name) = itPending name
42
- registerGroup (Describe only name groups) =
43
- describe only name (traverse_ registerGroup groups)
40
+ registerGroup tree =
41
+ case tree of
42
+ Leaf name (Just (Item { isFocused, example })) ->
43
+ itAsync isFocused name cb
44
+ where
45
+ cb onSuccess onError =
46
+ runAff_ (either onError (const onSuccess)) (example (\a -> a unit))
47
+ Leaf name Nothing ->
48
+ itPending name
49
+ Node a t ->
50
+ traverse_ registerGroup t
44
51
45
52
runMocha
46
- :: forall e
47
- . Spec Unit
53
+ :: ∀ a
54
+ . SpecT Aff Unit Effect a
48
55
-> Effect Unit
49
- runMocha spec = traverse_ registerGroup (collect spec)
56
+ runMocha spec =
57
+ traverse_ registerGroup =<< collect spec
0 commit comments