@@ -2,6 +2,43 @@ const test = require('tap')
22const requireInject = require ( 'require-inject' )
33const parseJSON = require ( 'json-parse-even-better-errors' )
44
5+ test . test ( 'completion' , t => {
6+ const SetScript = requireInject ( '../../lib/set-script.js' )
7+ const emptyDir = t . testdir ( )
8+ t . test ( 'already have a script name' , async t => {
9+ const setScript = new SetScript ( { localPrefix : emptyDir } )
10+ const res = await setScript . completion ( { conf : { argv : { remain : [ 'npm' , 'run' , 'x' ] } } } )
11+ t . equal ( res , undefined )
12+ t . end ( )
13+ } )
14+ t . test ( 'no package.json' , async t => {
15+ const setScript = new SetScript ( { localPrefix : emptyDir } )
16+ const res = await setScript . completion ( { conf : { argv : { remain : [ 'npm' , 'run' ] } } } )
17+ t . strictSame ( res , [ ] )
18+ t . end ( )
19+ } )
20+ t . test ( 'has package.json, no scripts' , async t => {
21+ const localPrefix = t . testdir ( {
22+ 'package.json' : JSON . stringify ( { } ) ,
23+ } )
24+ const setScript = new SetScript ( { localPrefix} )
25+ const res = await setScript . completion ( { conf : { argv : { remain : [ 'npm' , 'run' ] } } } )
26+ t . strictSame ( res , [ ] )
27+ t . end ( )
28+ } )
29+ t . test ( 'has package.json, with scripts' , async t => {
30+ const localPrefix = t . testdir ( {
31+ 'package.json' : JSON . stringify ( {
32+ scripts : { hello : 'echo hello' , world : 'echo world' } ,
33+ } ) ,
34+ } )
35+ const setScript = new SetScript ( { localPrefix} )
36+ const res = await setScript . completion ( { conf : { argv : { remain : [ 'npm' , 'run' ] } } } )
37+ t . strictSame ( res , [ 'hello' , 'world' ] )
38+ t . end ( )
39+ } )
40+ t . end ( )
41+ } )
542test . test ( 'fails on invalid arguments' , ( t ) => {
643 const SetScript = requireInject ( '../../lib/set-script.js' , {
744 npmlog : { } ,
0 commit comments