• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1var fs = require('fs')
2var path = require('path')
3
4var mkdirp = require('mkdirp')
5var mr = require('npm-registry-mock')
6var rimraf = require('rimraf')
7var test = require('tap').test
8
9var common = require('../common-tap.js')
10
11var pkg = common.pkg
12var outfile = path.join(pkg, '_npmrc')
13var opts = { cwd: pkg }
14
15var contents = `foo=boo
16//localhost:${common.port}/:_authToken=glarb
17`
18
19function mocks (server) {
20  server.delete('/-/user/token/glarb')
21    .reply(200, {})
22}
23
24test('setup', function (t) {
25  cleanup()
26  setup()
27  t.end()
28})
29
30test('npm logout', function (t) {
31  mr({ port: common.port, plugin: mocks }, function (err, s) {
32    if (err) throw err
33
34    common.npm(
35      [
36        'logout',
37        '--registry', common.registry,
38        '--loglevel', 'silent',
39        '--userconfig', outfile
40      ],
41      opts,
42      function (err, code) {
43        t.ifError(err, 'no error output')
44        t.notOk(code, 'exited OK')
45
46        var config = fs.readFileSync(outfile, 'utf8')
47        t.notMatch(config, /localhost/, 'creds gone')
48        s.close()
49        t.end()
50      }
51    )
52  })
53})
54
55test('cleanup', function (t) {
56  cleanup()
57  t.end()
58})
59
60function setup () {
61  mkdirp.sync(pkg)
62  fs.writeFileSync(outfile, contents)
63}
64
65function cleanup () {
66  rimraf.sync(pkg)
67}
68