All files / lib ping.js

100% Statements 21/21
100% Branches 4/4
100% Functions 3/3
100% Lines 19/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 293x 3x 3x 3x   3x 3x   3x 3x   3x 3x 3x 3x 3x 3x 3x 1x         2x 1x     3x  
const log = require('npmlog')
const npm = require('./npm.js')
const output = require('./utils/output.js')
const usageUtil = require('./utils/usage.js')
 
const usage = usageUtil('ping', 'npm ping\nping registry')
const completion = require('./utils/completion/none.js')
 
const cmd = (args, cb) => ping(args).then(() => cb()).catch(cb)
const pingUtil = require('./utils/ping.js')
 
const ping = async args => {
  log.notice('PING', npm.flatOptions.registry)
  const start = Date.now()
  const details = await pingUtil(npm.flatOptions)
  const time = Date.now() - start
  log.notice('PONG', `${time / 1000}ms`)
  if (npm.flatOptions.json) {
    output(JSON.stringify({
      registry: npm.flatOptions.registry,
      time,
      details,
    }, null, 2))
  } else if (Object.keys(details).length)
    log.notice('PONG', `${JSON.stringify(details, null, 2)}`)
}
 
module.exports = Object.assign(cmd, { completion, usage })