Skip to content

Commit 1aec4cb

Browse files
vanishcodeclaudiahdz
authored andcommitted
test: add test for npm doctor that ping registry returns error
1 parent b7ad775 commit 1aec4cb

File tree

1 file changed

+108
-0
lines changed

1 file changed

+108
-0
lines changed

test/tap/doctor-ping-registry-404.js

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
'use strict'
2+
/* eslint-disable camelcase */
3+
const common = require('../common-tap.js')
4+
const http = require('http')
5+
const mr = require('npm-registry-mock')
6+
const npm = require('../../lib/npm.js')
7+
const path = require('path')
8+
const Tacks = require('tacks')
9+
const t = require('tap')
10+
const which = require('which')
11+
12+
const Dir = Tacks.Dir
13+
const File = Tacks.File
14+
15+
const ROOT = common.pkg
16+
const CACHE = common.cache
17+
const TMP = path.join(ROOT, 'tmp')
18+
const PREFIX = path.join(ROOT, 'global-prefix')
19+
const PKG = path.join(ROOT, 'pkg')
20+
21+
let server, nodeServer
22+
let node_url
23+
24+
t.teardown(() => {
25+
if (server) {
26+
server.close()
27+
}
28+
if (nodeServer) {
29+
nodeServer.close()
30+
}
31+
})
32+
33+
t.test('setup', (t) => {
34+
const port = common.port + 2
35+
nodeServer = http.createServer(function (q, s) {
36+
s.end(JSON.stringify([{ lts: true, version: '0.0.0' }]))
37+
})
38+
nodeServer.listen(port, () => {
39+
node_url = 'http://localhost:' + port
40+
mr({ port: common.port }, (err, s) => {
41+
t.ifError(err, 'registry mocked successfully')
42+
server = s
43+
server.get('/-/ping?write=true').reply(404)
44+
server.get('/npm').reply(
45+
200,
46+
JSON.stringify({
47+
name: 'npm',
48+
'dist-tags': { latest: '0.0.0' },
49+
versions: {
50+
'0.0.0': {
51+
name: 'npm',
52+
version: '0.0.0',
53+
_shrinkwrap: null,
54+
_hasShrinkwrap: false,
55+
dist: {
56+
shasum: 'deadbeef',
57+
tarball: 'https://reg.eh/npm-0.0.0.tgz',
58+
},
59+
},
60+
},
61+
})
62+
)
63+
const fixture = new Tacks(
64+
Dir({
65+
[path.basename(PKG)]: Dir({
66+
'package.json': File({ name: 'npm', version: '0.0.0' }),
67+
}),
68+
[path.basename(PREFIX)]: Dir({}),
69+
})
70+
)
71+
fixture.create(ROOT)
72+
npm.load(
73+
{
74+
registry: common.registry,
75+
loglevel: 'silent',
76+
cache: CACHE,
77+
tmp: TMP,
78+
prefix: PREFIX,
79+
},
80+
(err) => {
81+
t.ifError(err, 'npm loaded successfully')
82+
t.pass('all set up')
83+
t.done()
84+
}
85+
)
86+
})
87+
})
88+
})
89+
90+
t.test('npm doctor ping returns 404 (or any other error)', function (t) {
91+
npm.commands.doctor({ 'node-url': node_url }, true, function (e, list) {
92+
t.ifError(e, 'npm loaded successfully')
93+
t.same(list.length, 9, 'list should have 9 prop')
94+
t.same(list[0][1], 'failed', 'npm ping')
95+
t.same(list[1][1], 'v' + npm.version, 'npm -v')
96+
t.same(list[2][1], process.version, 'node -v')
97+
t.same(list[3][1], common.registry + '/', 'npm config get registry')
98+
t.same(list[5][1], 'ok', 'Perms check on cached files')
99+
t.same(list[6][1], 'ok', 'Perms check on global node_modules')
100+
t.same(list[7][1], 'ok', 'Perms check on local node_modules')
101+
t.match(list[8][1], /^verified \d+ tarballs?$/, 'Cache verified')
102+
which('git', function (e, resolvedPath) {
103+
t.ifError(e, 'git command is installed')
104+
t.same(list[4][1], resolvedPath, 'which git')
105+
t.done()
106+
})
107+
})
108+
})

0 commit comments

Comments
 (0)