• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1var mr = require('npm-registry-mock')
2
3var test = require('tap').test
4var common = require('../common-tap.js')
5
6var server
7
8var cache = {
9  '_id': 'cond',
10  '_rev': '19-d458a706de1740662cd7728d7d7ddf07',
11  'name': 'cond',
12  'time': {
13    'modified': '2015-02-13T07:33:58.120Z',
14    'created': '2014-03-16T20:52:52.236Z',
15    '0.0.0': '2014-03-16T20:52:52.236Z',
16    '0.0.1': '2014-03-16T21:12:33.393Z',
17    '0.0.2': '2014-03-16T21:15:25.430Z'
18  },
19  'versions': {
20    '0.0.0': {},
21    '0.0.1': {},
22    '0.0.2': {}
23  },
24  'dist-tags': {
25    'latest': '0.0.2'
26  },
27  'description': 'Restartable error handling system',
28  'license': 'CC0'
29}
30
31test('setup', function (t) {
32  mr({port: common.port}, function (err, s) {
33    t.ifError(err, 'registry mocked successfully')
34    server = s
35    t.ok(true)
36    t.end()
37  })
38})
39
40test('npm deprecate an unscoped package', function (t) {
41  var deprecated = JSON.parse(JSON.stringify(cache))
42  deprecated.versions = {
43    '0.0.0': {},
44    '0.0.1': { deprecated: 'make it dead' },
45    '0.0.2': {}
46  }
47  server.get('/cond?write=true').reply(200, cache)
48  server.put('/cond', deprecated).reply(201, { deprecated: true })
49  common.npm([
50    'deprecate',
51    'cond@0.0.1',
52    'make it dead',
53    '--registry', common.registry,
54    '--loglevel', 'silent'
55  ], {},
56  function (er, code, stdout, stderr) {
57    t.ifError(er, 'npm deprecate')
58    t.equal(stderr, '', 'no error output')
59    t.equal(code, 0, 'exited OK')
60    t.end()
61  })
62})
63
64test('npm deprecate a scoped package', function (t) {
65  var cacheCopy = JSON.parse(JSON.stringify(cache))
66  cacheCopy.name = '@scope/cond'
67  cacheCopy._id = '@scope/cond'
68  var deprecated = JSON.parse(JSON.stringify(cacheCopy))
69  deprecated.versions = {
70    '0.0.0': {},
71    '0.0.1': { deprecated: 'make it dead' },
72    '0.0.2': {}
73  }
74  server.get('/@scope%2fcond?write=true').reply(200, cacheCopy)
75  server.put('/@scope%2fcond', deprecated).reply(201, { deprecated: true })
76  common.npm([
77    'deprecate',
78    '@scope/cond@0.0.1',
79    'make it dead',
80    '--registry', common.registry,
81    '--loglevel', 'silent'
82  ], {},
83  function (er, code, stdout, stderr) {
84    t.ifError(er, 'npm deprecate')
85    t.equal(stderr, '', 'no error output')
86    t.equal(code, 0, 'exited OK')
87    t.end()
88  })
89})
90
91test('npm deprecate semver range', function (t) {
92  var deprecated = JSON.parse(JSON.stringify(cache))
93  deprecated.versions = {
94    '0.0.0': { deprecated: 'make it dead' },
95    '0.0.1': { deprecated: 'make it dead' },
96    '0.0.2': {}
97  }
98  server.get('/cond?write=true').reply(200, cache)
99  server.put('/cond', deprecated).reply(201, { deprecated: true })
100  common.npm([
101    'deprecate',
102    'cond@<0.0.2',
103    'make it dead',
104    '--registry', common.registry,
105    '--loglevel', 'silent'
106  ], {},
107  function (er, code, stdout, stderr) {
108    t.ifError(er, 'npm deprecate')
109    t.equal(stderr, '', 'no error output')
110    t.equal(code, 0, 'exited OK')
111    t.end()
112  })
113})
114
115test('npm deprecate bad semver range', function (t) {
116  common.npm([
117    'deprecate',
118    'cond@-9001',
119    'make it dead',
120    '--registry', common.registry
121  ], {},
122  function (er, code, stdout, stderr) {
123    t.equal(code, 1, 'errored')
124    t.match(stderr, /invalid version range/, 'bad semver')
125    t.end()
126  })
127})
128
129test('npm deprecate a package with no semver range', function (t) {
130  var deprecated = JSON.parse(JSON.stringify(cache))
131  deprecated.versions = {
132    '0.0.0': { deprecated: 'make it dead' },
133    '0.0.1': { deprecated: 'make it dead' },
134    '0.0.2': { deprecated: 'make it dead' }
135  }
136  server.get('/cond?write=true').reply(200, cache)
137  server.put('/cond', deprecated).reply(201, { deprecated: true })
138  common.npm([
139    'deprecate',
140    'cond',
141    'make it dead',
142    '--registry', common.registry,
143    '--loglevel', 'silent'
144  ], {},
145  function (er, code, stdout, stderr) {
146    t.ifError(er, 'npm deprecate')
147    t.equal(stderr, '', 'no error output')
148    t.equal(code, 0, 'exited OK')
149    t.end()
150  })
151})
152
153test('cleanup', function (t) {
154  server.close()
155  t.ok(true)
156  t.end()
157})
158