summaryrefslogtreecommitdiff
path: root/deps/npm/test/tap/local-args-relative-to-cwd.js
blob: de95516e2893eda6ca05e75e05dd4288cb927abe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
'use strict'
var fs = require('graceful-fs')
var path = require('path')
var test = require('tap').test
var Tacks = require('tacks')
var File = Tacks.File
var Dir = Tacks.Dir
var common = require('../common-tap.js')
var testdir = common.pkg

var fixture = new Tacks(
  Dir({
    example: Dir({
    }),
    mod1: Dir({
      'package.json': File({
        name: 'mod1',
        version: '1.0.0'
      })
    }),
    node_modules: Dir({
    })
  })
)

function setup () {
  fixture.create(testdir)
}

function cleanup () {
  fixture.remove(testdir)
}

test('setup', function (t) {
  cleanup()
  setup()
  t.end()
})

function exists (file) {
  try {
    fs.statSync(file)
    return true
  } catch (ex) {
    return false
  }
}

test('local-args-relative-to-cwd', function (t) {
  var instdir = path.join(testdir, 'example')
  var config = ['--loglevel=error']
  common.npm(config.concat(['install', '../mod1']), {cwd: instdir}, function (err, code, stdout, stderr) {
    if (err) throw err
    t.comment(stdout.trim())
    t.comment(stderr.trim())
    t.is(code, 0, 'install ran ok')
    t.ok(exists(path.join(testdir, 'node_modules', 'mod1')), 'mod1 installed')
    t.end()
  })
})

test('cleanup', function (t) {
  cleanup()
  t.end()
})