• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1var fs = require('fs')
2var path = require('path')
3
4var mkdirp = require('mkdirp')
5var mr = require('npm-registry-mock')
6var test = require('tap').test
7
8var common = require('../common-tap.js')
9
10var pkg = common.pkg
11
12var EXEC_OPTS = { cwd: pkg }
13
14var PACKAGE_JSON1 = {
15  name: 'install-noargs-dev',
16  version: '0.0.1',
17  devDependencies: {
18    'underscore': '1.3.1'
19  }
20}
21
22var PACKAGE_JSON2 = {
23  name: 'install-noargs-dev',
24  version: '0.0.2',
25  devDependencies: {
26    'underscore': '1.5.1'
27  }
28}
29
30test('setup', function (t) {
31  mkdirp.sync(path.resolve(pkg, 'node_modules'))
32  fs.writeFileSync(
33    path.join(pkg, 'package.json'),
34    JSON.stringify(PACKAGE_JSON1, null, 2)
35  )
36  mr({ port: common.port }, function (er, s) {
37    t.ifError(er, 'started mock registry')
38    t.parent.teardown(() => s.close())
39    t.end()
40  })
41})
42
43test('install noargs installs devDependencies', function (t) {
44  common.npm(
45    [
46      '--registry', common.registry,
47      '--loglevel', 'silent',
48      '--no-save',
49      'install'
50    ],
51    EXEC_OPTS,
52    function (err, code) {
53      t.ifError(err, 'npm install ran without issue')
54      t.notOk(code, 'npm install exited with code 0')
55
56      var p = path.join(pkg, 'node_modules', 'underscore', 'package.json')
57      var pkgJson = JSON.parse(fs.readFileSync(p))
58
59      t.equal(pkgJson.version, '1.3.1')
60      t.end()
61    }
62  )
63})
64
65test('install noargs installs updated devDependencies', function (t) {
66  fs.writeFileSync(
67    path.join(pkg, 'package.json'),
68    JSON.stringify(PACKAGE_JSON2, null, 2)
69  )
70
71  common.npm(
72    [
73      '--registry', common.registry,
74      '--loglevel', 'silent',
75      '--no-save',
76      'install'
77    ],
78    EXEC_OPTS,
79    function (err, code) {
80      t.ifError(err, 'npm install ran without issue')
81      t.notOk(code, 'npm install exited with code 0')
82
83      var p = path.join(pkg, 'node_modules', 'underscore', 'package.json')
84      var pkgJson = JSON.parse(fs.readFileSync(p))
85
86      t.equal(pkgJson.version, '1.5.1')
87      t.end()
88    }
89  )
90})
91