1var fs = require('graceful-fs') 2var path = require('path') 3 4var mkdirp = require('mkdirp') 5var test = require('tap').test 6 7var common = require('../common-tap') 8 9var root = common.pkg 10var pkg = path.join(root, 'package-with-local-paths') 11 12var EXEC_OPTS = { cwd: pkg } 13 14var localPaths = { 15 name: 'package-with-local-paths', 16 version: '0.0.0', 17 dependencies: { 18 'package-local-dependency': 'file:../package-local-dependency' 19 }, 20 devDependencies: { 21 'package-local-dev-dependency': 'file:../package-local-dev-dependency' 22 } 23} 24 25var localDependency = { 26 name: 'package-local-dependency', 27 version: '0.0.0', 28 description: 'Test for local installs' 29} 30 31var localDevDependency = { 32 name: 'package-local-dev-dependency', 33 version: '0.0.0', 34 description: 'Test for local installs' 35} 36 37test('setup', function (t) { 38 mkdirp.sync(pkg) 39 fs.writeFileSync( 40 path.join(pkg, 'package.json'), 41 JSON.stringify(localPaths, null, 2) 42 ) 43 44 mkdirp.sync(path.join(root, 'package-local-dependency')) 45 fs.writeFileSync( 46 path.join(root, 'package-local-dependency', 'package.json'), 47 JSON.stringify(localDependency, null, 2) 48 ) 49 50 mkdirp.sync(path.join(root, 'package-local-dev-dependency')) 51 fs.writeFileSync( 52 path.join(root, 'package-local-dev-dependency', 'package.json'), 53 JSON.stringify(localDevDependency, null, 2) 54 ) 55 56 process.chdir(pkg) 57 t.end() 58}) 59 60test('\'npm install\' should install local packages', function (t) { 61 common.npm( 62 [ 63 'install', '.' 64 ], 65 EXEC_OPTS, 66 function (err, code) { 67 t.ifError(err, 'error should not exist') 68 t.notOk(code, 'npm install exited with code 0') 69 var dependencyPackageJson = path.resolve( 70 pkg, 71 'node_modules/package-local-dependency/package.json' 72 ) 73 t.ok( 74 JSON.parse(fs.readFileSync(dependencyPackageJson, 'utf8')), 75 'package with local dependency installed' 76 ) 77 78 var devDependencyPackageJson = path.resolve( 79 pkg, 'node_modules/package-local-dev-dependency/package.json' 80 ) 81 t.ok( 82 JSON.parse(fs.readFileSync(devDependencyPackageJson, 'utf8')), 83 'package with local dev dependency installed' 84 ) 85 86 t.end() 87 } 88 ) 89}) 90