Comments (1)
module Lib.AroundAll where
import Prelude (Unit, bind, discard, pure, void, ($), (<<<))
import Effect.Aff (Aff, Error, Fiber, forkAff, killFiber)
import Effect.Aff.Class (class MonadAff, liftAff)
import Effect.Class (class MonadEffect)
import Effect.Exception as Effect.Exception
import Effect.Aff.AVar as Effect.Aff.AVar
import Control.Monad.Error.Class (class MonadError)
import Data.Tuple (Tuple(..), fst)
import Test.Spec (SpecT, afterAll, beforeAll, beforeWith)
-- | Run a custom action before first and after last spec item.
-- | Example usage - to make a database provider for a group of tests
-- it's possible to make `withFunc` argument to have type
--
-- ((config -> g Unit) -> g Unit)
--
-- instead of
--
-- ((config -> g Unit) -> Aff Unit)
--
-- but it would require g to implement `MonadUnliftAff` class (there should be function `g Unit -> Aff Unit`)
aroundAll :: forall config m g . MonadEffect m => MonadAff g => MonadError Error g => ((config -> g Unit) -> Aff Unit) -> SpecT g config m Unit -> SpecT g Unit m Unit
aroundAll withFunc specWith = beforeAll start $ afterAll stop $ beforeWith (pure <<< fst) specWith
where
start :: g (Tuple config (Fiber Unit))
start = do
(avar :: Effect.Aff.AVar.AVar config) <- liftAff $ Effect.Aff.AVar.empty -- 1
fiber <- liftAff $ forkAff $ withFunc $ \value -> do
liftAff $ Effect.Aff.AVar.put value avar -- 2
liftAff $ void $ Effect.Aff.AVar.take avar -- 3
theConfig <- liftAff $ Effect.Aff.AVar.take avar -- 2
pure (Tuple theConfig fiber)
stop :: Tuple config (Fiber Unit) -> g Unit
stop (Tuple _config fiber) = liftAff $ killFiber (Effect.Exception.error "Kill fiber") fiber
from purescript-spec.
Related Issues (20)
- Changing timeouts is too difficult HOT 1
- Pursuit docs are not up to date HOT 2
- Add flag to run tests in randomised order
- Spec Editor integration HOT 3
- xit HOT 2
- Report output misses last `pending` in each nested `describe`? HOT 1
- itOnly still evalutates? HOT 3
- Add warning to `*Only` HOT 1
- Better reporting for diffs HOT 1
- Use an actual bracket to handle test setup/cleanup HOT 4
- `pulp test` fails on CI HOT 1
- Version 7.3.0 is not in the package set HOT 1
- beforeAll hook and Spec Identity monad HOT 10
- Fix warning in TeamCity file HOT 2
- new Tree type is a breaking api change HOT 3
- Changes in nesting of `describe` causes unexpected changes in reporting HOT 2
- Teamcity reporter overwrites nodes when there are more then one child of a describe HOT 5
- Warning when specifying the type of a Spec HOT 7
- `consoleReporter` not reporting which test that failed when running tests in `parallel` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from purescript-spec.