]> 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-exact.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-exact.js
1 var fs = require('graceful-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-exact')
14
15 var EXEC_OPTS = { cwd: pkg }
16
17 var json = {
18   name: 'install-save-exact',
19   version: '0.0.1',
20   description: 'fixture'
21 }
22
23 test('setup', function (t) {
24   setup()
25   mr({ port: common.port }, function (er, s) {
26     server = s
27     t.end()
28   })
29 })
30
31 test('\'npm install --save --save-exact\' should install local pkg', function (t) {
32   common.npm(
33     [
34       '--loglevel', 'silent',
35       '--registry', common.registry,
36       '--save',
37       '--save-exact',
38       'install', 'underscore@1.3.1'
39     ],
40     EXEC_OPTS,
41     function (err, code) {
42       t.ifError(err, 'npm ran without issue')
43       t.notOk(code, 'npm install exited without raising an error code')
44
45       var p = path.resolve(pkg, 'node_modules/underscore/package.json')
46       t.ok(JSON.parse(fs.readFileSync(p)))
47
48       p = path.resolve(pkg, 'package.json')
49       var pkgJson = JSON.parse(fs.readFileSync(p, 'utf8'))
50
51       t.same(
52         pkgJson.dependencies,
53         { 'underscore': '1.3.1' },
54         'underscore dependency should specify exactly 1.3.1'
55       )
56
57       t.end()
58     }
59   )
60 })
61
62 test('\'npm install --save-dev --save-exact\' should install local pkg', function (t) {
63   setup()
64
65   common.npm(
66     [
67       '--loglevel', 'silent',
68       '--registry', common.registry,
69       '--save-dev',
70       '--save-exact',
71       'install', 'underscore@1.3.1'
72     ],
73     EXEC_OPTS,
74     function (err, code) {
75       t.ifError(err, 'npm ran without issue')
76       t.notOk(code, 'npm install exited without raising an error code')
77
78       var p = path.resolve(pkg, 'node_modules/underscore/package.json')
79       t.ok(JSON.parse(fs.readFileSync(p)))
80
81       p = path.resolve(pkg, 'package.json')
82       var pkgJson = JSON.parse(fs.readFileSync(p, 'utf8'))
83
84       t.same(
85         pkgJson.devDependencies,
86         { 'underscore': '1.3.1' },
87         'underscore dependency should specify exactly 1.3.1'
88       )
89
90       t.end()
91     }
92   )
93 })
94
95 test('cleanup', function (t) {
96   server.close()
97   cleanup()
98   t.end()
99 })
100
101 function cleanup () {
102   process.chdir(osenv.tmpdir())
103   rimraf.sync(pkg)
104 }
105
106 function setup () {
107   cleanup()
108   mkdirp.sync(path.resolve(pkg, 'node_modules'))
109   fs.writeFileSync(
110     path.join(pkg, 'package.json'),
111     JSON.stringify(json, null, 2)
112   )
113   process.chdir(pkg)
114 }