2022-01-14 00:13:48 +03:00
|
|
|
module SpecHook
|
|
|
|
( hook,
|
|
|
|
)
|
|
|
|
where
|
|
|
|
|
2022-02-18 16:35:32 +03:00
|
|
|
import Control.Exception.Safe (bracket)
|
2022-03-17 23:53:56 +03:00
|
|
|
import Harness.GraphqlEngine (startServerThread)
|
|
|
|
import Harness.State (State (..), stopServer)
|
2022-02-18 16:35:32 +03:00
|
|
|
import System.Environment (lookupEnv)
|
|
|
|
import Test.Hspec (Spec, SpecWith, aroundAllWith)
|
|
|
|
import Text.Read (readMaybe)
|
2022-01-14 00:13:48 +03:00
|
|
|
import Prelude
|
|
|
|
|
|
|
|
setupState :: IO State
|
|
|
|
setupState = do
|
|
|
|
murlPrefix <- lookupEnv "HASURA_TEST_URLPREFIX"
|
|
|
|
mport <- fmap (>>= readMaybe) (lookupEnv "HASURA_TEST_PORT")
|
|
|
|
server <- startServerThread ((,) <$> murlPrefix <*> mport)
|
2022-02-14 20:24:24 +03:00
|
|
|
pure $ State server
|
2022-01-14 00:13:48 +03:00
|
|
|
|
|
|
|
teardownState :: State -> IO ()
|
|
|
|
teardownState State {server} =
|
|
|
|
stopServer server
|
|
|
|
|
|
|
|
hook :: SpecWith State -> Spec
|
|
|
|
hook = aroundAllWith (const . bracket setupState teardownState)
|