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
|
'use strict'
var path = require('path')
var test = require('tap').test
var common = require('../common-tap')
var mr = require('npm-registry-mock')
var server1
var server2
var packageName = path.basename(__filename, '.js')
var fooPkg = {
name: packageName,
versions: {
'0.0.0': {
name: packageName,
version: '0.0.0',
dist: {
tarball: 'https://localhost:1338/registry/' + packageName + '/-/' + packageName + '-0.0.0.tgz',
shasum: '356a192b7913b04c54574d18c28d46e6395428ab'
}
}
}
}
var iPackageName = packageName + 'i'
var fooiPkg = {
name: iPackageName,
versions: {
'0.0.0': {
name: iPackageName,
version: '0.0.0',
dist: {
tarball: 'http://127.0.0.1:1338/registry/' + iPackageName + '/-/' + iPackageName + '-0.0.0.tgz',
shasum: '356a192b7913b04c54574d18c28d46e6395428ab'
}
}
}
}
test('setup', function (t) {
mr({
port: 1337,
throwOnUnmatched: true
}, function (err, s) {
t.ifError(err, 'registry mocked successfully')
server1 = s
mr({
port: 1338,
throwOnUnmatched: true
}, function (err, s) {
t.ifError(err, 'registry mocked successfully')
server2 = s
t.end()
})
})
})
test('tarball paths should update port if updating protocol', function (t) {
server1.get('/registry/' + packageName).reply(200, fooPkg)
server1.get(
'/registry/' + packageName + '/-/' + packageName + '-0.0.0.tgz'
).reply(200, '1')
common.npm(
[
'cache',
'add',
packageName + '@0.0.0',
'--registry',
'http://localhost:1337/registry'
],
{},
function (er, code, stdout, stderr) {
if (er) { throw er }
t.equal(stderr, '', 'no error output')
t.equal(code, 0, 'addNamed worked')
server1.done()
t.end()
}
)
})
test('tarball paths should NOT update if different hostname', function (t) {
server1.get('/registry/' + iPackageName).reply(200, fooiPkg)
server2.get(
'/registry/' + iPackageName + '/-/' + iPackageName + '-0.0.0.tgz'
).reply(200, '1')
common.npm(
[
'cache',
'add',
iPackageName + '@0.0.0',
'--registry',
'http://localhost:1337/registry'
],
{},
function (er, code, stdout, stderr) {
if (er) { throw er }
t.equal(code, 0, 'addNamed worked')
server1.done()
server2.done()
t.end()
}
)
})
test('cleanup', function (t) {
t.pass('cleaned up')
server1.close()
server2.close()
t.end()
})
|