Welcome to mirror list, hosted at ThFree Co, Russian Federation.

request-gzip-content.js « test « npm-registry-client « node_modules - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2c7dcae59eacbd0a519b2b80d2eea8def70f94f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
var zlib = require('zlib')
var tap = require('tap')
var server = require('./fixtures/server.js')
var RC = require('../')
var pkg = {
  _id: 'some-package-gzip@1.2.3',
  name: 'some-package-gzip',
  version: '1.2.3'
}

zlib.gzip(JSON.stringify(pkg), function (err, pkgGzip) {
  var client = new RC({
      cache: __dirname + '/fixtures/cache'
    , 'fetch-retries': 1
    , 'fetch-retry-mintimeout': 10
    , 'fetch-retry-maxtimeout': 100
    , registry: 'http://localhost:' + server.port })

  tap.test('request gzip package content', function (t) {
    server.expect('GET', '/some-package-gzip/1.2.3', function (req, res) {
      res.statusCode = 200
      res.setHeader('Content-Encoding', 'gzip');
      res.setHeader('Content-Type', 'application/json');
      res.end(pkgGzip)
    })

    client.get('/some-package-gzip/1.2.3', function (er, data, raw, res) {
      if (er) throw er
      t.deepEqual(data, pkg)
      t.end()
    })
  })

  tap.test('request wrong gzip package content', function (t) {
    server.expect('GET', '/some-package-gzip-error/1.2.3', function (req, res) {
      res.statusCode = 200
      res.setHeader('Content-Encoding', 'gzip')
      res.setHeader('Content-Type', 'application/json')
      res.end(new Buffer('wrong gzip content'))
    })

    client.get('/some-package-gzip-error/1.2.3', function (er, data, raw, res) {
      t.ok(er)
      t.end()
    })
  })
});