• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.js')
8
9var pkg = path.resolve(common.pkg, 'package')
10
11var EXEC_OPTS = { cwd: pkg, stdio: [0, 1, 2] }
12
13var json = {
14  name: 'install-at-sub-path-locally-mock',
15  version: '0.0.0'
16}
17
18var target = '../package@1.2.3'
19
20test('setup', function (t) {
21  var root = path.resolve(pkg, target)
22  mkdirp.sync(root)
23  fs.writeFileSync(
24    path.join(root, 'package.json'),
25    JSON.stringify(json, null, 2)
26  )
27  mkdirp.sync(path.resolve(pkg, 'node_modules'))
28  t.end()
29})
30
31test('\'npm install ../package@1.2.3\' should install local pkg from sub path', function (t) {
32  common.npm(['install', '--loglevel=silent', target], EXEC_OPTS, function (err, code) {
33    if (err) throw err
34    var p = path.resolve(pkg, 'node_modules/install-at-sub-path-locally-mock/package.json')
35    t.equal(code, 0, 'npm install exited with code')
36    t.ok(JSON.parse(fs.readFileSync(p, 'utf8')))
37    t.end()
38  })
39})
40
41test('\'running npm install ../package@1.2.3\' should not break on sub path re-install', function (t) {
42  common.npm(['install', '--loglevel=silent', target], EXEC_OPTS, function (err, code) {
43    if (err) throw err
44    var p = path.resolve(pkg, 'node_modules/install-at-sub-path-locally-mock/package.json')
45    t.equal(code, 0, 'npm install exited with code')
46    t.ok(JSON.parse(fs.readFileSync(p, 'utf8')))
47    t.end()
48  })
49})
50