Welcome to mirror list, hosted at ThFree Co, Russian Federation.

outdated-private.js « tap « test - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1d5e460c6eab6c4fef3f597b45145a9c57ee6540 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
var common = require('../common-tap.js')
var test = require('tap').test
var npm = require('../../')
var rimraf = require('rimraf')
var path = require('path')
var mr = require('npm-registry-mock')
var osenv = require('osenv')
var mkdirp = require('mkdirp')
var fs = require('graceful-fs')

var pkg = path.resolve(__dirname, 'outdated-private')
var pkgLocalPrivate = path.resolve(pkg, 'local-private')
var pkgScopedLocalPrivate = path.resolve(pkg, 'another-local-private')
var pkgLocalUnderscore = path.resolve(pkg, 'underscore')

var pjParent = JSON.stringify({
  name: 'outdated-private',
  version: '1.0.0',
  dependencies: {
    'local-private': 'file:local-private',
    '@scoped/another-local-private': 'file:another-local-private',
    'underscore': 'file:underscore'
  }
}, null, 2) + '\n'

var pjLocalPrivate = JSON.stringify({
  name: 'local-private',
  version: '1.0.0',
  'private': true
}, null, 2) + '\n'

var pjLocalPrivateBumped = JSON.stringify({
  name: 'local-private',
  version: '1.1.0',
  'private': true
}, null, 2) + '\n'

var pjScopedLocalPrivate = JSON.stringify({
  name: '@scoped/another-local-private',
  version: '1.0.0',
  'private': true
}, null, 2) + '\n'

var pjLocalUnderscore = JSON.stringify({
  name: 'underscore',
  version: '1.3.1'
}, null, 2) + '\n'

test('setup', function (t) {
  bootstrap()
  t.end()
})

test('outdated ignores private modules', function (t) {
  t.plan(3)
  process.chdir(pkg)
  mr({ port: common.port }, function (er, s) {
    npm.load(
      {
        loglevel: 'silent',
        parseable: true,
        registry: common.registry
      },
      function () {
        npm.install('.', function (err) {
          t.ifError(err, 'install success')
          bumpLocalPrivate()
          npm.outdated(function (er, d) {
            t.ifError(er, 'outdated success')
            t.deepEqual(d, [[
              path.resolve(__dirname, 'outdated-private'),
              'underscore',
              '1.3.1',
              '1.5.1',
              '1.5.1',
              'underscore@1.5.1',
              null
            ]])
            s.close()
          })
        })
      }
    )
  })
})

test('cleanup', function (t) {
  cleanup()
  t.end()
})

function bootstrap () {
  mkdirp.sync(pkg)
  fs.writeFileSync(path.resolve(pkg, 'package.json'), pjParent)

  mkdirp.sync(pkgLocalPrivate)
  fs.writeFileSync(path.resolve(pkgLocalPrivate, 'package.json'), pjLocalPrivate)

  mkdirp.sync(pkgScopedLocalPrivate)
  fs.writeFileSync(path.resolve(pkgScopedLocalPrivate, 'package.json'), pjScopedLocalPrivate)

  mkdirp.sync(pkgLocalUnderscore)
  fs.writeFileSync(path.resolve(pkgLocalUnderscore, 'package.json'), pjLocalUnderscore)
}

function bumpLocalPrivate () {
  fs.writeFileSync(path.resolve(pkgLocalPrivate, 'package.json'), pjLocalPrivateBumped)
}

function cleanup () {
  process.chdir(osenv.tmpdir())
  rimraf.sync(pkg)
}