summaryrefslogtreecommitdiff
path: root/deps/npm/test/tap/shrinkwrap-save-dev-without-existing-dev-deps.js
blob: 436b17895a48383961e6aedbc3ad53e4f0eb5cc9 (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
var fs = require('fs')
var path = require('path')

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

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

var base = path.resolve(__dirname, path.basename(__filename, '.js'))
var installme = path.join(base, 'installme')
var installme_pkg = path.join(installme, 'package.json')
var example = path.join(base, 'example')
var example_shrinkwrap = path.join(example, 'npm-shrinkwrap.json')
var example_pkg = path.join(example, 'package.json')
var installed = path.join(example, 'node_modules', 'installed')
var installed_pkg = path.join(installed, 'package.json')

var EXEC_OPTS = { cwd: example }

var installme_pkg_json = {
  name: 'installme',
  version: '1.0.0',
  dependencies: {}
}

var example_pkg_json = {
  name: 'example',
  version: '1.0.0',
  dependencies: {
    'installed': '1.0'
  },
  devDependencies: {}
}

var example_shrinkwrap_json = {
  name: 'example',
  version: '1.0.0',
  dependencies: {
    installed: {
      version: '1.0.0'
    }
  }
}

var installed_pkg_json = {
  _id: 'installed@1.0.0',
  name: 'installed',
  version: '1.0.0'
}

function writeJson (filename, obj) {
  mkdirp.sync(path.dirname(filename))
  fs.writeFileSync(filename, JSON.stringify(obj, null, 2))
}

test('setup', function (t) {
  cleanup()
  writeJson(installme_pkg, installme_pkg_json)
  writeJson(example_pkg, example_pkg_json)
  writeJson(example_shrinkwrap, example_shrinkwrap_json)
  writeJson(installed_pkg, installed_pkg_json)
  t.end()
})

test('install --save-dev leaves dev deps alone', function (t) {
  common.npm(['install', '--save-dev', 'file://' + installme], EXEC_OPTS, function (er, code, stdout, stderr) {
    t.ifError(er, "spawn didn't catch fire")
    t.is(code, 0, 'install completed ok')
    t.is(stderr, '', 'install completed without error output')
    var shrinkwrap = JSON.parse(fs.readFileSync(example_shrinkwrap))
    t.ok(shrinkwrap.dependencies.installed, "save-dev new install didn't remove dep")
    t.notOk(shrinkwrap.dependencies.installme, 'save-dev new install DID NOT add new dev dep')
    t.end()
  })
})

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

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