11cb0ef41Sopenharmony_ciconst t = require('tap')
21cb0ef41Sopenharmony_ciconst { load: loadMockNpm } = require('../../fixtures/mock-npm.js')
31cb0ef41Sopenharmony_ciconst MockRegistry = require('@npmcli/mock-registry')
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_cit.test('no details', async t => {
61cb0ef41Sopenharmony_ci  const { npm, logs, joinedOutput } = await loadMockNpm(t)
71cb0ef41Sopenharmony_ci  const registry = new MockRegistry({
81cb0ef41Sopenharmony_ci    tap: t,
91cb0ef41Sopenharmony_ci    registry: npm.config.get('registry'),
101cb0ef41Sopenharmony_ci  })
111cb0ef41Sopenharmony_ci  registry.ping()
121cb0ef41Sopenharmony_ci  await npm.exec('ping', [])
131cb0ef41Sopenharmony_ci  t.match(logs.notice, [['PING', 'https://registry.npmjs.org/'], ['PONG', /[0-9]+ms/]])
141cb0ef41Sopenharmony_ci  t.equal(joinedOutput(), '')
151cb0ef41Sopenharmony_ci})
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_cit.test('with details', async t => {
181cb0ef41Sopenharmony_ci  const { npm, logs, joinedOutput } = await loadMockNpm(t)
191cb0ef41Sopenharmony_ci  const registry = new MockRegistry({
201cb0ef41Sopenharmony_ci    tap: t,
211cb0ef41Sopenharmony_ci    registry: npm.config.get('registry'),
221cb0ef41Sopenharmony_ci  })
231cb0ef41Sopenharmony_ci  registry.ping({ body: { test: true } })
241cb0ef41Sopenharmony_ci  await npm.exec('ping', [])
251cb0ef41Sopenharmony_ci  t.match(logs.notice, [
261cb0ef41Sopenharmony_ci    ['PING', 'https://registry.npmjs.org/'],
271cb0ef41Sopenharmony_ci    ['PONG', /[0-9]+ms/],
281cb0ef41Sopenharmony_ci    ['PONG', '{\n  "test": true\n}'],
291cb0ef41Sopenharmony_ci  ])
301cb0ef41Sopenharmony_ci  t.match(joinedOutput(), '')
311cb0ef41Sopenharmony_ci})
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_cit.test('valid json', async t => {
341cb0ef41Sopenharmony_ci  const { npm, logs, joinedOutput } = await loadMockNpm(t, {
351cb0ef41Sopenharmony_ci    config: { json: true },
361cb0ef41Sopenharmony_ci  })
371cb0ef41Sopenharmony_ci  const registry = new MockRegistry({
381cb0ef41Sopenharmony_ci    tap: t,
391cb0ef41Sopenharmony_ci    registry: npm.config.get('registry'),
401cb0ef41Sopenharmony_ci  })
411cb0ef41Sopenharmony_ci  registry.ping()
421cb0ef41Sopenharmony_ci  await npm.exec('ping', [])
431cb0ef41Sopenharmony_ci  t.match(logs.notice, [['PING', 'https://registry.npmjs.org/'], ['PONG', /[0-9]+ms/]])
441cb0ef41Sopenharmony_ci  t.match(JSON.parse(joinedOutput()), {
451cb0ef41Sopenharmony_ci    registry: npm.config.get('registry'),
461cb0ef41Sopenharmony_ci    time: /[0-9]+/,
471cb0ef41Sopenharmony_ci    details: {},
481cb0ef41Sopenharmony_ci  })
491cb0ef41Sopenharmony_ci})
501cb0ef41Sopenharmony_ci
511cb0ef41Sopenharmony_cit.test('invalid json', async t => {
521cb0ef41Sopenharmony_ci  const { npm, logs, joinedOutput } = await loadMockNpm(t, {
531cb0ef41Sopenharmony_ci    config: { json: true },
541cb0ef41Sopenharmony_ci  })
551cb0ef41Sopenharmony_ci  const registry = new MockRegistry({
561cb0ef41Sopenharmony_ci    tap: t,
571cb0ef41Sopenharmony_ci    registry: npm.config.get('registry'),
581cb0ef41Sopenharmony_ci  })
591cb0ef41Sopenharmony_ci  registry.ping({ body: '{not: real"json]' })
601cb0ef41Sopenharmony_ci  await npm.exec('ping', [])
611cb0ef41Sopenharmony_ci  t.match(logs.notice, [['PING', 'https://registry.npmjs.org/'], ['PONG', /[0-9]+ms/]])
621cb0ef41Sopenharmony_ci  t.match(JSON.parse(joinedOutput()), {
631cb0ef41Sopenharmony_ci    registry: npm.config.get('registry'),
641cb0ef41Sopenharmony_ci    time: /[0-9]+/,
651cb0ef41Sopenharmony_ci    details: {},
661cb0ef41Sopenharmony_ci  })
671cb0ef41Sopenharmony_ci})
68