1var fs = require('graceful-fs') 2var path = require('path') 3 4var mr = require('npm-registry-mock') 5var test = require('tap').test 6 7var npm = require('../../') 8var common = require('../common-tap.js') 9 10// config 11var pkg = common.pkg 12var cache = common.cache 13var originalLog 14 15var json = { 16 name: 'outdated', 17 description: 'fixture', 18 version: '0.0.1', 19 dependencies: { 20 underscore: '1.3.1', 21 async: '0.2.9', 22 checker: '0.5.1' 23 } 24} 25 26test('setup', function (t) { 27 originalLog = console.log 28 fs.writeFileSync( 29 path.join(pkg, 'package.json'), 30 JSON.stringify(json, null, 2) 31 ) 32 33 process.chdir(pkg) 34 t.end() 35}) 36 37test('it should not throw', function (t) { 38 var output = [] 39 var expOut = [ 40 path.resolve(pkg, 'node_modules', 'async') + 41 ':async@0.2.9' + 42 ':async@0.2.9' + 43 ':async@0.2.10' + 44 '\n' + 45 path.resolve(pkg, 'node_modules', 'checker') + 46 ':checker@0.5.1' + 47 ':checker@0.5.1' + 48 ':checker@0.5.2' + 49 '\n' + 50 path.resolve(pkg, 'node_modules', 'underscore') + 51 ':underscore@1.3.1' + 52 ':underscore@1.3.1' + 53 ':underscore@1.5.1' 54 ] 55 56 var expData = [ 57 [ 58 pkg, 59 'async', 60 '0.2.9', 61 '0.2.9', 62 '0.2.10', 63 '0.2.9', 64 null 65 ], 66 [ 67 pkg, 68 'checker', 69 '0.5.1', 70 '0.5.1', 71 '0.5.2', 72 '0.5.1', 73 null 74 ], 75 [ 76 pkg, 77 'underscore', 78 '1.3.1', 79 '1.3.1', 80 '1.5.1', 81 '1.3.1', 82 null 83 ] 84 ] 85 86 console.log = function () {} 87 mr({ port: common.port }, function (er, s) { 88 npm.load( 89 { 90 cache: cache, 91 loglevel: 'silent', 92 parseable: true, 93 registry: common.registry 94 }, 95 function () { 96 npm.install('.', function (err) { 97 t.ifError(err, 'install success') 98 console.log = function () { 99 output.push.apply(output, arguments) 100 } 101 npm.outdated(function (er, d) { 102 t.ifError(err, 'outdated completed without error') 103 t.equals(process.exitCode, 1, 'exitCode set to 1') 104 process.exitCode = 0 105 output = output.map(function (x) { return x.replace(/\r/g, '') }) 106 console.log = originalLog 107 108 t.same(output, expOut) 109 t.same(d, expData) 110 111 s.close() 112 t.end() 113 }) 114 }) 115 } 116 ) 117 }) 118}) 119 120test('cleanup', function (t) { 121 console.log = originalLog 122 t.end() 123}) 124