@@ -28,7 +28,7 @@ let hookArgs = null
28
28
const libnpmhook = {
29
29
add : async ( pkg , uri , secret , opts ) => {
30
30
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 }
32
32
} ,
33
33
ls : async opts => {
34
34
hookArgs = opts
@@ -39,7 +39,7 @@ const libnpmhook = {
39
39
40
40
return Object . keys ( pkgTypes ) . map ( name => ( {
41
41
id : ++ id ,
42
- name : name . replace ( / ^ @ / , '' ) ,
42
+ name,
43
43
type : pkgTypes [ name ] ,
44
44
endpoint : 'https://google.com' ,
45
45
last_delivery : id % 2 === 0 ? now : undefined ,
@@ -50,15 +50,15 @@ const libnpmhook = {
50
50
const pkg = Object . keys ( pkgTypes ) [ 0 ]
51
51
return {
52
52
id : 1 ,
53
- name : pkg . replace ( / ^ @ / , '' ) ,
53
+ name : pkg ,
54
54
type : pkgTypes [ pkg ] ,
55
55
endpoint : 'https://google.com' ,
56
56
}
57
57
} ,
58
58
update : async ( id , uri , secret , opts ) => {
59
59
hookArgs = { id, uri, secret, opts }
60
60
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 }
62
62
} ,
63
63
}
64
64
@@ -92,6 +92,48 @@ t.test('npm hook add', async t => {
92
92
t . strictSame ( output , [ '+ semver -> https://google.com' ] , 'prints the correct output' )
93
93
} )
94
94
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
+
95
137
t . test ( 'npm hook add - unicode output' , async t => {
96
138
npm . flatOptions . unicode = true
97
139
t . teardown ( ( ) => {
@@ -139,7 +181,7 @@ t.test('npm hook add - json output', async t => {
139
181
JSON . parse ( output [ 0 ] ) ,
140
182
{
141
183
id : 1 ,
142
- name : 'npmcli' ,
184
+ name : '@ npmcli' ,
143
185
endpoint : 'https://google.com' ,
144
186
type : 'scope' ,
145
187
} ,
@@ -174,7 +216,7 @@ t.test('npm hook add - parseable output', async t => {
174
216
)
175
217
t . strictSame (
176
218
output [ 1 ] . split ( / \t / ) ,
177
- [ '1' , 'npmcli' , 'scope' , 'https://google.com' ] ,
219
+ [ '1' , '@ npmcli' , 'scope' , 'https://google.com' ] ,
178
220
'prints the correct parseable values'
179
221
)
180
222
} )
@@ -345,7 +387,7 @@ t.test('npm hook ls - parseable output', async t => {
345
387
[
346
388
[ 'id' , 'name' , 'type' , 'endpoint' , 'last_delivery' ] ,
347
389
[ '1' , 'semver' , 'package' , 'https://google.com' , '' ] ,
348
- [ '2' , 'npmcli' , 'scope' , 'https://google.com' , `${ now } ` ] ,
390
+ [ '2' , '@ npmcli' , 'scope' , 'https://google.com' , `${ now } ` ] ,
349
391
[ '3' , 'npm' , 'owner' , 'https://google.com' , '' ] ,
350
392
] ,
351
393
'prints the correct result'
0 commit comments