File: Streaming.hs

package info (click to toggle)
haskell-yesod-core 1.6.26.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 672 kB
  • sloc: haskell: 7,833; makefile: 5
file content (30 lines) | stat: -rw-r--r-- 764 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
{-# LANGUAGE OverloadedStrings #-}
module YesodCoreTest.Streaming (specs) where

import Yesod.Core
import Test.Hspec
import Network.Wai.Test
import Data.Text (Text)
import Data.ByteString (ByteString)

app :: LiteApp
app = liteApp $ dispatchTo $ respondSource typeHtml $ do
    sendChunk ("Hello " :: String)
    sendChunk ("World" :: ByteString)
    sendChunk ("!\n" :: Text)
    sendChunkHtml "<&>"

test :: String
     -> (SResponse -> Session ())
     -> Spec
test name f = it name $ do
    wapp <- toWaiApp app
    flip runSession wapp $ do
        sres <- request defaultRequest
        f sres

specs :: Spec
specs = describe "Streaming" $ do
    test "works" $ \sres -> do
        assertStatus 200 sres
        assertBody "Hello World!\n&lt;&amp;&gt;" sres