• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1var fs = require('fs')
2var path = require('path')
3
4var test = require('tap').test
5var mr = require('npm-registry-mock')
6var common = require('../common-tap')
7var server
8
9var pkg = common.pkg
10
11test('setup', function (t) {
12  mr({port: common.port, throwOnUnmatched: true}, function (err, s) {
13    t.ifError(err, 'registry mocked successfully')
14    t.pass('setup done')
15    server = s
16    t.end()
17  })
18})
19
20test('unscoped packages can be explicitly set as public', function (t) {
21  server.filteringRequestBody(function (body) {
22    t.doesNotThrow(function () {
23      var parsed = JSON.parse(body)
24      t.equal(parsed.access, 'public', 'access level is correct')
25    }, 'converted body back into object')
26    return true
27  }).put('/publish-access', true).reply(201, {ok: true})
28
29  fs.writeFile(
30    path.join(pkg, 'package.json'),
31    JSON.stringify({
32      name: 'publish-access',
33      version: '1.2.5',
34      public: true
35    }),
36    'ascii',
37    function (er) {
38      t.ifError(er, 'package file written')
39      common.npm(
40        [
41          'publish',
42          '--access', 'public',
43          '--cache', common.cache,
44          '--loglevel', 'silly',
45          '--registry', common.registry
46        ],
47        {
48          cwd: pkg
49        },
50        function (er) {
51          t.ifError(er, 'published without error')
52
53          server.done()
54          t.end()
55        }
56      )
57    }
58  )
59})
60
61test('cleanup', function (t) {
62  process.chdir(__dirname)
63  server.close()
64  t.end()
65})
66