summaryrefslogtreecommitdiff
path: root/deps/npm/test/tap/publish-access-scoped.js
blob: 7b9a3ecb59b9cbed4530121e055ee7d0f7582e5c (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
58
59
60
61
62
63
64
65
var fs = require('fs')
var path = require('path')

var test = require('tap').test
var mr = require('npm-registry-mock')
var common = require('../common-tap')
var server

var pkg = common.pkg

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

test('scoped packages pass public access if set', function (t) {
  server.filteringRequestBody(function (body) {
    t.doesNotThrow(function () {
      var parsed = JSON.parse(body)
      t.equal(parsed.access, 'public', 'access level is correct')
    }, 'converted body back into object')
    return true
  }).put('/@bigco%2fpublish-access', true).reply(201, {ok: true})

  fs.writeFile(
    path.join(pkg, 'package.json'),
    JSON.stringify({
      name: '@bigco/publish-access',
      version: '1.2.5',
      public: true
    }),
    'ascii',
    function (er) {
      t.ifError(er, 'package file written')
      common.npm(
        [
          'publish',
          '--access', 'public',
          '--cache', common.cache,
          '--loglevel', 'silly',
          '--registry', common.registry
        ],
        {
          cwd: pkg
        },
        function (er) {
          t.ifError(er, 'published without error')

          server.done()
          t.end()
        }
      )
    }
  )
})

test('cleanup', function (t) {
  process.chdir(__dirname)
  server.close()
  t.end()
})