npm: Upgrade to 1.3.17
[platform/upstream/nodejs.git] / deps / npm / test / tap / outdated-json.js
1 var common = require("../common-tap.js")
2   , test = require("tap").test
3   , rimraf = require("rimraf")
4   , npm = require("../../")
5   , mr = require("npm-registry-mock")
6   , path = require("path")
7   , spawn = require('child_process').spawn
8   , node = process.execPath
9   , npmc = require.resolve('../../')
10   , pkg = __dirname + '/outdated-new-versions'
11   , args = [ npmc
12            , 'outdated'
13            , '--json'
14            , '--silent'
15            , '--registry=' + common.registry
16            , '--cache=' + pkg + '/cache'
17            ]
18
19 var expected = { underscore:
20                  { current: '1.3.3'
21                  , wanted: '1.3.3'
22                  , latest: '1.5.1'
23                  , location: 'node_modules' + path.sep + 'underscore'
24                  }
25                , request:
26                  { current: '0.9.5'
27                  , wanted: '0.9.5'
28                  , latest: '2.27.0'
29                  , location: 'node_modules' + path.sep + 'request'
30                  }
31                }
32
33 test("it should log json data", function (t) {
34   cleanup()
35   process.chdir(pkg)
36
37   mr(common.port, function (s) {
38     npm.load({
39       cache: pkg + "/cache",
40       loglevel: 'silent',
41       registry: common.registry }
42     , function () {
43       npm.install(".", function (err) {
44         var child = spawn(node, args)
45           , out = ''
46         child.stdout
47           .on('data', function (buf) {
48             out += buf.toString()
49           })
50           .pipe(process.stdout)
51         child.on('exit', function () {
52           out = JSON.parse(out)
53           t.deepEqual(out, expected)
54           s.close()
55           t.end()
56         })
57       })
58     })
59   })
60 })
61
62 test("cleanup", function (t) {
63   cleanup()
64   t.end()
65 })
66
67 function cleanup () {
68   rimraf.sync(pkg + "/node_modules")
69   rimraf.sync(pkg + "/cache")
70 }