• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict'
2var test = require('tap').test
3var common = require('../common-tap.js')
4var path = require('path')
5var basepath = path.resolve(__dirname, path.basename(__filename, '.js'))
6var Tacks = require('tacks')
7var File = Tacks.File
8var Dir = Tacks.Dir
9
10var fixture = new Tacks(
11  Dir({
12    README: File(
13      'just an npm test\n'
14    ),
15    'npm-shrinkwrap.json': File({
16      name: 'npm-test-shrinkwrap',
17      version: '0.0.0',
18      dependencies: {
19        glob: {
20          version: '3.1.5',
21          from: 'git://github.com/isaacs/node-glob.git#npm-test',
22          resolved: 'git://github.com/isaacs/node-glob.git#67bda227fd7a559cca5620307c7d30a6732a792f',
23          dependencies: {
24            'graceful-fs': {
25              version: '1.1.5',
26              resolved: 'https://registry.npmjs.org/graceful-fs/-/graceful-fs-1.1.5.tgz',
27              dependencies: {
28                'fast-list': {
29                  version: '1.0.2',
30                  resolved: 'https://registry.npmjs.org/fast-list/-/fast-list-1.0.2.tgz'
31                }
32              }
33            },
34            inherits: {
35              version: '1.0.0',
36              resolved: 'https://registry.npmjs.org/inherits/-/inherits-1.0.0.tgz'
37            },
38            minimatch: {
39              version: '0.2.1',
40              dependencies: {
41                'lru-cache': {
42                  version: '1.0.5'
43                }
44              }
45            }
46          }
47        },
48        minimatch: {
49          version: '0.1.5',
50          resolved: 'https://registry.npmjs.org/minimatch/-/minimatch-0.1.5.tgz',
51          dependencies: {
52            'lru-cache': {
53              version: '1.0.5',
54              resolved: 'https://registry.npmjs.org/lru-cache/-/lru-cache-1.0.5.tgz'
55            }
56          }
57        },
58        'npm-test-single-file': {
59          version: '1.2.3',
60          resolved: 'https://gist.github.com/isaacs/1837112/raw/9ef57a59fc22aeb1d1ca346b68826dcb638b8416/index.js'
61        }
62      }
63    }),
64    'package.json': File({
65      author: 'Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)',
66      name: 'npm-test-shrinkwrap',
67      version: '0.0.0',
68      dependencies: {
69        'npm-test-single-file': 'https://gist.github.com/isaacs/1837112/raw/9ef57a59fc22aeb1d1ca346b68826dcb638b8416/index.js',
70        glob: 'git://github.com/isaacs/node-glob.git#npm-test',
71        minimatch: '~0.1.0'
72      },
73      scripts: {
74        test: 'node test.js'
75      }
76    })
77  })
78)
79
80test('setup', function (t) {
81  setup()
82  t.done()
83})
84
85test('shrinkwrap', function (t) {
86  common.npm(['install'], {cwd: basepath}, installCheckAndTest)
87
88  function installCheckAndTest (err, code, stdout, stderr) {
89    if (err) throw err
90    console.error(stderr)
91    t.is(code, 0, 'install went ok')
92
93    common.npm(['ls', '--json'], {cwd: basepath}, verifyLsMatchesShrinkwrap)
94  }
95
96  function verifyLsMatchesShrinkwrap (err, code, stdout, stderr) {
97    if (err) throw err
98    console.error(stderr)
99    t.is(code, 0, 'ls went ok')
100    var actual = JSON.parse(stdout)
101    var expected = require(path.resolve(basepath, 'npm-shrinkwrap.json'))
102    // from is expected to vary
103    t.isDeeply(rmFrom(actual), rmFrom(expected))
104    t.done()
105  }
106
107  function rmFrom (obj) {
108    for (var i in obj) {
109      if (i === 'from') {
110        delete obj[i]
111      } else if (i === 'dependencies') {
112        for (var j in obj[i]) {
113          rmFrom(obj[i][j])
114        }
115      }
116    }
117  }
118})
119
120test('cleanup', function (t) {
121  cleanup()
122  t.done()
123})
124
125function setup () {
126  cleanup()
127  fixture.create(basepath)
128}
129
130function cleanup () {
131  fixture.remove(basepath)
132}
133