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