diff options
author | Forrest L Norvell <forrest@npmjs.com> | 2015-01-23 17:51:45 -0800 |
---|---|---|
committer | Julien Gilli <julien.gilli@joyent.com> | 2015-01-27 17:41:30 -0800 |
commit | 491ac6a84365e143255cd1b75717b05dadeec219 (patch) | |
tree | 2bc373b96c183a5d403fb874a41a8045280139fc /deps/npm/node_modules/npm-registry-client/test/fetch-github-api-json.js | |
parent | e67073256d847be085be7049cd1d6ebd8d86ac62 (diff) | |
download | node-491ac6a84365e143255cd1b75717b05dadeec219.tar.gz |
deps: upgrade npm to 2.3.0
PR: #9086
PR-URL: https://github.com/joyent/node/pull/9086
Reviewed-By: Julien Gilli <julien.gilli@joyent.com>
Reviewed-By: Timothy J Fontaine <tjfontaine@gmail.com>
Diffstat (limited to 'deps/npm/node_modules/npm-registry-client/test/fetch-github-api-json.js')
-rw-r--r-- | deps/npm/node_modules/npm-registry-client/test/fetch-github-api-json.js | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/deps/npm/node_modules/npm-registry-client/test/fetch-github-api-json.js b/deps/npm/node_modules/npm-registry-client/test/fetch-github-api-json.js new file mode 100644 index 000000000..643ac9927 --- /dev/null +++ b/deps/npm/node_modules/npm-registry-client/test/fetch-github-api-json.js @@ -0,0 +1,68 @@ +var resolve = require("path").resolve +var createReadStream = require("graceful-fs").createReadStream +var readFileSync = require("graceful-fs").readFileSync + +var tap = require("tap") +var cat = require("concat-stream") +var Negotiator = require("negotiator") + +var server = require("./lib/server.js") +var common = require("./lib/common.js") + +var tgz = resolve(__dirname, "./fixtures/underscore/1.3.3/package.tgz") + +tap.test("fetch accepts github api's json", function (t) { + server.expect("/underscore/-/underscore-1.3.3", function (req, res) { + t.equal(req.method, "GET", "got expected method") + + var negotiator = new Negotiator(req) + + // fetching a tarball from `api.github.com` returns a 415 error if json is + // not accepted + if (negotiator.mediaTypes().indexOf("application/vnd.github+json") === -1) { + res.writeHead(415, { + "Content-Type" : "application/json" + }) + } + else { + res.writeHead(302, { + "Content-Type" : "text/html", + "Location" : "/underscore/-/underscore-1.3.3.tgz" + }) + } + + res.end() + }) + + server.expect("/underscore/-/underscore-1.3.3.tgz", function (req, res) { + t.equal(req.method, "GET", "got expected method") + + res.writeHead(200, { + "Content-Type" : "application/x-tar", + "Content-Encoding" : "gzip" + }) + + createReadStream(tgz).pipe(res) + }) + + var client = common.freshClient() + var defaulted = {} + client.fetch( + "http://localhost:1337/underscore/-/underscore-1.3.3", + defaulted, + function (er, res) { + t.ifError(er, "loaded successfully") + + var sink = cat(function (data) { + t.deepEqual(data, readFileSync(tgz)) + t.end() + }) + + res.on("error", function (error) { + t.ifError(error, "no errors on stream") + }) + + res.pipe(sink) + } + ) +}) |