2 var path = require('path')
4 var mkdirp = require('mkdirp')
5 var mr = require('npm-registry-mock')
6 var osenv = require('osenv')
7 var rimraf = require('rimraf')
8 var test = require('tap').test
10 var common = require('../common-tap.js')
13 var pkg = path.join(__dirname, 'install-save-prefix')
15 var EXEC_OPTS = { cwd: pkg }
18 name: 'install-save-prefix',
22 test('setup', function (t) {
24 mr({ port: common.port }, function (er, s) {
25 t.ifError(er, 'started mock registry')
31 test('install --save with \'^\' save prefix should accept minor updates', function (t) {
34 '--registry', common.registry,
35 '--loglevel', 'silent',
38 'install', 'underscore@latest'
41 function (err, code) {
42 t.ifError(err, 'npm install ran without issue')
43 t.notOk(code, 'npm install exited with code 0')
45 var p = path.join(pkg, 'node_modules', 'underscore', 'package.json')
46 t.ok(JSON.parse(fs.readFileSync(p)))
48 var pkgJson = JSON.parse(fs.readFileSync(
49 path.join(pkg, 'package.json'),
54 { 'underscore': '^1.5.1' },
55 'got expected save prefix and version of 1.5.1'
62 test('install --save-dev with \'^\' save prefix should accept minor dev updates', function (t) {
66 '--registry', common.registry,
67 '--loglevel', 'silent',
70 'install', 'underscore@1.3.1'
73 function (err, code) {
74 t.ifError(err, 'npm install ran without issue')
75 t.notOk(code, 'npm install exited with code 0')
77 var p = path.join(pkg, 'node_modules', 'underscore', 'package.json')
78 t.ok(JSON.parse(fs.readFileSync(p)))
80 var pkgJson = JSON.parse(fs.readFileSync(
81 path.join(pkg, 'package.json'),
85 pkgJson.devDependencies,
86 { 'underscore': '^1.3.1' },
87 'got expected save prefix and version of 1.3.1'
94 test('install --save with \'~\' save prefix should accept patch updates', function (t) {
98 '--registry', common.registry,
99 '--loglevel', 'silent',
100 '--save-prefix', '~',
102 'install', 'underscore@1.3.1'
105 function (err, code) {
106 t.ifError(err, 'npm install ran without issue')
107 t.notOk(code, 'npm install exited with code 0')
109 var p = path.join(pkg, 'node_modules', 'underscore', 'package.json')
110 t.ok(JSON.parse(fs.readFileSync(p)))
112 var pkgJson = JSON.parse(fs.readFileSync(
113 path.join(pkg, 'package.json'),
117 pkgJson.dependencies,
118 { 'underscore': '~1.3.1' },
119 'got expected save prefix and version of 1.3.1'
126 test('install --save-dev with \'~\' save prefix should accept patch updates', function (t) {
130 '--registry', common.registry,
131 '--loglevel', 'silent',
132 '--save-prefix', '~',
134 'install', 'underscore@1.3.1'
137 function (err, code) {
138 t.ifError(err, 'npm install ran without issue')
139 t.notOk(code, 'npm install exited with code 0')
141 var p = path.join(pkg, 'node_modules', 'underscore', 'package.json')
142 t.ok(JSON.parse(fs.readFileSync(p)))
144 var pkgJson = JSON.parse(fs.readFileSync(
145 path.join(pkg, 'package.json'),
149 pkgJson.devDependencies,
150 { 'underscore': '~1.3.1' },
151 'got expected save prefix and version of 1.3.1'
158 test('cleanup', function (t) {
164 function cleanup () {
165 process.chdir(osenv.tmpdir())
171 mkdirp.sync(path.resolve(pkg, 'node_modules'))
173 path.join(pkg, 'package.json'),
174 JSON.stringify(json, null, 2)