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@bar:registry=http://localhost:${common.port} 17//localhost:${common.port}/:_authToken=glarb 18` 19 20function mocks (server) { 21 server.delete('/-/user/token/glarb') 22 .reply(200, {}) 23} 24 25test('setup', function (t) { 26 cleanup() 27 setup() 28 t.end() 29}) 30 31test('npm logout', function (t) { 32 mr({ port: common.port, plugin: mocks }, function (err, s) { 33 if (err) throw err 34 35 common.npm( 36 [ 37 'logout', 38 '--registry', common.registry, 39 '--scope', '@bar', 40 '--loglevel', 'silent', 41 '--userconfig', outfile 42 ], 43 opts, 44 function (err, code) { 45 t.ifError(err, 'no error output') 46 t.notOk(code, 'exited OK') 47 48 var config = fs.readFileSync(outfile, 'utf8') 49 t.equal(config.trim(), 'foo=boo', 'creds gone') 50 s.close() 51 t.end() 52 } 53 ) 54 }) 55}) 56 57test('cleanup', function (t) { 58 cleanup() 59 t.end() 60}) 61 62function setup () { 63 mkdirp.sync(pkg) 64 fs.writeFileSync(outfile, contents) 65} 66 67function cleanup () { 68 rimraf.sync(pkg) 69} 70