/
Mocha.purs
55 lines (48 loc) · 1.21 KB
/
Mocha.purs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
module Test.Spec.Mocha (runMocha) where
import Prelude
import Data.Either (Either(..), either)
import Data.Foldable (traverse_)
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 mochaItAsync
:: Boolean
-> String
-> (Effect Unit
-> (Error -> Effect Unit)
-> Effect Unit)
-> Effect Unit
foreign import mochaPending
:: String
-> Effect Unit
foreign import mochaDescribe
:: Boolean
-> String
-> Effect Unit
-> Effect Unit
registerGroup
:: ∀ m
. Tree String m (Item Aff Unit)
-> Effect Unit
registerGroup tree =
case tree of
Leaf name (Just (Item { isFocused, example })) ->
mochaItAsync isFocused name cb
where
cb onSuccess onError =
runAff_ (either onError (const onSuccess)) (example (\a -> a unit))
Leaf name Nothing ->
mochaPending name
Node (Left a) t ->
mochaDescribe false a $
traverse_ registerGroup t
Node _ t ->
traverse_ registerGroup t
runMocha
:: ∀ a
. SpecT Aff Unit Effect a
-> Effect Unit
runMocha spec =
traverse_ registerGroup =<< collect spec