on master help sign in
Add extra test case for ob run
commit88ba8016cec54de4eec3d66f365258985fe9d881 authorTom Smalley <tfsmalley@gmail.com> dateFri 25 May 2018, 17:26 (8 years ago) parent15b5aeb
1 file changed+18−13
lib/selftest/src/Obelisk/SelfTest.hs+18−13
lib/selftest/src/Obelisk/SelfTest.hs+18−13
@@ -137,17 +137,22 @@ main = do
137137 unpack
138138 testThunkPack (blankProject </> thunk)
139139
140− it "can use ob run" $ inProj $ handle_sh (\case ExitSuccess -> pure (); e -> throw e) $ do
141− runHandle "ob" ["run"] $ \stdout -> do
142− (_, firstUri) <- obRun httpManager stdout
143− let newUri = "http://localhost:8080/" -- trailing slash required for comparison
144− when (firstUri == newUri) $ errorExit $
145− "Default URI (" <> firstUri <> ") is the same as test URI (" <> newUri <> ")"
146− alterRouteTo newUri stdout
147− (_, runningUri) <- obRun httpManager stdout
148− if runningUri /= newUri
149− then errorExit $ "Reloading failed: expected " <> newUri <> " but got " <> runningUri
150− else exit 0
140+ describe "ob run" $ do
141+ it "works in root directory" $ inProj $ testObRun httpManager
142+ it "works in sub directory" $ inProj $ chdir "frontend" $ testObRun httpManager
143+
144+testObRun :: HTTP.Manager -> Sh ()
145+testObRun httpManager = handle_sh (\case ExitSuccess -> pure (); e -> throw e) $ do
146+ runHandle "ob" ["run"] $ \stdout -> do
147+ (_, firstUri) <- handleObRunStdout httpManager stdout
148+ let newUri = "http://localhost:8080/" -- trailing slash required for comparison
149+ when (firstUri == newUri) $ errorExit $
150+ "Default URI (" <> firstUri <> ") is the same as test URI (" <> newUri <> ")"
151+ alterRouteTo newUri stdout
152+ (_, runningUri) <- handleObRunStdout httpManager stdout
153+ if runningUri /= newUri
154+ then errorExit $ "Reloading failed: expected " <> newUri <> " but got " <> runningUri
155+ else exit 0
151156
152157testThunkPack :: Shelly.FilePath -> Sh ()
153158testThunkPack path = withTempFile (T.unpack $ toTextIgnore path) "test-file" $ \file handle -> do
@@ -193,8 +198,8 @@ alterRouteTo uri stdout = do
193198 "Reloading failed: " <> T.pack (show t)
194199
195200-- | Handle stdout of `ob run`: check that the frontend and backend servers are started correctly
196−obRun :: HTTP.Manager -> Handle -> Sh (Text, Text)
197−obRun httpManager stdout = flip fix ObRunState_Init $ \loop state -> do
201+handleObRunStdout :: HTTP.Manager -> Handle -> Sh (Text, Text)
202+handleObRunStdout httpManager stdout = flip fix ObRunState_Init $ \loop state -> do
198203 liftIO (T.hGetLine stdout) >>= \t -> case state of
199204 ObRunState_Init
200205 | "Running test..." `T.isPrefixOf` t -> loop ObRunState_Startup