2022-01-14 00:13:48 +03:00
|
|
|
module SpecHook
|
|
|
|
( hook,
|
2022-06-08 19:35:44 +03:00
|
|
|
setupTestEnvironment,
|
|
|
|
teardownTestEnvironment,
|
2022-01-14 00:13:48 +03:00
|
|
|
)
|
|
|
|
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)
|
2022-04-20 20:15:42 +03:00
|
|
|
import Harness.TestEnvironment (TestEnvironment (..), 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
|
|
|
|
|
2022-04-20 20:15:42 +03:00
|
|
|
setupTestEnvironment :: IO TestEnvironment
|
|
|
|
setupTestEnvironment = do
|
2022-01-14 00:13:48 +03:00
|
|
|
murlPrefix <- lookupEnv "HASURA_TEST_URLPREFIX"
|
|
|
|
mport <- fmap (>>= readMaybe) (lookupEnv "HASURA_TEST_PORT")
|
|
|
|
server <- startServerThread ((,) <$> murlPrefix <*> mport)
|
2022-04-20 20:15:42 +03:00
|
|
|
pure $ TestEnvironment server
|
2022-01-14 00:13:48 +03:00
|
|
|
|
2022-04-20 20:15:42 +03:00
|
|
|
teardownTestEnvironment :: TestEnvironment -> IO ()
|
|
|
|
teardownTestEnvironment TestEnvironment {server} =
|
2022-01-14 00:13:48 +03:00
|
|
|
stopServer server
|
|
|
|
|
2022-04-20 20:15:42 +03:00
|
|
|
hook :: SpecWith TestEnvironment -> Spec
|
|
|
|
hook = aroundAllWith (const . bracket setupTestEnvironment teardownTestEnvironment)
|