@@ -8,7 +8,10 @@ module Servant.Client.JSaddleSpec where
8
8
9
9
import Control.Concurrent
10
10
(threadDelay )
11
- import Control.Concurrent.MVar (newEmptyMVar , putMVar , takeMVar )
11
+ import Control.Concurrent.MVar
12
+ (newEmptyMVar , putMVar , takeMVar )
13
+ import Control.Exception
14
+ (handle , throwIO )
12
15
import Control.Monad.Trans
13
16
import Data.Aeson
14
17
import Data.ByteString
@@ -28,15 +31,16 @@ import qualified Language.Javascript.JSaddle.WebSockets as WS
28
31
import qualified Network.HTTP.Types as Http
29
32
import qualified Network.Wai as Wai
30
33
import Network.Wai.Handler.Warp as Warp
31
- import qualified System.Process as P
32
34
import Network.Wai.Middleware.AddHeaders
33
35
import Network.Wai.Middleware.Cors
34
36
(simpleCors )
35
37
import Network.WebSockets
36
38
(defaultConnectionOptions )
39
+ import qualified Network.WebSockets as WS
37
40
import Servant.API
38
41
import Servant.Client.JSaddle
39
42
import Servant.Server
43
+ import qualified System.Process as P
40
44
import Test.Hspec
41
45
42
46
type TestApi = ReqBody '[OctetStream ] ByteString :> Post '[JSON ] TestResponse
@@ -104,17 +108,23 @@ spec = do
104
108
let serverApp :: IO Application
105
109
serverApp = pure $ logRequest $ addCors $ serve testApi testServer
106
110
107
- Warp. testWithApplication serverApp $ \ serverPort -> do
111
+ let handler :: WS. ConnectionException -> IO ()
112
+ handler WS. ConnectionClosed = return ()
113
+ handler e = throwIO e
114
+
115
+ handle handler $ Warp. testWithApplication serverApp $ \ serverPort -> do
116
+ threadDelay $ 500 * 1000
108
117
109
118
let clientApp :: IO Application
110
119
clientApp = WS. jsaddleOr defaultConnectionOptions (action serverPort >> Run. syncPoint) WS. jsaddleApp
111
120
112
121
Warp. testWithApplication (simpleCors <$> clientApp) $ \ clientPort -> do
122
+ threadDelay $ 500 * 1000
123
+
113
124
putStrLn $ " server http://localhost:" ++ show serverPort
114
125
putStrLn $ " client http://localhost:" ++ show clientPort
115
126
putStrLn $ " google-chrome-stable --headless --disable-gpu --screenshot http://localhost:" ++ show clientPort
116
127
117
- -- threadDelay $ 1000 * 1000 * 1000
118
128
119
129
-- Run headless chrome
120
130
-- https://docs.travis-ci.com/user/gui-and-headless-browsers/#using-the-chrome-addon-in-the-headless-mode
0 commit comments