summaryrefslogtreecommitdiff
path: root/deps/npm/test/tap/install-scoped-link.js
blob: a0c9c61a9843ce6e9a4f9fa91f09de5cffe38c06 (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
66
67
68
69
70
71
72
73
var exec = require('child_process').exec
var fs = require('graceful-fs')
var path = require('path')
var existsSync = fs.existsSync || path.existsSync

var mkdirp = require('mkdirp')
var test = require('tap').test

var escapeExecPath = require('../../lib/utils/escape-exec-path')

var common = require('../common-tap.js')

var resolve = require('path').resolve
var pkg = resolve(common.pkg, 'package')
var work = resolve(common.pkg, 'TEST')
var modules = path.join(work, 'node_modules')

var EXEC_OPTS = { cwd: work }

var world = '#!/usr/bin/env node\nconsole.log("hello blrbld")\n'

var json = {
  name: '@scoped/package',
  version: '0.0.0',
  bin: {
    hello: './world.js'
  }
}

test('setup', function (t) {
  mkdirp.sync(pkg)
  fs.writeFileSync(
    path.join(pkg, 'package.json'),
    JSON.stringify(json, null, 2)
  )
  fs.writeFileSync(path.join(pkg, 'world.js'), world)

  mkdirp.sync(modules)
  process.chdir(work)

  t.end()
})

test('installing package with links', function (t) {
  common.npm(
    [
      '--loglevel', 'silent',
      'install', pkg
    ],
    EXEC_OPTS,
    function (err, code) {
      t.ifError(err, 'install ran to completion without error')
      t.notOk(code, 'npm install exited with code 0')

      t.ok(
        existsSync(path.join(modules, '@scoped', 'package', 'package.json')),
        'package installed'
      )
      t.ok(existsSync(path.join(modules, '.bin')), 'binary link directory exists')

      var hello = path.join(modules, '.bin', 'hello')
      t.ok(existsSync(hello), 'binary link exists')

      exec(escapeExecPath(hello), function (err, stdout, stderr) {
        t.ifError(err, 'command ran fine')
        t.notOk(stderr, 'got no error output back')
        t.equal(stdout, 'hello blrbld\n', 'output was as expected')

        t.end()
      })
    }
  )
})