@@ -134,50 +134,48 @@ describe('_mockNpmShow', () => {
134134
135135 it ( "errors if package doesn't exist" , async ( ) => {
136136 const emptyData = _makeRegistryData ( { } ) ;
137- const result = await _mockNpmShow ( emptyData , [ 'foo' ] , { cwd : undefined } ) ;
137+ const result = await _mockNpmShow ( emptyData , [ 'foo' ] , { cwd : '' } ) ;
138138 expect ( result ) . toEqual ( getErrorResult ( '[fake] code E404 - foo - not found' ) ) ;
139139 } ) ;
140140
141141 it ( 'returns requested version plus dist-tags and version list' , async ( ) => {
142- const result = await _mockNpmShow ( data , [ 'foo@1.0.0' ] , { cwd : undefined } ) ;
142+ const result = await _mockNpmShow ( data , [ 'foo@1.0.0' ] , { cwd : '' } ) ;
143143 expect ( result ) . toEqual ( getShowResult ( { name : 'foo' , version : '1.0.0' } ) ) ;
144144 } ) ;
145145
146146 it ( 'returns requested version of scoped package' , async ( ) => {
147- const result = await _mockNpmShow ( data , [ '@foo/bar@2.0.0' ] , { cwd : undefined } ) ;
147+ const result = await _mockNpmShow ( data , [ '@foo/bar@2.0.0' ] , { cwd : '' } ) ;
148148 expect ( result ) . toEqual ( getShowResult ( { name : '@foo/bar' , version : '2.0.0' } ) ) ;
149149 } ) ;
150150
151151 it ( 'returns requested tag' , async ( ) => {
152- const result = await _mockNpmShow ( data , [ 'foo@beta' ] , { cwd : undefined } ) ;
152+ const result = await _mockNpmShow ( data , [ 'foo@beta' ] , { cwd : '' } ) ;
153153 expect ( result ) . toEqual ( getShowResult ( { name : 'foo' , version : '1.0.0-beta' } ) ) ;
154154 } ) ;
155155
156156 it ( 'returns requested tag of scoped package' , async ( ) => {
157- const result = await _mockNpmShow ( data , [ '@foo/bar@beta' ] , { cwd : undefined } ) ;
157+ const result = await _mockNpmShow ( data , [ '@foo/bar@beta' ] , { cwd : '' } ) ;
158158 expect ( result ) . toEqual ( getShowResult ( { name : '@foo/bar' , version : '2.0.0-beta' } ) ) ;
159159 } ) ;
160160
161161 it ( 'returns latest version if no version requested' , async ( ) => {
162- const result = await _mockNpmShow ( data , [ 'foo' ] , { cwd : undefined } ) ;
162+ const result = await _mockNpmShow ( data , [ 'foo' ] , { cwd : '' } ) ;
163163 expect ( result ) . toEqual ( getShowResult ( { name : 'foo' , version : '1.0.1' } ) ) ;
164164 } ) ;
165165
166166 it ( 'returns latest version of scoped package if no version requested' , async ( ) => {
167- const result = await _mockNpmShow ( data , [ '@foo/bar' ] , { cwd : undefined } ) ;
167+ const result = await _mockNpmShow ( data , [ '@foo/bar' ] , { cwd : '' } ) ;
168168 expect ( result ) . toEqual ( getShowResult ( { name : '@foo/bar' , version : '2.0.1' } ) ) ;
169169 } ) ;
170170
171171 it ( "errors if requested version doesn't exist" , async ( ) => {
172- const result = await _mockNpmShow ( data , [ 'foo@2.0.0' ] , { cwd : undefined } ) ;
172+ const result = await _mockNpmShow ( data , [ 'foo@2.0.0' ] , { cwd : '' } ) ;
173173 expect ( result ) . toEqual ( getErrorResult ( '[fake] code E404 - foo@2.0.0 - not found' ) ) ;
174174 } ) ;
175175
176176 // support for this could be added later
177177 it ( 'currently throws if requested version is a range' , async ( ) => {
178- await expect ( ( ) => _mockNpmShow ( data , [ 'foo@^1.0.0' ] , { cwd : undefined } ) ) . rejects . toThrow (
179- / n o t c u r r e n t l y s u p p o r t e d /
180- ) ;
178+ await expect ( ( ) => _mockNpmShow ( data , [ 'foo@^1.0.0' ] , { cwd : '' } ) ) . rejects . toThrow ( / n o t c u r r e n t l y s u p p o r t e d / ) ;
181179 } ) ;
182180} ) ;
183181
@@ -209,9 +207,7 @@ describe('_mockNpmPublish', () => {
209207 } ) ;
210208
211209 it ( 'throws if cwd is not specified' , async ( ) => {
212- await expect ( ( ) => _mockNpmPublish ( { } , [ ] , { cwd : undefined } ) ) . rejects . toThrow (
213- 'cwd is required for mock npm publish'
214- ) ;
210+ await expect ( ( ) => _mockNpmPublish ( { } , [ ] , { cwd : '' } ) ) . rejects . toThrow ( 'cwd is required for mock npm publish' ) ;
215211 } ) ;
216212
217213 it ( 'errors if reading package.json fails' , async ( ) => {
@@ -308,7 +304,7 @@ describe('_mockNpmPack', () => {
308304 } ) ;
309305
310306 it ( 'throws if cwd is not specified' , async ( ) => {
311- await expect ( ( ) => _mockNpmPack ( { } , [ ] , { cwd : undefined } ) ) . rejects . toThrow ( 'cwd is required for mock npm pack' ) ;
307+ await expect ( ( ) => _mockNpmPack ( { } , [ ] , { cwd : '' } ) ) . rejects . toThrow ( 'cwd is required for mock npm pack' ) ;
312308 } ) ;
313309
314310 it ( 'errors if reading package.json fails' , async ( ) => {
@@ -433,7 +429,7 @@ describe('mockNpm', () => {
433429 versions : [ '1.0.0' ] ,
434430 'dist-tags' : { latest : '1.0.0' } ,
435431 } ) ;
436- expect ( await npm ( [ 'show' , 'foo' ] , { cwd : undefined } ) ) . toMatchObject ( {
432+ expect ( await npm ( [ 'show' , 'foo' ] , { cwd : '' } ) ) . toMatchObject ( {
437433 success : true ,
438434 stdout : JSON . stringify ( {
439435 name : 'foo' ,
@@ -485,19 +481,19 @@ describe('mockNpm', () => {
485481 } ) ;
486482
487483 it ( 'throws if required cwd is missing' , async ( ) => {
488- await expect ( ( ) => npm ( [ 'publish' ] , { cwd : undefined } ) ) . rejects . toThrow ( 'cwd is required for mock npm publish' ) ;
489- await expect ( ( ) => npm ( [ 'pack' ] , { cwd : undefined } ) ) . rejects . toThrow ( 'cwd is required for mock npm pack' ) ;
484+ await expect ( ( ) => npm ( [ 'publish' ] , { cwd : '' } ) ) . rejects . toThrow ( 'cwd is required for mock npm publish' ) ;
485+ await expect ( ( ) => npm ( [ 'pack' ] , { cwd : '' } ) ) . rejects . toThrow ( 'cwd is required for mock npm pack' ) ;
490486 } ) ;
491487
492488 it ( 'throws on unsupported command' , async ( ) => {
493- await expect ( ( ) => npm ( [ 'foo' ] , { cwd : undefined } ) ) . rejects . toThrow ( 'Command not supported by mock npm: foo' ) ;
489+ await expect ( ( ) => npm ( [ 'foo' ] , { cwd : '' } ) ) . rejects . toThrow ( 'Command not supported by mock npm: foo' ) ;
494490 expect ( npmMock . mock ) . toHaveBeenCalledTimes ( 1 ) ;
495- expect ( npmMock . mock ) . toHaveBeenCalledWith ( [ 'foo' ] , expect . objectContaining ( { cwd : undefined } ) ) ;
491+ expect ( npmMock . mock ) . toHaveBeenCalledWith ( [ 'foo' ] , expect . objectContaining ( { cwd : '' } ) ) ;
496492 } ) ;
497493
498494 it ( 'TEMP mocks npm show command' , async ( ) => {
499495 npmMock . setRegistryData ( { foo : { versions : [ '1.0.0' ] } } ) ;
500- const result = await npm ( [ 'show' , 'foo' ] , { cwd : undefined } ) ;
496+ const result = await npm ( [ 'show' , 'foo' ] , { cwd : '' } ) ;
501497 expect ( result ) . toMatchObject ( {
502498 success : true ,
503499 stdout : expect . stringContaining ( '"name":"foo"' ) ,
@@ -511,24 +507,24 @@ describe('mockNpm', () => {
511507 it ( 'respects mocked command override' , async ( ) => {
512508 const mockPublish = jest . fn ( ( ) => Promise . resolve ( fakePublishResult as unknown as MockNpmResult ) ) ;
513509 npmMock . setCommandOverride ( 'publish' , mockPublish ) ;
514- const result = await npm ( [ 'publish' , 'foo' ] , { cwd : undefined } ) ;
510+ const result = await npm ( [ 'publish' , 'foo' ] , { cwd : '' } ) ;
515511 expect ( result ) . toEqual ( fakePublishResult ) ;
516- expect ( mockPublish ) . toHaveBeenCalledWith ( expect . any ( Object ) , [ 'foo' ] , { cwd : undefined } ) ;
512+ expect ( mockPublish ) . toHaveBeenCalledWith ( expect . any ( Object ) , [ 'foo' ] , { cwd : '' } ) ;
517513 } ) ;
518514
519515 it ( "respects extra mocked command that's not normally supported" , async ( ) => {
520516 const mockFoo = jest . fn ( ( ) => Promise . resolve ( 'hi' as unknown as MockNpmResult ) ) ;
521517 npmMock . setCommandOverride ( 'foo' , mockFoo ) ;
522- const result = await npm ( [ 'foo' ] , { cwd : undefined } ) ;
518+ const result = await npm ( [ 'foo' ] , { cwd : '' } ) ;
523519 expect ( result ) . toEqual ( 'hi' ) ;
524- expect ( mockFoo ) . toHaveBeenCalledWith ( expect . any ( Object ) , [ ] , { cwd : undefined } ) ;
520+ expect ( mockFoo ) . toHaveBeenCalledWith ( expect . any ( Object ) , [ ] , { cwd : '' } ) ;
525521 } ) ;
526522
527523 it ( 'resets commands after each test' , async ( ) => {
528524 // extra command is gone
529- await expect ( ( ) => npm ( [ 'foo' ] , { cwd : undefined } ) ) . rejects . toThrow ( 'Command not supported by mock npm: foo' ) ;
525+ await expect ( ( ) => npm ( [ 'foo' ] , { cwd : '' } ) ) . rejects . toThrow ( 'Command not supported by mock npm: foo' ) ;
530526 // publish mock is gone
531- await expect ( ( ) => npm ( [ 'publish' ] , { cwd : undefined } ) ) . rejects . toThrow ( 'cwd is required for mock npm publish' ) ;
527+ await expect ( ( ) => npm ( [ 'publish' ] , { cwd : '' } ) ) . rejects . toThrow ( 'cwd is required for mock npm publish' ) ;
532528 } ) ;
533529 } ) ;
534530} ) ;
0 commit comments