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
|
const t = require('tap')
const { load: loadMockNpm } = require('../../fixtures/mock-npm.js')
const MockRegistry = require('../../fixtures/mock-registry.js')
t.test('no details', async t => {
const { npm, logs, joinedOutput } = await loadMockNpm(t)
const registry = new MockRegistry({
tap: t,
registry: npm.config.get('registry'),
})
registry.ping()
await npm.exec('ping', [])
t.match(logs.notice, [['PING', 'https://registry.npmjs.org/'], ['PONG', /[0-9]+ms/]])
t.equal(joinedOutput(), '')
})
t.test('with details', async t => {
const { npm, logs, joinedOutput } = await loadMockNpm(t)
const registry = new MockRegistry({
tap: t,
registry: npm.config.get('registry'),
})
registry.ping({ body: { test: true } })
await npm.exec('ping', [])
t.match(logs.notice, [
['PING', 'https://registry.npmjs.org/'],
['PONG', /[0-9]+ms/],
['PONG', '{\n "test": true\n}'],
])
t.match(joinedOutput(), '')
})
t.test('valid json', async t => {
const { npm, logs, joinedOutput } = await loadMockNpm(t, {
config: { json: true },
})
const registry = new MockRegistry({
tap: t,
registry: npm.config.get('registry'),
})
registry.ping()
await npm.exec('ping', [])
t.match(logs.notice, [['PING', 'https://registry.npmjs.org/'], ['PONG', /[0-9]+ms/]])
t.match(JSON.parse(joinedOutput()), {
registry: npm.config.get('registry'),
time: /[0-9]+/,
details: {},
})
})
t.test('invalid json', async t => {
const { npm, logs, joinedOutput } = await loadMockNpm(t, {
config: { json: true },
})
const registry = new MockRegistry({
tap: t,
registry: npm.config.get('registry'),
})
registry.ping({ body: '{not: real"json]' })
await npm.exec('ping', [])
t.match(logs.notice, [['PING', 'https://registry.npmjs.org/'], ['PONG', /[0-9]+ms/]])
t.match(JSON.parse(joinedOutput()), {
registry: npm.config.get('registry'),
time: /[0-9]+/,
details: {},
})
})
|