1var fs = require('graceful-fs') 2var path = require('path') 3 4var mr = require('npm-registry-mock') 5var test = require('tap').test 6 7var common = require('../common-tap.js') 8var npm = require('../../') 9 10// config 11var pkg = common.pkg 12var cache = common.cache 13 14var json = { 15 name: 'outdated-long', 16 description: 'fixture', 17 version: '0.0.1', 18 dependencies: { 19 underscore: '1.3.1' 20 } 21} 22 23test('setup', function (t) { 24 fs.writeFileSync( 25 path.join(pkg, 'package.json'), 26 JSON.stringify(json, null, 2) 27 ) 28 29 process.chdir(pkg) 30 t.end() 31}) 32 33test('it should not throw', function (t) { 34 var originalLog = console.log 35 36 var output = [] 37 var expOut = [ 38 'add\tunderscore\t1.3.1\tnode_modules/underscore\t\t', 39 path.resolve(pkg, 'node_modules', 'underscore') + 40 ':underscore@1.3.1' + 41 ':underscore@1.3.1' + 42 ':underscore@1.5.1' + 43 ':dependencies' 44 ] 45 46 var expData = [ 47 [ 48 pkg, 49 'underscore', 50 '1.3.1', 51 '1.3.1', 52 '1.5.1', 53 '1.3.1', 54 'dependencies' 55 ] 56 ] 57 58 console.log = function () { 59 output.push.apply(output, arguments) 60 } 61 mr({ port: common.port }, function (er, s) { 62 npm.load( 63 { 64 cache: cache, 65 loglevel: 'silent', 66 parseable: true, 67 registry: common.registry 68 }, 69 function () { 70 npm.install('.', function (err) { 71 t.ifError(err, 'install success') 72 npm.config.set('long', true) 73 // since it's possible for the homepage of a package to change, after the 74 // install we read the value from the package.json directly to specify our 75 // expected output. 76 expOut[1] = expOut[1] + ':' + JSON.parse(fs.readFileSync(path.resolve(pkg, 'node_modules', 'underscore', 'package.json'))).homepage 77 npm.outdated(function (er, d) { 78 t.ifError(err, 'npm outdated ran without error') 79 t.is(process.exitCode, 1, 'exit code set to 1') 80 process.exitCode = 0 81 console.log = originalLog 82 output[0] = output[0].replace(/\\/g, '/') 83 t.same(output, expOut) 84 t.same(d, expData) 85 86 s.close() 87 t.end() 88 }) 89 }) 90 } 91 ) 92 }) 93}) 94