Skip to content

Commit

Permalink
Merge pull request #115 from Raynos/firefox-204-response
Browse files Browse the repository at this point in the history
Firefox 204 response
  • Loading branch information
naugtur authored Jun 17, 2016
2 parents da9b448 + 6a0a3d4 commit 6eae30a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@
"devDependencies": {
"for-each": "^0.3.2",
"pre-commit": "1.0.10",
"run-browser": "^2.0.2",
"run-browser": "naugtur/run-browser",
"tap-spec": "^4.0.2",
"tape": "^4.0.0"
},
"license": "MIT",
"scripts": {
"test": "run-browser test/index.js -b | tap-spec",
"browser": "run-browser test/index.js"
"test": "run-browser test/index.js -b -m test/mock-server.js | tap-spec",
"browser": "run-browser -m test/mock-server.js test/index.js"
}
}
12 changes: 11 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,20 @@ test("[func] Returns http error responses like npm's request (cross-domain)", fu
}
})

test("[func] Returns a falsey body for 204 responses", function(assert) {
xhr({
uri: "/mock/no-content"
}, function(err, resp, body) {
assert.notOk(body, "body should be falsey")
assert.equal(resp.statusCode, 204)
assert.end()
})
})

test("[func] Times out to an error ", function(assert) {
xhr({
timeout: 1,
uri: "/tests-bundle.js?should-take-a-bit-to-parse=1&" + (new Array(300)).join("cachebreaker=" + Math.random().toFixed(5) + "&")
uri: "/mock/timeout"
}, function(err, resp, body) {
assert.ok(err instanceof Error, "should return error")
assert.equal(err.message, "XMLHttpRequest timeout")
Expand Down
11 changes: 11 additions & 0 deletions test/mock-server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = function (req, res) {
if (req.url === '/mock/no-content') {
res.statusCode = 204
res.end('')
} else if (req.url === '/mock/timeout') {
setTimeout(function() {
res.statusCode = 200
res.end()
}, 100)
}
}

0 comments on commit 6eae30a

Please sign in to comment.