summaryrefslogtreecommitdiff
path: root/deps/node/deps/npm/test/need-npm5-update/ignore-shrinkwrap.js
blob: 9468162eeef863fbc412c5ff2c5e3fd74e7db12c (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
133
134
135
var fs = require('graceful-fs')
var path = require('path')

var mkdirp = require('mkdirp')
var mr = require('npm-registry-mock')
var rimraf = require('rimraf')
var test = require('tap').test

var common = require('../common-tap.js')

var pkg = require('path').join(__dirname, 'ignore-shrinkwrap')

var EXEC_OPTS = { cwd: pkg }

var customMocks = {
  'get': {
    '/package.js': [200, { ente: true }],
    '/shrinkwrap.js': [200, { ente: true }]
  }
}

var json = {
  author: 'Rocko Artischocko',
  name: 'ignore-shrinkwrap',
  version: '0.0.0',
  dependencies: {
    'npm-test-ignore-shrinkwrap-file': 'http://localhost:1337/package.js'
  }
}

var shrinkwrap = {
  name: 'ignore-shrinkwrap',
  version: '0.0.0',
  dependencies: {
    'npm-test-ignore-shrinkwrap-file': {
      version: '1.2.3',
      from: 'http://localhost:1337/shrinkwrap.js',
      resolved: 'http://localhost:1337/shrinkwrap.js',
      dependencies: {
        opener: {
          version: '1.3.0',
          from: 'opener@1.3.0'
        }
      }
    }
  }
}

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

test('npm install --no-shrinkwrap', function (t) {
  mr({ port: common.port, mocks: customMocks }, function (err, s) {
    t.ifError(err, 'mock registry bootstrapped without issue')
    s._server.on('request', function (req) {
      switch (req.url) {
        case '/shrinkwrap.js':
          t.fail('npm-shrinkwrap.json used instead of package.json')
          break
        case '/package.js':
          t.pass('package.json used')
      }
    })

    common.npm(
      [
        '--registry', common.registry,
        '--loglevel', 'silent',
        'install', '--no-shrinkwrap'
      ],
      EXEC_OPTS,
      function (err, code) {
        t.ifError(err, 'npm ran without issue')
        t.ok(code, "install isn't going to succeed")
        s.close()
        t.end()
      }
    )
  })
})

test('npm install (with shrinkwrap)', function (t) {
  mr({ port: common.port, mocks: customMocks }, function (err, s) {
    t.ifError(err, 'mock registry bootstrapped without issue')
    s._server.on('request', function (req) {
      switch (req.url) {
        case '/shrinkwrap.js':
          t.pass('shrinkwrap used')
          break
        case '/package.js':
          t.fail('shrinkwrap ignored')
      }
    })

    common.npm(
      [
        '--registry', common.registry,
        '--loglevel', 'silent',
        'install'
      ],
      EXEC_OPTS,
      function (err, code) {
        t.ifError(err, 'npm ran without issue')
        t.ok(code, "install isn't going to succeed")
        s.close()
        t.end()
      }
    )
  })
})

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

function cleanup () {
  rimraf.sync(pkg)
}

function setup () {
  cleanup()
  mkdirp.sync(pkg)
  fs.writeFileSync(
    path.join(pkg, 'package.json'),
    JSON.stringify(json, null, 2)
  )
  fs.writeFileSync(
    path.join(pkg, 'npm-shrinkwrap.json'),
    JSON.stringify(shrinkwrap, null, 2)
  )
  process.chdir(pkg)
}