]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/test/tap/outdated-local.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / test / tap / outdated-local.js
1 var common = require('../common-tap.js')
2 var test = require('tap').test
3 var npm = require('../../')
4 var rimraf = require('rimraf')
5 var path = require('path')
6 var mr = require('npm-registry-mock')
7 var osenv = require('osenv')
8 var mkdirp = require('mkdirp')
9 var fs = require('graceful-fs')
10
11 var pkg = path.resolve(__dirname, 'outdated-local')
12 var pkgLocal = path.resolve(pkg, 'local-module')
13 var pkgScopedLocal = path.resolve(pkg, 'another-local-module')
14 var pkgLocalUnderscore = path.resolve(pkg, 'underscore')
15 var pkgLocalOptimist = path.resolve(pkg, 'optimist')
16
17 var pjParent = JSON.stringify({
18   name: 'outdated-local',
19   version: '1.0.0',
20   dependencies: {
21     'local-module': 'file:local-module', // updated locally, not on repo
22     '@scoped/another-local-module': 'file:another-local-module', // updated locally, scoped, not on repo
23     'underscore': 'file:underscore', // updated locally, updated but lesser version on repo
24     'optimist': 'file:optimist' // updated locally, updated and greater version on repo
25   }
26 }, null, 2) + '\n'
27
28 var pjLocal = JSON.stringify({
29   name: 'local-module',
30   version: '1.0.0'
31 }, null, 2) + '\n'
32
33 var pjLocalBumped = JSON.stringify({
34   name: 'local-module',
35   version: '1.1.0'
36 }, null, 2) + '\n'
37
38 var pjScopedLocal = JSON.stringify({
39   name: '@scoped/another-local-module',
40   version: '1.0.0'
41 }, null, 2) + '\n'
42
43 var pjScopedLocalBumped = JSON.stringify({
44   name: '@scoped/another-local-module',
45   version: '1.2.0'
46 }, null, 2) + '\n'
47
48 var pjLocalUnderscore = JSON.stringify({
49   name: 'underscore',
50   version: '1.3.1'
51 }, null, 2) + '\n'
52
53 var pjLocalUnderscoreBumped = JSON.stringify({
54   name: 'underscore',
55   version: '1.6.1'
56 }, null, 2) + '\n'
57
58 var pjLocalOptimist = JSON.stringify({
59   name: 'optimist',
60   version: '0.4.0'
61 }, null, 2) + '\n'
62
63 var pjLocalOptimistBumped = JSON.stringify({
64   name: 'optimist',
65   version: '0.5.0'
66 }, null, 2) + '\n'
67
68
69 function mocks (server) {
70   server.get('/local-module')
71     .reply(404)
72   server.get('/@scoped%2fanother-local-module')
73     .reply(404)
74 }
75
76 test('setup', function (t) {
77   bootstrap()
78   t.end()
79 })
80
81 test('outdated support local modules', function (t) {
82   t.plan(4)
83   process.chdir(pkg)
84   mr({ port: common.port, plugin: mocks }, function (err, s) {
85     t.ifError(err, 'mock registry started without problems')
86
87     function verify (actual, expected) {
88       for (var i = 0; i < expected.length; i++) {
89         var current = expected[i]
90
91         var found = false
92         for (var j = 0; j < actual.length; j++) {
93           var target = actual[j]
94
95           var k
96           for (k = 0; k < current.length; k++) {
97             if (current[k] !== target[k]) break
98           }
99           if (k === current.length) found = true
100         }
101
102         if (!found) return false
103       }
104
105       return true
106     }
107
108     npm.load(
109       {
110         loglevel: 'silent',
111         parseable: true,
112         registry: common.registry
113       },
114       function () {
115         npm.install('.', function (err) {
116           t.ifError(err, 'install success')
117           bumpLocalModules()
118           npm.outdated(function (er, d) {
119             t.ifError(er, 'outdated success')
120             t.ok(verify(d, [
121               [
122                 path.resolve(__dirname, 'outdated-local'),
123                 'local-module',
124                 '1.0.0',
125                 '1.1.0',
126                 '1.1.0',
127                 'file:local-module'
128               ],
129               [
130                 path.resolve(__dirname, 'outdated-local'),
131                 '@scoped/another-local-module',
132                 '1.0.0',
133                 '1.2.0',
134                 '1.2.0',
135                 'file:another-local-module'
136               ],
137               [
138                 path.resolve(__dirname, 'outdated-local'),
139                 'underscore',
140                 '1.3.1',
141                 '1.6.1',
142                 '1.5.1',
143                 'file:underscore'
144               ],
145               [
146                 path.resolve(__dirname, 'outdated-local'),
147                 'optimist',
148                 '0.4.0',
149                 '0.6.0',
150                 '0.6.0',
151                 'optimist@0.6.0'
152               ]
153             ]), 'got expected outdated output')
154             s.close()
155           })
156         })
157       }
158     )
159   })
160 })
161
162 test('cleanup', function (t) {
163   cleanup()
164   t.end()
165 })
166
167 function bootstrap () {
168   mkdirp.sync(pkg)
169   fs.writeFileSync(path.resolve(pkg, 'package.json'), pjParent)
170
171   mkdirp.sync(pkgLocal)
172   fs.writeFileSync(path.resolve(pkgLocal, 'package.json'), pjLocal)
173
174   mkdirp.sync(pkgScopedLocal)
175   fs.writeFileSync(path.resolve(pkgScopedLocal, 'package.json'), pjScopedLocal)
176
177   mkdirp.sync(pkgLocalUnderscore)
178   fs.writeFileSync(path.resolve(pkgLocalUnderscore, 'package.json'), pjLocalUnderscore)
179
180   mkdirp.sync(pkgLocalOptimist)
181   fs.writeFileSync(path.resolve(pkgLocalOptimist, 'package.json'), pjLocalOptimist)
182 }
183
184 function bumpLocalModules () {
185   fs.writeFileSync(path.resolve(pkgLocal, 'package.json'), pjLocalBumped)
186   fs.writeFileSync(path.resolve(pkgScopedLocal, 'package.json'), pjScopedLocalBumped)
187   fs.writeFileSync(path.resolve(pkgLocalUnderscore, 'package.json'), pjLocalUnderscoreBumped)
188   fs.writeFileSync(path.resolve(pkgLocalOptimist, 'package.json'), pjLocalOptimistBumped)
189 }
190
191 function cleanup () {
192   process.chdir(osenv.tmpdir())
193   rimraf.sync(pkg)
194 }