1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
|
var common = require("../common-tap.js")
var test = require("tap").test
var osenv = require("osenv")
var path = require("path")
var fs = require("fs")
var rimraf = require("rimraf")
var mkdirp = require("mkdirp")
var tmp = osenv.tmpdir()
var t1dir = path.resolve(tmp, "view-local-no-pkg")
var t2dir = path.resolve(tmp, "view-local-notmine")
var t3dir = path.resolve(tmp, "view-local-mine")
var mr = require("npm-registry-mock")
test("setup", function (t) {
mkdirp.sync(t1dir)
mkdirp.sync(t2dir)
mkdirp.sync(t3dir)
fs.writeFileSync(t2dir + "/package.json", JSON.stringify({
author: "Evan Lucas"
, name: "test-repo-url-https"
, version: "0.0.1"
}), "utf8")
fs.writeFileSync(t3dir + "/package.json", JSON.stringify({
author: "Evan Lucas"
, name: "biscuits"
, version: "0.0.1"
}), "utf8")
t.pass("created fixtures")
t.end()
})
test("npm view . in global mode", function (t) {
process.chdir(t1dir)
common.npm([
"view"
, "."
, "--registry=" + common.registry
, "--global"
], { cwd: t1dir }, function (err, code, stdout, stderr) {
t.ifError(err, "view command finished successfully")
t.equal(code, 1, "exit not ok")
t.similar(stderr, /Cannot use view command in global mode./m)
t.end()
})
})
test("npm view --global", function(t) {
process.chdir(t1dir)
common.npm([
"view"
, "--registry=" + common.registry
, "--global"
], { cwd: t1dir }, function(err, code, stdout, stderr) {
t.ifError(err, "view command finished successfully")
t.equal(code, 1, "exit not ok")
t.similar(stderr, /Cannot use view command in global mode./m)
t.end()
})
})
test("npm view . with no package.json", function(t) {
process.chdir(t1dir)
common.npm([
"view"
, "."
, "--registry=" + common.registry
], { cwd: t1dir }, function (err, code, stdout, stderr) {
t.ifError(err, "view command finished successfully")
t.equal(code, 1, "exit not ok")
t.similar(stderr, /Invalid package.json/m)
t.end()
})
})
test("npm view . with no published package", function (t) {
process.chdir(t3dir)
mr(common.port, function (s) {
common.npm([
"view"
, "."
, "--registry=" + common.registry
], { cwd: t3dir }, function (err, code, stdout, stderr) {
t.ifError(err, "view command finished successfully")
t.equal(code, 1, "exit not ok")
t.similar(stderr, /version not found/m)
s.close()
t.end()
})
})
})
test("npm view .", function (t) {
process.chdir(t2dir)
mr(common.port, function (s) {
common.npm([
"view"
, "."
, "--registry=" + common.registry
], { cwd: t2dir }, function (err, code, stdout) {
t.ifError(err, "view command finished successfully")
t.equal(code, 0, "exit ok")
var re = new RegExp("name: 'test-repo-url-https'")
t.similar(stdout, re)
s.close()
t.end()
})
})
})
test("npm view . select fields", function (t) {
process.chdir(t2dir)
mr(common.port, function (s) {
common.npm([
"view"
, "."
, "main"
, "--registry=" + common.registry
], { cwd: t2dir }, function (err, code, stdout) {
t.ifError(err, "view command finished successfully")
t.equal(code, 0, "exit ok")
t.equal(stdout.trim(), "index.js", "should print `index.js`")
s.close()
t.end()
})
})
})
test("npm view .@<version>", function (t) {
process.chdir(t2dir)
mr(common.port, function (s) {
common.npm([
"view"
, ".@0.0.0"
, "version"
, "--registry=" + common.registry
], { cwd: t2dir }, function (err, code, stdout) {
t.ifError(err, "view command finished successfully")
t.equal(code, 0, "exit ok")
t.equal(stdout.trim(), "0.0.0", "should print `0.0.0`")
s.close()
t.end()
})
})
})
test("npm view .@<version> --json", function (t) {
process.chdir(t2dir)
mr(common.port, function (s) {
common.npm([
"view"
, ".@0.0.0"
, "version"
, "--json"
, "--registry=" + common.registry
], { cwd: t2dir }, function (err, code, stdout) {
t.ifError(err, "view command finished successfully")
t.equal(code, 0, "exit ok")
t.equal(stdout.trim(), "\"0.0.0\"", "should print `\"0.0.0\"`")
s.close()
t.end()
})
})
})
test("npm view <package name>", function (t) {
mr(common.port, function (s) {
common.npm([
"view"
, "underscore"
, "--registry=" + common.registry
], { cwd: t2dir }, function (err, code, stdout) {
t.ifError(err, "view command finished successfully")
t.equal(code, 0, "exit ok")
var re = new RegExp("name: 'underscore'")
t.similar(stdout, re, "should have name `underscore`")
s.close()
t.end()
})
})
})
test("npm view <package name> --global", function(t) {
mr(common.port, function(s) {
common.npm([
"view"
, "underscore"
, "--global"
, "--registry=" + common.registry
], { cwd: t2dir }, function(err, code, stdout) {
t.ifError(err, "view command finished successfully")
t.equal(code, 0, "exit ok")
var re = new RegExp("name: 'underscore'")
t.similar(stdout, re, "should have name `underscore`")
s.close()
t.end()
})
})
})
test("npm view <package name> --json", function(t) {
t.plan(3)
mr(common.port, function (s) {
common.npm([
"view"
, "underscore"
, "--json"
, "--registry=" + common.registry
], { cwd: t2dir }, function (err, code, stdout) {
t.ifError(err, "view command finished successfully")
t.equal(code, 0, "exit ok")
s.close()
try {
var out = JSON.parse(stdout.trim())
t.similar(out, {
maintainers: "jashkenas <jashkenas@gmail.com>"
}, "should have the same maintainer")
}
catch (er) {
t.fail("Unable to parse JSON")
}
})
})
})
test("npm view <package name> <field>", function (t) {
mr(common.port, function (s) {
common.npm([
"view"
, "underscore"
, "homepage"
, "--registry=" + common.registry
], { cwd: t2dir }, function (err, code, stdout) {
t.ifError(err, "view command finished successfully")
t.equal(code, 0, "exit ok")
t.equal(stdout.trim(), "http://underscorejs.org",
"homepage should equal `http://underscorejs.org`")
s.close()
t.end()
})
})
})
test("cleanup", function (t) {
process.chdir(osenv.tmpdir())
rimraf.sync(t1dir)
rimraf.sync(t2dir)
rimraf.sync(t3dir)
t.pass("cleaned up")
t.end()
})
|