diff --git a/lib/commands/edit.js b/lib/commands/edit.js index b2c2ec8d2a39a..1140c59efa3e4 100644 --- a/lib/commands/edit.js +++ b/lib/commands/edit.js @@ -33,8 +33,6 @@ class Edit extends BaseCommand { static params = ['editor'] static ignoreImplicitWorkspace = false - // TODO - /* istanbul ignore next */ static async completion (opts, npm) { return completion(npm, opts) } diff --git a/lib/commands/explain.js b/lib/commands/explain.js index 5f37ba9925f41..3b843e3bbff6c 100644 --- a/lib/commands/explain.js +++ b/lib/commands/explain.js @@ -17,8 +17,6 @@ class Explain extends ArboristWorkspaceCmd { static ignoreImplicitWorkspace = false - // TODO - /* istanbul ignore next */ static async completion (opts, npm) { const completion = require('../utils/installed-deep.js') return completion(npm, opts) diff --git a/lib/commands/explore.js b/lib/commands/explore.js index 184af2bdc5a16..d0d2e5c3ef891 100644 --- a/lib/commands/explore.js +++ b/lib/commands/explore.js @@ -14,8 +14,6 @@ class Explore extends BaseCommand { static params = ['shell'] static ignoreImplicitWorkspace = false - // TODO - /* istanbul ignore next */ static async completion (opts, npm) { return completion(npm, opts) } diff --git a/lib/commands/fund.js b/lib/commands/fund.js index 8c194dac80b49..a281912d77b32 100644 --- a/lib/commands/fund.js +++ b/lib/commands/fund.js @@ -34,8 +34,6 @@ class Fund extends ArboristWorkspaceCmd { return `${msg}\`` } - // TODO - /* istanbul ignore next */ static async completion (opts, npm) { const completion = require('../utils/installed-deep.js') return completion(npm, opts) diff --git a/lib/commands/get.js b/lib/commands/get.js index 4191f2c973e7d..e111d7f2f54c8 100644 --- a/lib/commands/get.js +++ b/lib/commands/get.js @@ -8,8 +8,6 @@ class Get extends BaseCommand { static params = ['long'] static ignoreImplicitWorkspace = false - // TODO - /* istanbul ignore next */ static async completion (opts) { const Config = Npm.cmd('config') return Config.completion(opts) diff --git a/lib/commands/ls.js b/lib/commands/ls.js index bc8beb007e809..0ea8704a50573 100644 --- a/lib/commands/ls.js +++ b/lib/commands/ls.js @@ -39,8 +39,6 @@ class LS extends ArboristWorkspaceCmd { ...super.params, ] - // TODO - /* istanbul ignore next */ static async completion (opts, npm) { const completion = require('../utils/installed-deep.js') return completion(npm, opts) diff --git a/lib/commands/rebuild.js b/lib/commands/rebuild.js index 1c19836106e06..a23df39f1560b 100644 --- a/lib/commands/rebuild.js +++ b/lib/commands/rebuild.js @@ -17,8 +17,6 @@ class Rebuild extends ArboristWorkspaceCmd { static usage = ['[] ...]'] - // TODO - /* istanbul ignore next */ static async completion (opts, npm) { const completion = require('../utils/installed-deep.js') return completion(npm, opts) diff --git a/lib/commands/set.js b/lib/commands/set.js index 2e61762ba9dcd..9a90e2a50ea1e 100644 --- a/lib/commands/set.js +++ b/lib/commands/set.js @@ -8,8 +8,6 @@ class Set extends BaseCommand { static params = ['global', 'location'] static ignoreImplicitWorkspace = false - // TODO - /* istanbul ignore next */ static async completion (opts) { const Config = Npm.cmd('config') return Config.completion(opts) diff --git a/lib/commands/uninstall.js b/lib/commands/uninstall.js index f9baebe3bc2e2..a369158d99c52 100644 --- a/lib/commands/uninstall.js +++ b/lib/commands/uninstall.js @@ -11,8 +11,6 @@ class Uninstall extends ArboristWorkspaceCmd { static usage = ['[<@scope>/]...'] static ignoreImplicitWorkspace = false - // TODO - /* istanbul ignore next */ static async completion (opts, npm) { return completion(npm, opts) } diff --git a/lib/commands/update.js b/lib/commands/update.js index 0d2fc324d9245..38e83f3f6bb95 100644 --- a/lib/commands/update.js +++ b/lib/commands/update.js @@ -29,8 +29,6 @@ class Update extends ArboristWorkspaceCmd { static usage = ['[...]'] - // TODO - /* istanbul ignore next */ static async completion (opts, npm) { const completion = require('../utils/installed-deep.js') return completion(npm, opts) diff --git a/test/lib/commands/edit.js b/test/lib/commands/edit.js index ae6826f7f98ad..b55bb2df218ba 100644 --- a/test/lib/commands/edit.js +++ b/test/lib/commands/edit.js @@ -3,6 +3,20 @@ const path = require('node:path') const tspawk = require('../../fixtures/tspawk') const { load: loadMockNpm } = require('../../fixtures/mock-npm') +t.test('completion', async t => { + const { edit } = await loadMockNpm(t, { + command: 'edit', + prefixDir: { + node_modules: { + foo: {}, + bar: {}, + }, + }, + }) + const res = await edit.completion({ conf: { argv: { remain: ['npm', 'edit'] } } }) + t.match(res, ['bar', 'foo']) +}) + const spawk = tspawk(t) const npmConfig = { diff --git a/test/lib/commands/explain.js b/test/lib/commands/explain.js index b55371c8b7e5c..d702019e9202a 100644 --- a/test/lib/commands/explain.js +++ b/test/lib/commands/explain.js @@ -2,6 +2,22 @@ const t = require('tap') const { resolve } = require('node:path') const mockNpm = require('../../fixtures/mock-npm.js') +t.test('completion', async t => { + const { explain } = await mockNpm(t, { + command: 'explain', + prefixDir: { + node_modules: { + foo: { + 'package.json': JSON.stringify({ name: 'foo', version: '1.0.0' }), + }, + }, + 'package.json': JSON.stringify({ name: 'project', version: '1.0.0' }), + }, + }) + const res = await explain.completion({ conf: { argv: { remain: ['npm', 'explain'] } } }) + t.type(res, Array) +}) + const mockExplain = async (t, opts) => { const mock = await mockNpm(t, { command: 'explain', diff --git a/test/lib/commands/explore.js b/test/lib/commands/explore.js index 6988dca90fbfb..b40de9817bff6 100644 --- a/test/lib/commands/explore.js +++ b/test/lib/commands/explore.js @@ -2,6 +2,20 @@ const t = require('tap') const mockNpm = require('../../fixtures/mock-npm') const { cleanCwd } = require('../../fixtures/clean-snapshot') +t.test('completion', async t => { + const { explore } = await mockNpm(t, { + command: 'explore', + prefixDir: { + node_modules: { + foo: {}, + bar: {}, + }, + }, + }) + const res = await explore.completion({ conf: { argv: { remain: ['npm', 'explore'] } } }) + t.match(res, ['bar', 'foo']) +}) + const mockExplore = async (t, exec, { PJ_ERROR = null, RUN_SCRIPT_ERROR = null, diff --git a/test/lib/commands/fund.js b/test/lib/commands/fund.js index 277190e7a1a48..95521fb6da650 100644 --- a/test/lib/commands/fund.js +++ b/test/lib/commands/fund.js @@ -1,6 +1,22 @@ const t = require('tap') const mockNpm = require('../../fixtures/mock-npm') +t.test('completion', async t => { + const { fund } = await mockNpm(t, { + command: 'fund', + prefixDir: { + node_modules: { + foo: { + 'package.json': JSON.stringify({ name: 'foo', version: '1.0.0' }), + }, + }, + 'package.json': JSON.stringify({ name: 'project', version: '1.0.0' }), + }, + }) + const res = await fund.completion({ conf: { argv: { remain: ['npm', 'fund'] } } }) + t.type(res, Array) +}) + const version = '1.0.0' const funding = { diff --git a/test/lib/commands/get.js b/test/lib/commands/get.js index dec634f835172..6a1db69628217 100644 --- a/test/lib/commands/get.js +++ b/test/lib/commands/get.js @@ -1,6 +1,12 @@ const t = require('tap') const { load: loadMockNpm } = require('../../fixtures/mock-npm') +t.test('completion', async t => { + const { get } = await loadMockNpm(t, { command: 'get' }) + const res = await get.completion({ conf: { argv: { remain: ['npm', 'get'] } } }) + t.type(res, Array) +}) + t.test('should retrieve values from config', async t => { const name = 'editor' const value = 'vigor' diff --git a/test/lib/commands/ls.js b/test/lib/commands/ls.js index c876af9e83ddf..1de85b8cfd095 100644 --- a/test/lib/commands/ls.js +++ b/test/lib/commands/ls.js @@ -5285,3 +5285,19 @@ t.test('ls --package-lock-only', async t => { }) }) }) + +t.test('completion', async t => { + const { ls } = await mockNpm(t, { + command: 'ls', + prefixDir: { + node_modules: { + foo: { + 'package.json': JSON.stringify({ name: 'foo', version: '1.0.0' }), + }, + }, + 'package.json': JSON.stringify({ name: 'project', version: '1.0.0' }), + }, + }) + const res = await ls.completion({ conf: { argv: { remain: ['npm', 'ls'] } } }) + t.type(res, Array) +}) diff --git a/test/lib/commands/rebuild.js b/test/lib/commands/rebuild.js index aa5578460b90f..0062362b61329 100644 --- a/test/lib/commands/rebuild.js +++ b/test/lib/commands/rebuild.js @@ -205,3 +205,19 @@ t.test('global prefix', async t => { 'should output success msg' ) }) + +t.test('completion', async t => { + const { rebuild } = await setupMockNpm(t, { + command: 'rebuild', + prefixDir: { + node_modules: { + foo: { + 'package.json': JSON.stringify({ name: 'foo', version: '1.0.0' }), + }, + }, + 'package.json': JSON.stringify({ name: 'project', version: '1.0.0' }), + }, + }) + const res = await rebuild.completion({ conf: { argv: { remain: ['npm', 'rebuild'] } } }) + t.type(res, Array) +}) diff --git a/test/lib/commands/set.js b/test/lib/commands/set.js index a4a2a7349ef1a..8574b80345e5c 100644 --- a/test/lib/commands/set.js +++ b/test/lib/commands/set.js @@ -4,6 +4,12 @@ const mockNpm = require('../../fixtures/mock-npm') const { join } = require('node:path') const { cleanNewlines } = require('../../fixtures/clean-snapshot') +t.test('completion', async t => { + const { set } = await mockNpm(t, { command: 'set' }) + const res = await set.completion({ conf: { argv: { remain: ['npm', 'set'] } } }) + t.type(res, Array) +}) + t.test('no args', async t => { const { npm } = await mockNpm(t) t.rejects(npm.exec('set', []), /Usage:/, 'prints usage') diff --git a/test/lib/commands/uninstall.js b/test/lib/commands/uninstall.js index a1ef1745d0f55..2ede1c4c1a72a 100644 --- a/test/lib/commands/uninstall.js +++ b/test/lib/commands/uninstall.js @@ -200,3 +200,17 @@ t.test('non ENOENT error reading from localPrefix package.json', async t => { 'should throw non ENOENT error' ) }) + +t.test('completion', async t => { + const { uninstall } = await _mockNpm(t, { + command: 'uninstall', + prefixDir: { + node_modules: { + foo: {}, + bar: {}, + }, + }, + }) + const res = await uninstall.completion({ conf: { argv: { remain: ['npm', 'uninstall'] } } }) + t.match(res, ['bar', 'foo']) +}) diff --git a/test/lib/commands/update.js b/test/lib/commands/update.js index e84e2c3142141..a8c68bd65bb36 100644 --- a/test/lib/commands/update.js +++ b/test/lib/commands/update.js @@ -79,3 +79,19 @@ t.test('update --global', async t => { t.match(ctor.path, globalPrefix) t.ok(ctor.path.startsWith(globalPrefix)) }) + +t.test('completion', async t => { + const { update } = await _mockNpm(t, { + command: 'update', + prefixDir: { + node_modules: { + foo: { + 'package.json': JSON.stringify({ name: 'foo', version: '1.0.0' }), + }, + }, + 'package.json': JSON.stringify({ name: 'project', version: '1.0.0' }), + }, + }) + const res = await update.completion({ conf: { argv: { remain: ['npm', 'update'] } } }) + t.type(res, Array) +})