1var fs = require('fs') 2var path = require('path') 3var test = require('tap').test 4var rimraf = require('rimraf') 5var mkdirp = require('mkdirp') 6var common = require('../common-tap.js') 7 8var pkg = common.pkg 9var opts = { cwd: pkg, env: common.emptyEnv() } 10var npmrc = path.resolve(pkg, '.npmrc') 11var npmrcContents = ` 12_private=private; 13registry/:_pwd=pwd; 14foo=1234 15` 16 17test('setup', function (t) { 18 rimraf.sync(pkg) 19 mkdirp.sync(pkg) 20 21 // Write per-project conf file 22 fs.writeFileSync(npmrc, npmrcContents, 'utf8') 23 24 // Create empty package.json to indicate project root 25 fs.writeFileSync(path.resolve(pkg, 'package.json'), '{}', 'utf8') 26 t.end() 27}) 28 29test('config list includes project config', function (t) { 30 common.npm( 31 ['config', 'list'], 32 opts, 33 function (err, code, stdout, stderr) { 34 t.ifError(err) 35 t.equal(stderr, '', 'stderr is empty') 36 37 var expected = '; project config ' + npmrc + '\nfoo = "1234"' 38 t.match(stdout, expected, 'contains project config') 39 t.notMatch(stdout, '_private', 'excludes private config') 40 t.notMatch(stdout, '_pwd', 'excludes private segmented config') 41 t.end() 42 } 43 ) 44}) 45 46test('config list --json outputs json', function (t) { 47 common.npm( 48 ['config', 'list', '--json'], 49 opts, 50 function (err, code, stdout, stderr) { 51 t.ifError(err) 52 t.equal(stderr, '', 'stderr is empty') 53 54 var json = JSON.parse(stdout) 55 t.equal(json.foo, '1234', 'contains project config') 56 t.equal(json.argv, undefined, 'excludes argv') 57 t.equal(json._private, undefined, 'excludes private config') 58 t.equal(json['registry/:_pwd'], undefined, 'excludes private config') 59 t.end() 60 } 61 ) 62}) 63 64// TODO: test cases for other configuration types (cli, env, user, global) 65 66test('clean', function (t) { 67 rimraf.sync(pkg) 68 t.end() 69}) 70