@@ -21,6 +21,9 @@ jest.mock('../../bin-utils', () => {
21
21
return defaultPsConfig
22
22
} ) ,
23
23
initialize : jest . fn ( ( ) => {
24
+ if ( mockFindUp . mock . syncFail ) {
25
+ return undefined
26
+ }
24
27
return {
25
28
packageScriptsPath : '/path/to/package-scripts.js' ,
26
29
packageJsonPath : '/path/to/package.json' ,
@@ -196,6 +199,22 @@ test('init without an existing config will initialize package-scripts.js', () =>
196
199
delete mockFindUp . mock . syncReturn
197
200
} )
198
201
202
+ test ( 'init without an existing package.json will fail' , ( ) => {
203
+ mockFindUp . mock . syncFail = true
204
+ mockFindUp . mock . syncReturn = undefined
205
+
206
+ const result = parse ( 'init' )
207
+ expect ( result ) . toBe ( undefined )
208
+ expect ( mockReadLine . keyInYN ) . toHaveBeenCalledTimes ( 0 )
209
+ expect ( mockGetLogger . mock . error ) . toHaveBeenCalledWith (
210
+ expect . stringMatching ( / U n a b l e / ) ,
211
+ )
212
+
213
+ delete mockFindUp . mock . syncFail
214
+ delete mockReadLine . mock . keyInYNReturn
215
+ delete mockFindUp . mock . syncReturn
216
+ } )
217
+
199
218
test ( 'if there is a help script in the psConfig, does not show the help' , ( ) => {
200
219
mockBinUtils . mock . psConfig = { scripts : { help : 'hi' } , options : { } }
201
220
expect ( parse ( 'help' ) ) . not . toBe ( undefined )
0 commit comments