]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/test/tap/view.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / test / tap / view.js
1 var common = require("../common-tap.js")
2 var test = require("tap").test
3 var osenv = require("osenv")
4 var path = require("path")
5 var fs = require("fs")
6 var rimraf = require("rimraf")
7 var mkdirp = require("mkdirp")
8 var tmp = osenv.tmpdir()
9 var t1dir = path.resolve(tmp, "view-local-no-pkg")
10 var t2dir = path.resolve(tmp, "view-local-notmine")
11 var t3dir = path.resolve(tmp, "view-local-mine")
12 var mr = require("npm-registry-mock")
13
14 test("setup", function (t) {
15   mkdirp.sync(t1dir)
16   mkdirp.sync(t2dir)
17   mkdirp.sync(t3dir)
18
19   fs.writeFileSync(t2dir + "/package.json", JSON.stringify({
20     author: "Evan Lucas"
21   , name: "test-repo-url-https"
22   , version: "0.0.1"
23   }), "utf8")
24
25   fs.writeFileSync(t3dir + "/package.json", JSON.stringify({
26     author: "Evan Lucas"
27   , name: "biscuits"
28   , version: "0.0.1"
29   }), "utf8")
30
31   t.pass("created fixtures")
32   t.end()
33 })
34
35 function plugin (server) {
36   server
37     .get("/biscuits")
38     .many()
39     .reply(404, {"error": "version not found"})
40 }
41
42 test("npm view . in global mode", function (t) {
43   process.chdir(t1dir)
44   common.npm([
45     "view"
46   , "."
47   , "--registry=" + common.registry
48   , "--global"
49   ], { cwd: t1dir }, function (err, code, stdout, stderr) {
50     t.ifError(err, "view command finished successfully")
51     t.equal(code, 1, "exit not ok")
52     t.similar(stderr, /Cannot use view command in global mode./m)
53     t.end()
54   })
55 })
56
57 test("npm view --global", function(t) {
58   process.chdir(t1dir)
59   common.npm([
60     "view"
61   , "--registry=" + common.registry
62   , "--global"
63   ], { cwd: t1dir }, function(err, code, stdout, stderr) {
64     t.ifError(err, "view command finished successfully")
65     t.equal(code, 1, "exit not ok")
66     t.similar(stderr, /Cannot use view command in global mode./m)
67     t.end()
68   })
69 })
70
71 test("npm view . with no package.json", function(t) {
72   process.chdir(t1dir)
73   common.npm([
74     "view"
75   , "."
76   , "--registry=" + common.registry
77   ], { cwd: t1dir }, function (err, code, stdout, stderr) {
78     t.ifError(err, "view command finished successfully")
79     t.equal(code, 1, "exit not ok")
80     t.similar(stderr, /Invalid package.json/m)
81     t.end()
82   })
83 })
84
85 test("npm view . with no published package", function (t) {
86   process.chdir(t3dir)
87   mr({port : common.port, plugin : plugin}, function (er, s) {
88     common.npm([
89       "view"
90     , "."
91     , "--registry=" + common.registry
92     ], { cwd: t3dir }, function (err, code, stdout, stderr) {
93       t.ifError(err, "view command finished successfully")
94       t.equal(code, 1, "exit not ok")
95       t.similar(stderr, /version not found/m)
96       s.close()
97       t.end()
98     })
99   })
100 })
101
102 test("npm view .", function (t) {
103   process.chdir(t2dir)
104   mr({port : common.port, plugin : plugin}, function (er, s) {
105     common.npm([
106       "view"
107     , "."
108     , "--registry=" + common.registry
109     ], { cwd: t2dir }, function (err, code, stdout) {
110       t.ifError(err, "view command finished successfully")
111       t.equal(code, 0, "exit ok")
112       var re = new RegExp("name: 'test-repo-url-https'")
113       t.similar(stdout, re)
114       s.close()
115       t.end()
116     })
117   })
118 })
119
120 test("npm view . select fields", function (t) {
121   process.chdir(t2dir)
122   mr({port : common.port, plugin : plugin}, function (er, s) {
123     common.npm([
124       "view"
125     , "."
126     , "main"
127     , "--registry=" + common.registry
128     ], { cwd: t2dir }, function (err, code, stdout) {
129       t.ifError(err, "view command finished successfully")
130       t.equal(code, 0, "exit ok")
131       t.equal(stdout.trim(), "index.js", "should print `index.js`")
132       s.close()
133       t.end()
134     })
135   })
136 })
137
138 test("npm view .@<version>", function (t) {
139   process.chdir(t2dir)
140   mr({port : common.port, plugin : plugin}, function (er, s) {
141     common.npm([
142       "view"
143     , ".@0.0.0"
144     , "version"
145     , "--registry=" + common.registry
146     ], { cwd: t2dir }, function (err, code, stdout) {
147       t.ifError(err, "view command finished successfully")
148       t.equal(code, 0, "exit ok")
149       t.equal(stdout.trim(), "0.0.0", "should print `0.0.0`")
150       s.close()
151       t.end()
152     })
153   })
154 })
155
156 test("npm view .@<version> --json", function (t) {
157   process.chdir(t2dir)
158   mr({port : common.port, plugin : plugin}, function (er, s) {
159     common.npm([
160       "view"
161     , ".@0.0.0"
162     , "version"
163     , "--json"
164     , "--registry=" + common.registry
165     ], { cwd: t2dir }, function (err, code, stdout) {
166       t.ifError(err, "view command finished successfully")
167       t.equal(code, 0, "exit ok")
168       t.equal(stdout.trim(), "\"0.0.0\"", "should print `\"0.0.0\"`")
169       s.close()
170       t.end()
171     })
172   })
173 })
174
175 test("npm view <package name>", function (t) {
176   mr({port : common.port, plugin : plugin}, function (er, s) {
177     common.npm([
178       "view"
179     , "underscore"
180     , "--registry=" + common.registry
181     ], { cwd: t2dir }, function (err, code, stdout) {
182       t.ifError(err, "view command finished successfully")
183       t.equal(code, 0, "exit ok")
184       var re = new RegExp("name: 'underscore'")
185       t.similar(stdout, re, "should have name `underscore`")
186       s.close()
187       t.end()
188     })
189   })
190 })
191
192 test("npm view <package name> --global", function(t) {
193   mr({port : common.port, plugin : plugin}, function (er, s) {
194     common.npm([
195       "view"
196     , "underscore"
197     , "--global"
198     , "--registry=" + common.registry
199     ], { cwd: t2dir }, function(err, code, stdout) {
200       t.ifError(err, "view command finished successfully")
201       t.equal(code, 0, "exit ok")
202       var re = new RegExp("name: 'underscore'")
203       t.similar(stdout, re, "should have name `underscore`")
204       s.close()
205       t.end()
206     })
207   })
208 })
209
210 test("npm view <package name> --json", function(t) {
211   t.plan(3)
212   mr({port : common.port, plugin : plugin}, function (er, s) {
213     common.npm([
214       "view"
215     , "underscore"
216     , "--json"
217     , "--registry=" + common.registry
218     ], { cwd: t2dir }, function (err, code, stdout) {
219       t.ifError(err, "view command finished successfully")
220       t.equal(code, 0, "exit ok")
221       s.close()
222       try {
223         var out = JSON.parse(stdout.trim())
224         t.similar(out, {
225           maintainers: "jashkenas <jashkenas@gmail.com>"
226         }, "should have the same maintainer")
227       }
228       catch (er) {
229         t.fail("Unable to parse JSON")
230       }
231     })
232   })
233 })
234
235 test("npm view <package name> <field>", function (t) {
236   mr({port : common.port, plugin : plugin}, function (er, s) {
237     common.npm([
238       "view"
239     , "underscore"
240     , "homepage"
241     , "--registry=" + common.registry
242     ], { cwd: t2dir }, function (err, code, stdout) {
243       t.ifError(err, "view command finished successfully")
244       t.equal(code, 0, "exit ok")
245       t.equal(stdout.trim(), "http://underscorejs.org",
246         "homepage should equal `http://underscorejs.org`")
247       s.close()
248       t.end()
249     })
250   })
251 })
252
253 test("npm view with invalid package name", function (t) {
254   var invalidName = "InvalidPackage"
255       obj = {}
256   obj["/" + invalidName] = [404, {"error": "not found"}]
257
258   mr({port : common.port, mocks: {"get": obj}}, function (er, s) {
259     common.npm([
260       "view"
261     , invalidName
262     , "--registry=" + common.registry
263     ], {}, function (err, code, stdout, stderr) {
264       t.ifError(err, "view command finished successfully")
265       t.equal(code, 1, "exit not ok")
266
267       t.similar(stderr, new RegExp("is not in the npm registry"),
268         "Package should NOT be found")
269
270       t.dissimilar(stderr, new RegExp("use the name yourself!"),
271         "Suggestion should not be there")
272
273       t.similar(stderr, new RegExp("name can no longer contain capital letters"),
274         "Suggestion about Capital letter should be there")
275
276       s.close()
277       t.end()
278     })
279   })
280 })
281
282
283 test("npm view with valid but non existent package name", function (t) {
284   mr({port : common.port, mocks: {
285       "get": {
286           "/valid-but-non-existent-package" : [404, {"error": "not found"}]
287       }
288   }}, function (er, s) {
289     common.npm([
290       "view"
291     , "valid-but-non-existent-package"
292     , "--registry=" + common.registry
293     ], {}, function (err, code, stdout, stderr) {
294       t.ifError(err, "view command finished successfully")
295       t.equal(code, 1, "exit not ok")
296
297       t.similar(stderr,
298         new RegExp("'valid-but-non-existent-package' is not in the npm registry\."),
299         "Package should NOT be found")
300
301       t.similar(stderr, new RegExp("use the name yourself!"),
302         "Suggestion should be there")
303
304       s.close()
305       t.end()
306     })
307   })
308 })
309
310 test("cleanup", function (t) {
311   process.chdir(osenv.tmpdir())
312   rimraf.sync(t1dir)
313   rimraf.sync(t2dir)
314   rimraf.sync(t3dir)
315   t.pass("cleaned up")
316   t.end()
317 })