1var common = require('../common-tap.js') 2var test = require('tap').test 3var npm = require('../../') 4var rimraf = require('rimraf') 5var path = require('path') 6var mr = require('npm-registry-mock') 7var osenv = require('osenv') 8var mkdirp = require('mkdirp') 9var fs = require('graceful-fs') 10 11var pkg = path.resolve(__dirname, 'outdated-private') 12var pkgLocalPrivate = path.resolve(pkg, 'local-private') 13var pkgScopedLocalPrivate = path.resolve(pkg, 'another-local-private') 14var pkgLocalUnderscore = path.resolve(pkg, 'underscore') 15 16var pjParent = JSON.stringify({ 17 name: 'outdated-private', 18 version: '1.0.0', 19 dependencies: { 20 'local-private': 'file:local-private', 21 '@scoped/another-local-private': 'file:another-local-private', 22 'underscore': 'file:underscore' 23 } 24}, null, 2) + '\n' 25 26var pjLocalPrivate = JSON.stringify({ 27 name: 'local-private', 28 version: '1.0.0', 29 'private': true 30}, null, 2) + '\n' 31 32var pjLocalPrivateBumped = JSON.stringify({ 33 name: 'local-private', 34 version: '1.1.0', 35 'private': true 36}, null, 2) + '\n' 37 38var pjScopedLocalPrivate = JSON.stringify({ 39 name: '@scoped/another-local-private', 40 version: '1.0.0', 41 'private': true 42}, null, 2) + '\n' 43 44var pjLocalUnderscore = JSON.stringify({ 45 name: 'underscore', 46 version: '1.3.1' 47}, null, 2) + '\n' 48 49test('setup', function (t) { 50 bootstrap() 51 t.end() 52}) 53 54test('outdated ignores private modules', function (t) { 55 t.plan(4) 56 process.chdir(pkg) 57 mr({ port: common.port }, function (er, s) { 58 npm.load( 59 { 60 loglevel: 'silent', 61 parseable: true, 62 registry: common.registry 63 }, 64 function () { 65 npm.install('.', function (err) { 66 t.ifError(err, 'install success') 67 bumpLocalPrivate() 68 npm.outdated(function (er, d) { 69 t.ifError(err, 'npm outdated ran without error') 70 t.is(process.exitCode, 1, 'exitCode set to 1') 71 process.exitCode = 0 72 t.deepEqual(d, [[ 73 path.resolve(__dirname, 'outdated-private'), 74 'underscore', 75 '1.3.1', 76 '1.5.1', 77 '1.5.1', 78 'underscore@1.5.1', 79 null 80 ]]) 81 s.close() 82 }) 83 }) 84 } 85 ) 86 }) 87}) 88 89test('cleanup', function (t) { 90 cleanup() 91 t.end() 92}) 93 94function bootstrap () { 95 mkdirp.sync(pkg) 96 fs.writeFileSync(path.resolve(pkg, 'package.json'), pjParent) 97 98 mkdirp.sync(pkgLocalPrivate) 99 fs.writeFileSync(path.resolve(pkgLocalPrivate, 'package.json'), pjLocalPrivate) 100 101 mkdirp.sync(pkgScopedLocalPrivate) 102 fs.writeFileSync(path.resolve(pkgScopedLocalPrivate, 'package.json'), pjScopedLocalPrivate) 103 104 mkdirp.sync(pkgLocalUnderscore) 105 fs.writeFileSync(path.resolve(pkgLocalUnderscore, 'package.json'), pjLocalUnderscore) 106} 107 108function bumpLocalPrivate () { 109 fs.writeFileSync(path.resolve(pkgLocalPrivate, 'package.json'), pjLocalPrivateBumped) 110} 111 112function cleanup () { 113 process.chdir(osenv.tmpdir()) 114 rimraf.sync(pkg) 115} 116