1 var fs = require('graceful-fs')
2 var path = require('path')
4 var mkdirp = require('mkdirp')
5 var mr = require('npm-registry-mock')
6 var osenv = require('osenv')
7 var rimraf = require('rimraf')
8 var test = require('tap').test
10 var common = require('../common-tap')
13 var pkg = path.resolve(__dirname, 'url-dependencies')
16 author: 'Steve Mason',
17 name: 'url-dependencies',
20 underscore: common.registry + '/underscore/-/underscore-1.3.1.tgz'
26 '/underscore/-/underscore-1.3.1.tgz': [200]
30 test('setup', function (t) {
31 mr({ port: common.port, mocks: mockRoutes }, function (er, s) {
37 test('url-dependencies: download first time', function (t) {
40 performInstall(t, function (output) {
41 if (!tarballWasFetched(output)) {
42 t.fail('Tarball was not fetched')
44 t.pass('Tarball was fetched')
50 test('url-dependencies: do not download subsequent times', function (t) {
53 performInstall(t, function () {
54 performInstall(t, function (output) {
55 if (tarballWasFetched(output)) {
56 t.fail('Tarball was fetched second time around')
58 t.pass('Tarball was not fetched')
65 test('cleanup', function (t) {
72 // windows fix for locked files
73 process.chdir(osenv.tmpdir())
74 rimraf.sync(path.resolve(pkg))
81 path.join(pkg, 'package.json'),
82 JSON.stringify(json, null, 2)
86 function tarballWasFetched (output) {
87 return output.indexOf(
90 '/underscore/-/underscore-1.3.1.tgz'
94 function performInstall (t, cb) {
98 npm_config_registry: common.registry,
99 npm_config_cache_lock_stale: 1000,
100 npm_config_cache_lock_wait: 1000,
101 npm_config_loglevel: 'http',
102 HOME: process.env.HOME,
103 Path: process.env.PATH,
104 PATH: process.env.PATH
107 common.npm(['install'], opts, function (err, code, stdout, stderr) {
108 t.ifError(err, 'install success')
109 t.notOk(code, 'npm install exited with code 0')