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
|
var fs = require('graceful-fs')
var path = require('path')
var mkdirp = require('mkdirp')
var mr = require('npm-registry-mock')
var osenv = require('osenv')
var rimraf = require('rimraf')
var test = require('tap').test
var common = require('../common-tap.js')
// Install from a tarball that thinks it is underscore@1.5.1
// (but is actually a fork)
var forkPath = path.resolve(
__dirname, '..', 'fixtures', 'forked-underscore-1.5.1.tgz'
)
var pkg = path.resolve(__dirname, 'cache-shasum-fork')
var cache = path.join(pkg, 'cache')
var server
test('setup', function (t) {
setup()
t.comment('test for https://github.com/npm/npm/issues/3265')
mr({ port: common.port }, function (er, s) {
server = s
t.end()
})
})
test('npm cache - install from fork', function (t) {
setup()
common.npm(
[
'--loglevel', 'silent',
'--json',
'--registry', common.registry,
'install', forkPath
],
{
cwd: pkg,
env: { npm_config_cache: cache }
},
function (err, code, stdout, stderr) {
t.ifErr(err, 'install finished without error')
t.notOk(stderr, 'Should not get data on stderr: ' + stderr)
t.equal(code, 0, 'install finished successfully')
var deps = {}
JSON.parse(stdout).added.forEach(function (dep) { deps[dep.name] = dep })
t.equal(deps.underscore && deps.underscore.version, '1.5.1')
var index = fs.readFileSync(
path.join(pkg, 'node_modules', 'underscore', 'index.js'),
'utf8'
)
t.equal(index, 'console.log("This is the fork");\n\n')
t.end()
}
)
})
// Now install the real 1.5.1.
test('npm cache - install from origin', function (t) {
setup()
common.npm(
[
'--loglevel', 'silent',
'--json',
'--registry', common.registry,
'install', 'underscore'
],
{
cwd: pkg,
env: { npm_config_cache: cache }
},
function (err, code, stdout, stderr) {
t.ifErr(err, 'install finished without error')
t.equal(code, 0, 'install finished successfully')
t.notOk(stderr, 'Should not get data on stderr: ' + stderr)
var deps = {}
JSON.parse(stdout).updated.forEach(function (dep) { deps[dep.name] = dep })
t.equal(deps.underscore && deps.underscore.version, '1.5.1')
var index = fs.readFileSync(
path.join(pkg, 'node_modules', 'underscore', 'index.js'),
'utf8'
)
t.equal(index, 'module.exports = require(\'./underscore\');\n')
t.end()
}
)
})
test('cleanup', function (t) {
server.close()
cleanup()
t.end()
})
function cleanup () {
process.chdir(osenv.tmpdir())
rimraf.sync(pkg)
}
function setup () {
mkdirp.sync(cache)
mkdirp.sync(path.join(pkg, 'node_modules'))
process.chdir(pkg)
}
|