Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ping.js « utils « lib « test - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1bebfa69d2b78d7d881650a667fd2b96f7dd5b7d (plain)
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
const t = require('tap')

t.test('pings', async (t) => {
  t.plan(3)

  const options = { fake: 'options' }
  const response = { some: 'details' }
  const ping = t.mock('../../../lib/utils/ping.js', {
    'npm-registry-fetch': (url, opts) => {
      t.equal(url, '/-/ping?write=true', 'calls the correct url')
      t.equal(opts, options, 'passes through options')
      return { json: () => Promise.resolve(response) }
    },
  })

  const res = await ping(options)
  t.match(res, response, 'returns json response')
})

t.test('catches errors and returns empty json', async (t) => {
  t.plan(3)

  const options = { fake: 'options' }
  const response = { some: 'details' }
  const ping = t.mock('../../../lib/utils/ping.js', {
    'npm-registry-fetch': (url, opts) => {
      t.equal(url, '/-/ping?write=true', 'calls the correct url')
      t.equal(opts, options, 'passes through options')
      return { json: () => Promise.reject(response) }
    },
  })

  const res = await ping(options)
  t.match(res, {}, 'returns empty json response')
})