1var fs = require('graceful-fs') 2var path = require('path') 3var existsSync = fs.existsSync || path.existsSync 4 5var mkdirp = require('mkdirp') 6var mr = require('npm-registry-mock') 7var test = require('tap').test 8 9var common = require('../common-tap.js') 10var server 11 12var pkg = common.pkg 13var minimist = path.join(pkg, 'minimist') 14 15var EXEC_OPTS = { 16 cwd: path.join(pkg, 'minimist/node_modules'), 17 npm_config_cache: common.cache 18} 19 20var json = { 21 name: 'minimist', 22 version: '0.0.5', 23 dependencies: { 24 optimist: '0.6.0' 25 } 26} 27 28test('setup', function (t) { 29 t.comment('test for https://github.com/npm/npm/issues/4312') 30 setup(function () { 31 t.end() 32 }) 33}) 34 35test('installing a package that depends on the current package', function (t) { 36 common.npm( 37 [ 38 '--registry', common.registry, 39 '--loglevel', 'silent', 40 'install', 'optimist' 41 ], 42 EXEC_OPTS, 43 function (err, code, stdout, stderr) { 44 t.ifError(err, 'npm ran without issue') 45 t.notOk(code, 'npm ran without raising an error code') 46 t.notOk(stderr, 'no error output') 47 48 common.npm( 49 [ 50 '--registry', common.registry, 51 '--loglevel', 'silent', 52 'dedupe' 53 ], 54 EXEC_OPTS, 55 function (err, code, stdout, stderr) { 56 t.ifError(err, 'npm ran without issue') 57 t.notOk(code, 'npm ran without raising an error code') 58 t.notOk(stderr, 'no error output') 59 60 t.ok(existsSync(path.resolve( 61 minimist, 62 'node_modules', 'optimist' 63 )), 'optimist in place') 64 t.ok(existsSync(path.resolve( 65 minimist, 66 'node_modules', 'minimist' 67 )), 'circular dependency uncircled') 68 t.end() 69 } 70 ) 71 } 72 ) 73}) 74 75test('cleanup', function (t) { 76 server.close() 77 t.end() 78}) 79 80function setup (cb) { 81 mkdirp.sync(minimist) 82 fs.writeFileSync( 83 path.join(minimist, 'package.json'), 84 JSON.stringify(json, null, 2) 85 ) 86 process.chdir(path.resolve(pkg, 'minimist')) 87 88 fs.mkdirSync(path.resolve(pkg, 'minimist/node_modules')) 89 mr({ port: common.port }, function (er, s) { 90 server = s 91 cb() 92 }) 93} 94