@@ -55,41 +55,47 @@ assertEq x y = if x == y
55
55
typeIs :: forall e a . a -> Assert e Unit
56
56
typeIs = const (return unit)
57
57
58
- main = runAff throwException (const $ log " affjax: All good!" ) $ do
58
+ main = runAff (\e -> print e >>= \_ -> throwException e) (const $ log " affjax: All good!" ) $ do
59
59
let ok200 = StatusCode 200
60
60
let notFound404 = StatusCode 404
61
61
62
- A .log " GET /does-not-exists: should be 404 Not found after retries"
63
- (attempt $ retry (Just 5000 ) affjax $ defaultRequest { url = " /does-not-exist" }) >>= assertRight >>= \res -> do
62
+ -- A complete URL is necessary for tests to work on Node.js
63
+ let prefix = append " http://localhost:3838"
64
+ let mirror = prefix " /mirror"
65
+ let doesNotExist = prefix " /does-not-exist"
66
+ let notJson = prefix " /not-json"
67
+
68
+ A .log " GET /does-not-exist: should be 404 Not found after retries"
69
+ (attempt $ retry (Just 5000 ) affjax $ defaultRequest { url = doesNotExist }) >>= assertRight >>= \res -> do
64
70
typeIs (res :: AffjaxResponse String )
65
71
assertEq notFound404 res.status
66
72
67
73
A .log " GET /mirror: should be 200 OK"
68
- (attempt $ affjax $ defaultRequest { url = " / mirror" }) >>= assertRight >>= \res -> do
74
+ (attempt $ affjax $ defaultRequest { url = mirror }) >>= assertRight >>= \res -> do
69
75
typeIs (res :: AffjaxResponse Foreign )
70
76
assertEq ok200 res.status
71
77
72
78
A .log " GET /does-not-exist: should be 404 Not found"
73
- (attempt $ affjax $ defaultRequest { url = " /does-not-exist " }) >>= assertRight >>= \res -> do
79
+ (attempt $ affjax $ defaultRequest { url = doesNotExist }) >>= assertRight >>= \res -> do
74
80
typeIs (res :: AffjaxResponse String )
75
81
assertEq notFound404 res.status
76
82
77
83
A .log " GET /not-json: invalid JSON with Foreign response should throw an error"
78
- assertLeft =<< attempt (get " /not-json " :: Affjax _ Foreign )
84
+ assertLeft =<< attempt (get doesNotExist :: Affjax _ Foreign )
79
85
80
86
A .log " GET /not-json: invalid JSON with String response should be ok"
81
- (attempt $ get " /not-json " ) >>= assertRight >>= \res -> do
87
+ (attempt $ get notJson ) >>= assertRight >>= \res -> do
82
88
typeIs (res :: AffjaxResponse String )
83
89
assertEq ok200 res.status
84
90
85
91
A .log " POST /mirror: should use the POST method"
86
- (attempt $ post " / mirror" " test" ) >>= assertRight >>= \res -> do
92
+ (attempt $ post mirror " test" ) >>= assertRight >>= \res -> do
87
93
assertEq ok200 res.status
88
94
assertEq " POST" (_.method $ unsafeFromForeign res.response)
89
95
90
96
A .log " PUT with a request body"
91
97
let content = " the quick brown fox jumps over the lazy dog"
92
- (attempt $ put " / mirror" content) >>= assertRight >>= \res -> do
98
+ (attempt $ put mirror content) >>= assertRight >>= \res -> do
93
99
typeIs (res :: AffjaxResponse Foreign )
94
100
assertEq ok200 res.status
95
101
let mirroredReq = unsafeFromForeign res.response
@@ -103,6 +109,6 @@ main = runAff throwException (const $ log "affjax: All good!") $ do
103
109
-- assertEq (Just "test=test") (lookupHeader "Set-Cookie" res.headers)
104
110
105
111
A .log " Testing cancellation"
106
- canceler <- forkAff (post_ " / mirror" " do it now" )
112
+ canceler <- forkAff (post_ mirror " do it now" )
107
113
canceled <- canceler `cancel` error " Pull the cord!"
108
114
assertMsg " Should have been canceled" canceled
0 commit comments