summaryrefslogtreecommitdiff
path: root/deps/npm/test/tap/shrinkwrap-prod-dependency-also.js
blob: d3e86fcd659c18261e0773c5b39d4455126676e8 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
var fs = require('fs')
var path = require('path')

var mkdirp = require('mkdirp')
var mr = require('npm-registry-mock')
var osenv = require('osenv')
var rimraf = require('rimraf')
var test = require('tap').test

var common = require('../common-tap.js')
var pkg = path.resolve(__dirname, path.basename(__filename, '.js'))
var opts = [
  '--cache=' + path.resolve(pkg, 'cache'),
  '--registry=' + common.registry
]

function reportOutput (t, fh, out) {
  var trimmed = out.trim()
  if (!trimmed.length) return
  var prefix = fh + '> '
  t.comment(prefix + trimmed.split(/\n/).join('\n' + prefix))
}

var server
test("shrinkwrap --also=development doesn't strip out prod dependencies", function (t) {
  t.plan(4)

  mr({port: common.port}, function (er, s) {
    server = s
    setup()
    common.npm(['install', '.'].concat(opts), {cwd: pkg}, function (err, code, stdout, stderr) {
      if (err) return t.fail(err)
      t.is(code, 0, 'install')
      reportOutput(t, 'out', stdout)
      reportOutput(t, 'err', stderr)
      common.npm(['shrinkwrap', '--also=development'].concat(opts), {cwd: pkg}, function (err, code, stdout, stderr) {
        if (err) return t.fail(err)
        var ok = t.is(code, 0, 'shrinkwrap')
        reportOutput(t, 'out', stdout)
        reportOutput(t, 'err', stderr)
        if (ok) {
          try {
            var results = JSON.parse(fs.readFileSync(path.join(pkg, 'npm-shrinkwrap.json')))
            t.pass('read shrinkwrap')
          } catch (ex) {
            t.ifError(ex, 'read shrinkwrap')
          }
        }
        t.deepEqual(results, desired, 'results have dev dep')
        s.done()
        t.end()
      })
    })
  })
})

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

var desired = {
  name: 'npm-test-shrinkwrap-prod-dependency',
  version: '0.0.0',
  dependencies: {
    request: {
      version: '0.9.0',
      from: 'request@0.9.0',
      resolved: common.registry + '/request/-/request-0.9.0.tgz'
    },
    underscore: {
      dev: true,
      version: '1.5.1',
      from: 'underscore@1.5.1',
      resolved: common.registry + '/underscore/-/underscore-1.5.1.tgz'
    }
  }
}

var json = {
  author: 'Domenic Denicola',
  name: 'npm-test-shrinkwrap-prod-dependency',
  version: '0.0.0',
  dependencies: {
    request: '0.9.0'
  },
  devDependencies: {
    underscore: '1.5.1'
  }
}

function setup (opts) {
  cleanup()
  mkdirp.sync(pkg)
  fs.writeFileSync(path.join(pkg, 'package.json'), JSON.stringify(json, null, 2))
}

function cleanup () {
  process.chdir(osenv.tmpdir())
  rimraf.sync(pkg)
}