graphql-engine/server/tests-hspec/SpecHook.hs
Gil Mizrahi ac8f9daaa9 Use hspec-discover for hspec-tests
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3328
GitOrigin-RevId: 5f1cfc43434d971083b32e992e40f348bbf75ecd
2022-01-13 21:14:53 +00:00

27 lines
649 B
Haskell

module SpecHook
( hook,
)
where
import Control.Exception
import Harness.GraphqlEngine (startServerThread, stopServer)
import Harness.State (State (..))
import System.Environment
import Test.Hspec
import Text.Read
import Prelude
setupState :: IO State
setupState = do
murlPrefix <- lookupEnv "HASURA_TEST_URLPREFIX"
mport <- fmap (>>= readMaybe) (lookupEnv "HASURA_TEST_PORT")
server <- startServerThread ((,) <$> murlPrefix <*> mport)
pure State {server}
teardownState :: State -> IO ()
teardownState State {server} =
stopServer server
hook :: SpecWith State -> Spec
hook = aroundAllWith (const . bracket setupState teardownState)