diff options
author | Yash Singh <saiansh2525@gmail.com> | 2021-03-23 21:59:38 +0300 |
---|---|---|
committer | Gar <gar+gh@danger.computer> | 2021-03-24 21:05:07 +0300 |
commit | c76f04ac28ddf2ae4df4b3ce0aec684a118de1b5 (patch) | |
tree | a12794efdfd455a1ebac9591aa7e858591e47724 /test | |
parent | 877b4ed2925c97b5249a4d33575420dda64f7339 (diff) |
fix(set-script): add completion
PR-URL: https://github.com/npm/cli/pull/2925
Credit: @Yash-Singh1
Close: #2925
Reviewed-by: @ruyadorno
Diffstat (limited to 'test')
-rw-r--r-- | test/lib/set-script.js | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/test/lib/set-script.js b/test/lib/set-script.js index b6b6e2519..dc00fd374 100644 --- a/test/lib/set-script.js +++ b/test/lib/set-script.js @@ -2,6 +2,43 @@ const test = require('tap') const requireInject = require('require-inject') const parseJSON = require('json-parse-even-better-errors') +test.test('completion', t => { + const SetScript = requireInject('../../lib/set-script.js') + const emptyDir = t.testdir() + t.test('already have a script name', async t => { + const setScript = new SetScript({localPrefix: emptyDir}) + const res = await setScript.completion({conf: {argv: {remain: ['npm', 'run', 'x']}}}) + t.equal(res, undefined) + t.end() + }) + t.test('no package.json', async t => { + const setScript = new SetScript({localPrefix: emptyDir}) + const res = await setScript.completion({conf: {argv: {remain: ['npm', 'run']}}}) + t.strictSame(res, []) + t.end() + }) + t.test('has package.json, no scripts', async t => { + const localPrefix = t.testdir({ + 'package.json': JSON.stringify({}), + }) + const setScript = new SetScript({localPrefix}) + const res = await setScript.completion({conf: {argv: {remain: ['npm', 'run']}}}) + t.strictSame(res, []) + t.end() + }) + t.test('has package.json, with scripts', async t => { + const localPrefix = t.testdir({ + 'package.json': JSON.stringify({ + scripts: { hello: 'echo hello', world: 'echo world' }, + }), + }) + const setScript = new SetScript({localPrefix}) + const res = await setScript.completion({conf: {argv: {remain: ['npm', 'run']}}}) + t.strictSame(res, ['hello', 'world']) + t.end() + }) + t.end() +}) test.test('fails on invalid arguments', (t) => { const SetScript = requireInject('../../lib/set-script.js', { npmlog: {}, |