|
| 1 | +var fs = require('graceful-fs') |
| 2 | +var path = require('path') |
| 3 | + |
| 4 | +var mkdirp = require('mkdirp') |
| 5 | +var osenv = require('osenv') |
| 6 | +var rimraf = require('rimraf') |
| 7 | +var test = require('tap').test |
| 8 | + |
| 9 | +var common = require('../common-tap.js') |
| 10 | + |
| 11 | +var pkg = common.pkg |
| 12 | + |
| 13 | +var EXEC_OPTS = { cwd: pkg, stdio: [0, 1, 2] } |
| 14 | + |
| 15 | +var localDependencyJson = { |
| 16 | + name: 'local-dependency', |
| 17 | + version: '0.0.0', |
| 18 | + dependencies: { |
| 19 | + underscore: '1.5.1' |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +var dependentJson = { |
| 24 | + name: 'dependent', |
| 25 | + version: '0.0.0', |
| 26 | + dependencies: { |
| 27 | + 'local-dependency': '../local-dependency' |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +var target = path.resolve(pkg, '../local-dependency') |
| 32 | + |
| 33 | +test('setup', function (t) { |
| 34 | + cleanup() |
| 35 | + t.end() |
| 36 | +}) |
| 37 | + |
| 38 | +test('\'npm install\' should install local pkg from sub path', function (t) { |
| 39 | + setup() |
| 40 | + common.npm(['install', '--loglevel=silent'], EXEC_OPTS, function (err, code) { |
| 41 | + if (err) throw err |
| 42 | + t.equal(code, 0, 'npm install exited with code') |
| 43 | + t.ok(fs.statSync(path.resolve(pkg, 'node_modules/local-dependency/package.json')).isFile(), 'local dependency package.json exists') |
| 44 | + t.ok(fs.statSync(path.resolve(pkg, 'node_modules/local-dependency/node_modules/underscore')).isDirectory(), 'transitive dependency installed') |
| 45 | + t.end() |
| 46 | + }) |
| 47 | +}) |
| 48 | + |
| 49 | +test('\'npm ci\' should work', function (t) { |
| 50 | + common.npm(['ci', '--loglevel=silent'], EXEC_OPTS, function (err, code) { |
| 51 | + if (err) throw err |
| 52 | + t.equal(code, 0, 'npm install exited with code') |
| 53 | + t.ok(fs.statSync(path.resolve(pkg, 'node_modules/local-dependency/package.json')).isFile(), 'local dependency package.json exists') |
| 54 | + t.ok(fs.statSync(path.resolve(pkg, 'node_modules/local-dependency/node_modules/underscore')).isDirectory(), 'transitive dependency installed') |
| 55 | + t.end() |
| 56 | + }) |
| 57 | +}) |
| 58 | + |
| 59 | +test('cleanup', function (t) { |
| 60 | + cleanup() |
| 61 | + t.end() |
| 62 | +}) |
| 63 | + |
| 64 | +function cleanup () { |
| 65 | + process.chdir(osenv.tmpdir()) |
| 66 | + rimraf.sync(pkg) |
| 67 | + rimraf.sync(target) |
| 68 | +} |
| 69 | + |
| 70 | +function setup () { |
| 71 | + cleanup() |
| 72 | + mkdirp.sync(target) |
| 73 | + fs.writeFileSync( |
| 74 | + path.join(target, 'package.json'), |
| 75 | + JSON.stringify(localDependencyJson, null, 2) |
| 76 | + ) |
| 77 | + mkdirp.sync(pkg) |
| 78 | + fs.writeFileSync( |
| 79 | + path.join(pkg, 'package.json'), |
| 80 | + JSON.stringify(dependentJson, null, 2) |
| 81 | + ) |
| 82 | + process.chdir(pkg) |
| 83 | +} |
0 commit comments