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

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan LaFreniere <quitlahok@gmail.com>2020-09-18 23:55:25 +0300
committerisaacs <i@izs.me>2020-09-21 21:32:09 +0300
commit165f4ef4e831a6f802e5d440ce6bbc81484c6095 (patch)
treed9130fd7d74f81c57d96a002ebb3a0e41c03a80f /test/lib/utils
parent2042c5532277b76fcee295075e74549b84abe664 (diff)
chore: add tests for ping util and cmd
PR-URL: https://github.com/npm/cli/pull/1825 Credit: @nlf Close: #1825 Reviewed-by: @isaacs
Diffstat (limited to 'test/lib/utils')
-rw-r--r--test/lib/utils/ping.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/test/lib/utils/ping.js b/test/lib/utils/ping.js
new file mode 100644
index 000000000..d2b269556
--- /dev/null
+++ b/test/lib/utils/ping.js
@@ -0,0 +1,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')
+})