1var fs = require('graceful-fs') 2var path = require('path') 3 4var mkdirp = require('mkdirp') 5var mr = require('npm-registry-mock') 6var test = require('tap').test 7 8var common = require('../common-tap.js') 9 10// Install from a tarball that thinks it is underscore@1.5.1 11// (but is actually a fork) 12var forkPath = path.resolve( 13 __dirname, '..', 'fixtures', 'forked-underscore-1.5.1.tgz' 14) 15var pkg = common.pkg 16var cache = common.cache 17var server 18 19test('setup', function (t) { 20 mkdirp.sync(path.join(pkg, 'node_modules')) 21 process.chdir(pkg) 22 t.comment('test for https://github.com/npm/npm/issues/3265') 23 mr({ port: common.port }, function (er, s) { 24 server = s 25 t.end() 26 }) 27}) 28 29test('npm cache - install from fork', function (t) { 30 common.npm( 31 [ 32 '--loglevel', 'silent', 33 '--json', 34 '--registry', common.registry, 35 'install', forkPath 36 ], 37 { 38 cwd: pkg, 39 env: { npm_config_cache: cache } 40 }, 41 function (err, code, stdout, stderr) { 42 t.ifErr(err, 'install finished without error') 43 t.equal(stderr, '', 'Should not get data on stderr') 44 t.equal(code, 0, 'install finished successfully') 45 46 var deps = {} 47 JSON.parse(stdout).added.forEach(function (dep) { deps[dep.name] = dep }) 48 t.equal(deps.underscore && deps.underscore.version, '1.5.1') 49 var index = fs.readFileSync( 50 path.join(pkg, 'node_modules', 'underscore', 'index.js'), 51 'utf8' 52 ) 53 t.equal(index, 'console.log("This is the fork");\n\n') 54 t.end() 55 } 56 ) 57}) 58 59// Now install the real 1.5.1. 60test('npm cache - install from origin', function (t) { 61 common.npm( 62 [ 63 '--loglevel', 'silent', 64 '--json', 65 '--registry', common.registry, 66 'install', 'underscore' 67 ], 68 { 69 cwd: pkg, 70 env: { npm_config_cache: cache } 71 }, 72 function (err, code, stdout, stderr) { 73 t.ifErr(err, 'install finished without error') 74 t.equal(code, 0, 'install finished successfully') 75 t.notOk(stderr, 'Should not get data on stderr: ' + stderr) 76 var deps = {} 77 JSON.parse(stdout).updated.forEach(function (dep) { deps[dep.name] = dep }) 78 t.equal(deps.underscore && deps.underscore.version, '1.5.1') 79 var index = fs.readFileSync( 80 path.join(pkg, 'node_modules', 'underscore', 'index.js'), 81 'utf8' 82 ) 83 t.equal(index, 'module.exports = require(\'./underscore\');\n') 84 t.end() 85 } 86 ) 87}) 88 89test('cleanup', function (t) { 90 server.close() 91 t.end() 92}) 93