@@ -28,7 +28,7 @@ let hookArgs = null
2828const libnpmhook = {
2929 add : async ( pkg , uri , secret , opts ) => {
3030 hookArgs = { pkg, uri, secret, opts }
31- return { id : 1 , name : pkg . replace ( / ^ @ / , '' ) , type : pkgTypes [ pkg ] , endpoint : uri }
31+ return { id : 1 , name : pkg , type : pkgTypes [ pkg ] , endpoint : uri }
3232 } ,
3333 ls : async opts => {
3434 hookArgs = opts
@@ -39,7 +39,7 @@ const libnpmhook = {
3939
4040 return Object . keys ( pkgTypes ) . map ( name => ( {
4141 id : ++ id ,
42- name : name . replace ( / ^ @ / , '' ) ,
42+ name,
4343 type : pkgTypes [ name ] ,
4444 endpoint : 'https://google.com' ,
4545 last_delivery : id % 2 === 0 ? now : undefined ,
@@ -50,15 +50,15 @@ const libnpmhook = {
5050 const pkg = Object . keys ( pkgTypes ) [ 0 ]
5151 return {
5252 id : 1 ,
53- name : pkg . replace ( / ^ @ / , '' ) ,
53+ name : pkg ,
5454 type : pkgTypes [ pkg ] ,
5555 endpoint : 'https://google.com' ,
5656 }
5757 } ,
5858 update : async ( id , uri , secret , opts ) => {
5959 hookArgs = { id, uri, secret, opts }
6060 const pkg = Object . keys ( pkgTypes ) [ 0 ]
61- return { id, name : pkg . replace ( / ^ @ / , '' ) , type : pkgTypes [ pkg ] , endpoint : uri }
61+ return { id, name : pkg , type : pkgTypes [ pkg ] , endpoint : uri }
6262 } ,
6363}
6464
@@ -92,6 +92,48 @@ t.test('npm hook add', async t => {
9292 t . strictSame ( output , [ '+ semver -> https://google.com' ] , 'prints the correct output' )
9393} )
9494
95+ t . test ( 'npm hook add - correct owner hook output' , async t => {
96+ t . teardown ( ( ) => {
97+ hookArgs = null
98+ output . length = 0
99+ } )
100+
101+ await hook . exec ( [ 'add' , '~npm' , 'https://google.com' , 'some-secret' ] )
102+
103+ t . match (
104+ hookArgs ,
105+ {
106+ pkg : '~npm' ,
107+ uri : 'https://google.com' ,
108+ secret : 'some-secret' ,
109+ opts : npm . flatOptions ,
110+ } ,
111+ 'provided the correct arguments to libnpmhook'
112+ )
113+ t . strictSame ( output , [ '+ ~npm -> https://google.com' ] , 'prints the correct output' )
114+ } )
115+
116+ t . test ( 'npm hook add - correct scope hook output' , async t => {
117+ t . teardown ( ( ) => {
118+ hookArgs = null
119+ output . length = 0
120+ } )
121+
122+ await hook . exec ( [ 'add' , '@npmcli' , 'https://google.com' , 'some-secret' ] )
123+
124+ t . match (
125+ hookArgs ,
126+ {
127+ pkg : '@npmcli' ,
128+ uri : 'https://google.com' ,
129+ secret : 'some-secret' ,
130+ opts : npm . flatOptions ,
131+ } ,
132+ 'provided the correct arguments to libnpmhook'
133+ )
134+ t . strictSame ( output , [ '+ @npmcli -> https://google.com' ] , 'prints the correct output' )
135+ } )
136+
95137t . test ( 'npm hook add - unicode output' , async t => {
96138 npm . flatOptions . unicode = true
97139 t . teardown ( ( ) => {
@@ -139,7 +181,7 @@ t.test('npm hook add - json output', async t => {
139181 JSON . parse ( output [ 0 ] ) ,
140182 {
141183 id : 1 ,
142- name : 'npmcli' ,
184+ name : '@ npmcli' ,
143185 endpoint : 'https://google.com' ,
144186 type : 'scope' ,
145187 } ,
@@ -174,7 +216,7 @@ t.test('npm hook add - parseable output', async t => {
174216 )
175217 t . strictSame (
176218 output [ 1 ] . split ( / \t / ) ,
177- [ '1' , 'npmcli' , 'scope' , 'https://google.com' ] ,
219+ [ '1' , '@ npmcli' , 'scope' , 'https://google.com' ] ,
178220 'prints the correct parseable values'
179221 )
180222} )
@@ -345,7 +387,7 @@ t.test('npm hook ls - parseable output', async t => {
345387 [
346388 [ 'id' , 'name' , 'type' , 'endpoint' , 'last_delivery' ] ,
347389 [ '1' , 'semver' , 'package' , 'https://google.com' , '' ] ,
348- [ '2' , 'npmcli' , 'scope' , 'https://google.com' , `${ now } ` ] ,
390+ [ '2' , '@ npmcli' , 'scope' , 'https://google.com' , `${ now } ` ] ,
349391 [ '3' , 'npm' , 'owner' , 'https://google.com' , '' ] ,
350392 ] ,
351393 'prints the correct result'
0 commit comments