1var fs = require('graceful-fs') 2var path = require('path') 3 4var mr = require('npm-registry-mock') 5var test = require('tap').test 6 7var common = require('../common-tap') 8 9var pkg = common.pkg 10 11var json = { 12 author: 'Steve Mason', 13 name: 'url-dependencies', 14 version: '0.0.0', 15 dependencies: { 16 underscore: common.registry + '/underscore/-/underscore-1.3.1.tgz' 17 } 18} 19 20var mockRoutes = { 21 'get': { 22 '/underscore/-/underscore-1.3.1.tgz': [200] 23 } 24} 25 26const tarballWasFetched = output => output.includes( 27 `GET 200 ${common.registry}/underscore/-/underscore-1.3.1.tgz`) 28 29const performInstall = () => common.npm(['install'], { 30 cwd: pkg, 31 env: { 32 npm_config_registry: common.registry, 33 npm_config_cache_lock_stale: 1000, 34 npm_config_cache_lock_wait: 1000, 35 npm_config_loglevel: 'http', 36 HOME: process.env.HOME, 37 Path: process.env.PATH, 38 PATH: process.env.PATH 39 } 40}) 41 42test('setup', function (t) { 43 fs.writeFileSync( 44 path.join(pkg, 'package.json'), 45 JSON.stringify(json, null, 2) 46 ) 47 mr({ port: common.port, mocks: mockRoutes }, function (er, s) { 48 t.parent.teardown(() => s.close()) 49 t.end() 50 }) 51}) 52 53test('url-dependencies: download first time', t => 54 performInstall().then(([code, _, output]) => { 55 t.equal(code, 0, 'exited successfully') 56 t.ok(tarballWasFetched(output), 'download first time') 57 }) 58 .then(() => performInstall()).then(([code, _, output]) => { 59 t.equal(code, 0, 'exited successfully') 60 t.notOk(tarballWasFetched(output), 'do not download second time') 61 })) 62