]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/test/tap/install-save-prefix.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / test / tap / install-save-prefix.js
1 var fs = require('fs')
2 var path = require('path')
3
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
9
10 var common = require('../common-tap.js')
11 var server
12
13 var pkg = path.join(__dirname, 'install-save-prefix')
14
15 var EXEC_OPTS = { cwd: pkg }
16
17 var json = {
18   name: 'install-save-prefix',
19   version: '0.0.1'
20 }
21
22 test('setup', function (t) {
23   setup()
24   mr({ port: common.port }, function (er, s) {
25     t.ifError(er, 'started mock registry')
26     server = s
27     t.end()
28   })
29 })
30
31 test('install --save with \'^\' save prefix should accept minor updates', function (t) {
32   common.npm(
33     [
34       '--registry', common.registry,
35       '--loglevel', 'silent',
36       '--save-prefix', '^',
37       '--save',
38       'install', 'underscore@latest'
39     ],
40     EXEC_OPTS,
41     function (err, code) {
42       t.ifError(err, 'npm install ran without issue')
43       t.notOk(code, 'npm install exited with code 0')
44
45       var p = path.join(pkg, 'node_modules', 'underscore', 'package.json')
46       t.ok(JSON.parse(fs.readFileSync(p)))
47
48       var pkgJson = JSON.parse(fs.readFileSync(
49         path.join(pkg, 'package.json'),
50         'utf8'
51       ))
52       t.deepEqual(
53         pkgJson.dependencies,
54         { 'underscore': '^1.5.1' },
55         'got expected save prefix and version of 1.5.1'
56       )
57       t.end()
58     }
59   )
60 })
61
62 test('install --save-dev with \'^\' save prefix should accept minor dev updates', function (t) {
63   setup()
64   common.npm(
65     [
66       '--registry', common.registry,
67       '--loglevel', 'silent',
68       '--save-prefix', '^',
69       '--save-dev',
70       'install', 'underscore@1.3.1'
71     ],
72     EXEC_OPTS,
73     function (err, code) {
74       t.ifError(err, 'npm install ran without issue')
75       t.notOk(code, 'npm install exited with code 0')
76
77       var p = path.join(pkg, 'node_modules', 'underscore', 'package.json')
78       t.ok(JSON.parse(fs.readFileSync(p)))
79
80       var pkgJson = JSON.parse(fs.readFileSync(
81         path.join(pkg, 'package.json'),
82         'utf8'
83       ))
84       t.deepEqual(
85         pkgJson.devDependencies,
86         { 'underscore': '^1.3.1' },
87         'got expected save prefix and version of 1.3.1'
88       )
89       t.end()
90     }
91   )
92 })
93
94 test('install --save with \'~\' save prefix should accept patch updates', function (t) {
95   setup()
96   common.npm(
97     [
98       '--registry', common.registry,
99       '--loglevel', 'silent',
100       '--save-prefix', '~',
101       '--save',
102       'install', 'underscore@1.3.1'
103     ],
104     EXEC_OPTS,
105     function (err, code) {
106       t.ifError(err, 'npm install ran without issue')
107       t.notOk(code, 'npm install exited with code 0')
108
109       var p = path.join(pkg, 'node_modules', 'underscore', 'package.json')
110       t.ok(JSON.parse(fs.readFileSync(p)))
111
112       var pkgJson = JSON.parse(fs.readFileSync(
113         path.join(pkg, 'package.json'),
114         'utf8'
115       ))
116       t.deepEqual(
117         pkgJson.dependencies,
118         { 'underscore': '~1.3.1' },
119         'got expected save prefix and version of 1.3.1'
120       )
121       t.end()
122     }
123   )
124 })
125
126 test('install --save-dev with \'~\' save prefix should accept patch updates', function (t) {
127   setup()
128   common.npm(
129     [
130       '--registry', common.registry,
131       '--loglevel', 'silent',
132       '--save-prefix', '~',
133       '--save-dev',
134       'install', 'underscore@1.3.1'
135     ],
136     EXEC_OPTS,
137     function (err, code) {
138       t.ifError(err, 'npm install ran without issue')
139       t.notOk(code, 'npm install exited with code 0')
140
141       var p = path.join(pkg, 'node_modules', 'underscore', 'package.json')
142       t.ok(JSON.parse(fs.readFileSync(p)))
143
144       var pkgJson = JSON.parse(fs.readFileSync(
145         path.join(pkg, 'package.json'),
146         'utf8'
147       ))
148       t.deepEqual(
149         pkgJson.devDependencies,
150         { 'underscore': '~1.3.1' },
151         'got expected save prefix and version of 1.3.1'
152       )
153       t.end()
154     }
155   )
156 })
157
158 test('cleanup', function (t) {
159   server.close()
160   cleanup()
161   t.end()
162 })
163
164 function cleanup () {
165   process.chdir(osenv.tmpdir())
166   rimraf.sync(pkg)
167 }
168
169 function setup () {
170   cleanup()
171   mkdirp.sync(path.resolve(pkg, 'node_modules'))
172   fs.writeFileSync(
173     path.join(pkg, 'package.json'),
174     JSON.stringify(json, null, 2)
175   )
176
177   process.chdir(pkg)
178 }