Skip to content

Updates for ps-0.12.0 #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@
"output"
],
"dependencies": {
"purescript-prelude": "^3.0.0",
"purescript-console": "^3.0.0",
"purescript-hyper": "^0.7.3"
"purescript-hyper": "httsp://github.com/lambdaterms-forks/hyper.git#33edf95c4e1db5a6f798e66199fad9b5643e0064"
},
"devDependencies": {
"purescript-psci-support": "^3.0.0",
"purescript-spec": "^0.14.0",
"purescript-spec-discovery": "^0.6.0"
"purescript-psci-support": "^4.0.0",
"purescript-spec": "^3.0.0",
"purescript-spec-discovery": "https://github.com/owickstrom/purescript-spec-discovery.git#a1a8dfd5fadb3f00199d68d20af4bbf56a048c6e"
}
}
14 changes: 7 additions & 7 deletions src/Hyper/Drive.purs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ module Hyper.Drive ( Request(..)
) where

import Prelude
import Data.StrMap as StrMap
import Control.IxMonad (ibind)
import Data.Bifunctor (class Bifunctor)
import Data.Either (Either)
import Data.HTTP.Method (CustomMethod, Method)
import Data.Newtype (class Newtype)
import Data.StrMap (StrMap)
import Data.Tuple (Tuple(..), curry)
import Foreign.Object as Object
import Foreign.Object (Object)
import Hyper.Conn (Conn)
import Hyper.Header (Header)
import Hyper.Middleware (Middleware, lift')
Expand All @@ -28,14 +28,14 @@ import Hyper.Status (Status, statusOK)
newtype Request body components =
Request { method :: Either Method CustomMethod
, url :: String
, headers :: StrMap String
, headers :: Object String
, body :: body
, components :: components
}

newtype Response body =
Response { status :: Status
, headers :: StrMap String
, headers :: Object String
, body :: body
}

Expand Down Expand Up @@ -78,7 +78,7 @@ hyperdrive app = do
}
Response res <- lift' (app req)
writeStatus res.status
StrMap.foldM (const (curry writeHeader)) unit res.headers
Object.foldM (const (curry writeHeader)) unit res.headers
closeHeaders
toResponse res.body >>= send
end
Expand All @@ -94,7 +94,7 @@ response
response b =
Response
{ status: statusOK
, headers: StrMap.empty
, headers: Object.empty
, body: b
}

Expand All @@ -112,7 +112,7 @@ header
-> Response body
-> Response body
header (Tuple k v) (Response res) =
Response (res { headers = StrMap.insert k v res.headers })
Response (res { headers = Object.insert k v res.headers })

body
:: forall a body
Expand Down
6 changes: 3 additions & 3 deletions test/Hyper/DriveSpec.purs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
module Hyper.DriveSpec where

import Prelude
import Data.StrMap as StrMap
import Data.Maybe (Maybe(..))
import Data.Monoid (mempty)
import Data.Newtype (unwrap)
import Data.Tuple (Tuple(..))
import Foreign.Object as Object
import Hyper.Drive (Response(..), hyperdrive)
import Hyper.Middleware (evalMiddleware)
import Hyper.Status (statusNotFound, statusOK)
import Hyper.Test.TestServer (TestRequest(..), TestResponse(..), defaultRequest, testHeaders, testServer, testStatus, testStringBody)
import Test.Spec (Spec, describe, it)
import Test.Spec.Assertions (shouldContain, shouldEqual)

spec :: Spec () Unit
spec :: Spec Unit
spec = do
let runHyperdrive app =
{ request: TestRequest $ defaultRequest { body = "Bonjour" }
Expand All @@ -35,7 +35,7 @@ spec = do

it "responds with the supplied headers" do
conn <- runHyperdrive (const $ pure $ Response { status: statusOK
, headers: StrMap.singleton "foo" "bar"
, headers: Object.singleton "foo" "bar"
, body: mempty
})
testHeaders conn `shouldContain` Tuple "foo" "bar"
Expand Down
7 changes: 3 additions & 4 deletions test/Main.purs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
module Test.Main where

import Prelude
import Control.Monad.Eff (Eff)
import Node.FS (FS)
import Effect (Effect)
import Test.Spec.Discovery (discover)
import Test.Spec.Reporter.Console (consoleReporter)
import Test.Spec.Runner (RunnerEffects, run)
import Test.Spec.Runner (run)

main :: Eff (RunnerEffects (fs :: FS)) Unit
main :: Effect Unit
main = discover "Hyper\\..*Spec" >>= run [consoleReporter]