summaryrefslogtreecommitdiff
path: root/deps/npm/test/tap/404-private-registry-scoped.js
blob: f8a8c5b05a572165fc1768373f5ef4c98b1daa32 (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
48
49
50
51
52
53
54
55
56
57
var test = require('tap').test
var path = require('path')
var mkdirp = require('mkdirp')
var rimraf = require('rimraf')
var common = require('../common-tap.js')
var mr = common.fakeRegistry.compat
var server

var testdir = path.join(__dirname, path.basename(__filename, '.js'))

function setup () {
  cleanup()
  mkdirp.sync(testdir)
}

function cleanup () {
  rimraf.sync(testdir)
}

test('setup', function (t) {
  setup()
  mr({port: common.port, throwOnUnmatched: true}, function (err, s) {
    t.ifError(err, 'registry mocked successfully')
    server = s
    t.end()
  })
})

test('scoped package names not mangled on error with non-root registry', function (t) {
  server.get('/@scope%2ffoo').reply(404, {})
  common.npm(
    [
      '--registry=' + common.registry,
      '--cache=' + testdir,
      'cache',
      'add',
      '@scope/foo@*',
      '--force'
    ],
    {},
    function (er, code, stdout, stderr) {
      t.ifError(er, 'correctly handled 404')
      t.equal(code, 1, 'exited with error')
      t.match(stderr, /E404/, 'should notify the sort of error as a 404')
      t.match(stderr, /@scope(?:%2f|\/)foo/, 'should have package name in error')
      server.done()
      t.end()
    }
  )
})

test('cleanup', function (t) {
  server.close()
  cleanup()
  t.pass('cleaned up')
  t.end()
})