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
|
var fs = require('fs')
var path = require('path')
var mkdirp = require('mkdirp')
var mr = require('npm-registry-mock')
var rimraf = require('rimraf')
var test = require('tap').test
var common = require('../common-tap.js')
var pkg = path.resolve(__dirname, 'ping')
var opts = { cwd: pkg }
var outfile = path.join(pkg, '_npmrc')
var contents = function () {
}.toString().split('\n').slice(1, -1).join('\n')
var pingResponse = {
host: 'registry.npmjs.org',
ok: true,
username: null,
peer: 'example.com'
}
function mocks (server) {
server.get('/-/ping?write=true').reply(200, JSON.stringify(pingResponse))
}
test('setup', function (t) {
cleanup()
setup()
t.end()
})
test('npm ping', function (t) {
mr({ port: common.port, plugin: mocks }, function (err, s) {
if (err) throw err
common.npm([
'ping',
'--registry', common.registry,
'--loglevel', 'silent',
'--userconfig', outfile
], opts, function (err, code, stdout) {
s.close()
t.ifError(err, 'no error output')
t.notOk(code, 'exited OK')
t.same(stdout, 'Ping success: ' + JSON.stringify(pingResponse) + '\n')
t.end()
})
})
})
test('cleanup', function (t) {
cleanup()
t.end()
})
function setup () {
mkdirp.sync(pkg)
fs.writeFileSync(outfile, contents)
}
function cleanup () {
rimraf.sync(pkg)
}
|