]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/node_modules/npm-registry-client/test/fetch-basic.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / node_modules / npm-registry-client / test / fetch-basic.js
1 var resolve = require('path').resolve
2 var createReadStream = require('graceful-fs').createReadStream
3 var readFileSync = require('graceful-fs').readFileSync
4
5 var test = require('tap').test
6 var concat = require('concat-stream')
7
8 var server = require('./lib/server.js')
9 var common = require('./lib/common.js')
10 var client = common.freshClient()
11
12 var tgz = resolve(__dirname, './fixtures/underscore/1.3.3/package.tgz')
13
14 function nop () {}
15
16 var URI = 'https://npm.registry:8043/rewrite'
17 var USERNAME = 'username'
18 var PASSWORD = 'hi'
19 var EMAIL = 'n@p.m'
20 var HEADERS = {
21   'npm-custom': 'lolbutts'
22 }
23 var AUTH = {
24   username: USERNAME,
25   password: PASSWORD,
26   email: EMAIL
27 }
28 var PARAMS = {
29   headers: HEADERS,
30   auth: AUTH
31 }
32
33 test('fetch call contract', function (t) {
34   t.throws(function () {
35     client.get(undefined, PARAMS, nop)
36   }, 'requires a URI')
37
38   t.throws(function () {
39     client.get([], PARAMS, nop)
40   }, 'requires URI to be a string')
41
42   t.throws(function () {
43     client.get(URI, undefined, nop)
44   }, 'requires params object')
45
46   t.throws(function () {
47     client.get(URI, '', nop)
48   }, 'params must be object')
49
50   t.throws(function () {
51     client.get(URI, PARAMS, undefined)
52   }, 'requires callback')
53
54   t.throws(function () {
55     client.get(URI, PARAMS, 'callback')
56   }, 'callback must be function')
57
58   t.end()
59 })
60
61 test('basic fetch', function (t) {
62   server.expect('/underscore/-/underscore-1.3.3.tgz', function (req, res) {
63     t.equal(req.method, 'GET', 'got expected method')
64
65     res.writeHead(200, {
66       'content-type': 'application/x-tar',
67       'content-encoding': 'gzip'
68     })
69
70     createReadStream(tgz).pipe(res)
71   })
72
73   var defaulted = {}
74   client.fetch(
75     'http://localhost:1337/underscore/-/underscore-1.3.3.tgz',
76     defaulted,
77     function (er, res) {
78       t.ifError(er, 'loaded successfully')
79
80       var sink = concat(function (data) {
81         t.deepEqual(data, readFileSync(tgz))
82         server.close()
83         t.end()
84       })
85
86       res.on('error', function (error) {
87         t.ifError(error, 'no errors on stream')
88       })
89
90       res.pipe(sink)
91     }
92   )
93 })