• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1var fs = require('graceful-fs')
2var path = require('path')
3var osenv = require('osenv')
4var mkdirp = require('mkdirp')
5var mr = require('npm-registry-mock')
6var rimraf = require('rimraf')
7var test = require('tap').test
8
9var common = require('../common-tap.js')
10
11var pkg = path.resolve(__dirname, 'outdated-symlink')
12var cache = path.resolve(pkg, 'cache')
13
14var fakeRoot = path.join(pkg, 'fakeRoot')
15var OPTS = {
16  env: Object.assign({}, process.env, {
17    'npm_config_prefix': fakeRoot,
18    'registry': common.registry
19  })
20}
21
22var json = {
23  name: 'my-local-package',
24  description: 'fixture',
25  version: '1.0.0'
26}
27
28test('setup', function (t) {
29  cleanup()
30  mkdirp.sync(cache)
31  fs.writeFileSync(
32    path.join(pkg, 'package.json'),
33    JSON.stringify(json, null, 2)
34  )
35  process.chdir(pkg)
36  common.npm(['install', '-g', 'async@0.2.9', 'underscore@1.3.1'], OPTS, function (err, code, stdout, stderr) {
37    if (err) throw err
38    t.comment(stdout)
39    t.comment(stderr)
40    common.npm(['link'], OPTS, function (err, code, stdout, stderr) {
41      if (err) throw err
42      t.comment(stdout)
43      t.comment(stderr)
44      t.is(code, 0)
45      common.npm(['ls', '-g'], OPTS, function (err, code, stdout, stderr) {
46        if (err) throw err
47        t.is(code, 0)
48        t.is(stderr, '', 'got expected stderr')
49        t.match(stdout, /my-local-package@1.0.0/, 'creates global link ok')
50        t.end()
51      })
52    })
53  })
54})
55
56test('when outdated is called linked packages should be displayed as such', function (t) {
57  var regOutLinked = /my-local-package\s*1.0.0\s*linked\s*linked\n/
58  var regOutInstallOne = /async\s*0.2.9\s*0.2.9\s*0.2.10\n/
59  var regOutInstallTwo = /underscore\s*1.3.1\s*1.3.1\s*1.5.1\n/
60
61  mr({ port: common.port }, function (er, s) {
62    common.npm(
63      [
64        '--registry', common.registry,
65        'outdated', '-g'
66      ],
67      OPTS,
68      function (err, c, out, stderr) {
69        if (err) throw err
70        t.is(stderr, '')
71        t.match(out, regOutLinked, 'Global Link format as expected')
72        t.match(out, regOutInstallOne, 'Global Install format as expected')
73        t.match(out, regOutInstallTwo, 'Global Install format as expected')
74        s.close()
75        t.end()
76      }
77    )
78  })
79})
80
81test('cleanup', function (t) {
82  process.chdir(osenv.tmpdir())
83  common.npm(['rm', 'outdated'], OPTS, function (err, code, stdout, stderr) {
84    if (err) throw err
85    t.comment(stdout)
86    t.comment(stderr)
87    t.is(code, 0, 'cleanup outdated in local ok')
88    common.npm(['rm', '-g', 'outdated', 'async', 'underscore'], OPTS, function (err, code) {
89      if (err) throw err
90      t.comment(stdout)
91      t.comment(stderr)
92      t.is(code, 0, 'cleanup outdated in global ok')
93
94      cleanup()
95      t.end()
96    })
97  })
98})
99
100function cleanup () {
101  rimraf.sync(pkg)
102  rimraf.sync(fakeRoot)
103}
104