summaryrefslogtreecommitdiff
path: root/deps/npm/test/network/legacy-shrinkwrap.js
blob: 6f5303037707a02da354d01a4b11022b59414795 (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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
'use strict'
var test = require('tap').test
var common = require('../common-tap.js')
var path = require('path')
var basepath = path.resolve(__dirname, path.basename(__filename, '.js'))
var Tacks = require('tacks')
var File = Tacks.File
var Dir = Tacks.Dir

var fixture = new Tacks(
  Dir({
    README: File(
      'just an npm test\n'
    ),
    'npm-shrinkwrap.json': File({
      name: 'npm-test-shrinkwrap',
      version: '0.0.0',
      dependencies: {
        glob: {
          version: '3.1.5',
          from: 'git://github.com/isaacs/node-glob.git#npm-test',
          resolved: 'git://github.com/isaacs/node-glob.git#67bda227fd7a559cca5620307c7d30a6732a792f',
          dependencies: {
            'graceful-fs': {
              version: '1.1.5',
              resolved: 'https://registry.npmjs.org/graceful-fs/-/graceful-fs-1.1.5.tgz',
              dependencies: {
                'fast-list': {
                  version: '1.0.2',
                  resolved: 'https://registry.npmjs.org/fast-list/-/fast-list-1.0.2.tgz'
                }
              }
            },
            inherits: {
              version: '1.0.0',
              resolved: 'https://registry.npmjs.org/inherits/-/inherits-1.0.0.tgz'
            },
            minimatch: {
              version: '0.2.1',
              dependencies: {
                'lru-cache': {
                  version: '1.0.5'
                }
              }
            }
          }
        },
        minimatch: {
          version: '0.1.5',
          resolved: 'https://registry.npmjs.org/minimatch/-/minimatch-0.1.5.tgz',
          dependencies: {
            'lru-cache': {
              version: '1.0.5',
              resolved: 'https://registry.npmjs.org/lru-cache/-/lru-cache-1.0.5.tgz'
            }
          }
        },
        'npm-test-single-file': {
          version: '1.2.3',
          resolved: 'https://gist.github.com/isaacs/1837112/raw/9ef57a59fc22aeb1d1ca346b68826dcb638b8416/index.js'
        }
      }
    }),
    'package.json': File({
      author: 'Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)',
      name: 'npm-test-shrinkwrap',
      version: '0.0.0',
      dependencies: {
        'npm-test-single-file': 'https://gist.github.com/isaacs/1837112/raw/9ef57a59fc22aeb1d1ca346b68826dcb638b8416/index.js',
        glob: 'git://github.com/isaacs/node-glob.git#npm-test',
        minimatch: '~0.1.0'
      },
      scripts: {
        test: 'node test.js'
      }
    })
  })
)

test('setup', function (t) {
  setup()
  t.done()
})

test('shrinkwrap', function (t) {
  common.npm(['install'], {cwd: basepath}, installCheckAndTest)

  function installCheckAndTest (err, code, stdout, stderr) {
    if (err) throw err
    console.error(stderr)
    t.is(code, 0, 'install went ok')

    common.npm(['ls', '--json'], {cwd: basepath}, verifyLsMatchesShrinkwrap)
  }

  function verifyLsMatchesShrinkwrap (err, code, stdout, stderr) {
    if (err) throw err
    console.error(stderr)
    t.is(code, 0, 'ls went ok')
    var actual = JSON.parse(stdout)
    var expected = require(path.resolve(basepath, 'npm-shrinkwrap.json'))
    // from is expected to vary
    t.isDeeply(rmFrom(actual), rmFrom(expected))
    t.done()
  }

  function rmFrom (obj) {
    for (var i in obj) {
      if (i === 'from') {
        delete obj[i]
      } else if (i === 'dependencies') {
        for (var j in obj[i]) {
          rmFrom(obj[i][j])
        }
      }
    }
  }
})

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

function setup () {
  cleanup()
  fixture.create(basepath)
}

function cleanup () {
  fixture.remove(basepath)
}