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: 6e0451538f9fac1c83947b60872d1d232060d3ed (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
36
const { test } = require('tap')
const requireInject = require('require-inject')

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

  const options = { fake: 'options' }
  const response = { some: 'details' }
  const ping = requireInject('../../../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')
})

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

  const options = { fake: 'options' }
  const response = { some: 'details' }
  const ping = requireInject('../../../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')
})