@@ -90,24 +90,33 @@ class MockStream extends EventEmitter {
9090 public pipe ( destination : any , options ?: { end ?: boolean ; } ) : any {
9191 // Nothing to do here, just mock the method.
9292 }
93+ public end ( ) : any {
94+ //
95+ }
96+ }
97+
98+ class MockBuffer {
99+ constructor ( ) {
100+ return Buffer . from ( [ ] ) ;
101+ }
93102}
94103
95- describe . skip ( "pacoteService" , ( ) => {
104+ describe ( "pacoteService" , ( ) => {
96105 const manifestResult : any = { } ;
97106 const manifestOptions : IPacoteManifestOptions = { fullMetadata : true } ;
98107 let sandboxInstance : sinon . SinonSandbox = null ;
99108 let manifestStub : sinon . SinonStub = null ;
100109 let tarballStreamStub : sinon . SinonStub = null ;
101110 let tarXStub : sinon . SinonStub = null ;
102- let tarballSourceStream : MockStream = null ;
111+ let tarballSourceBuffer : MockBuffer = null ;
103112 let tarExtractDestinationStream : MockStream = null ;
104113
105114 beforeEach ( ( ) => {
106115 sandboxInstance = sinon . createSandbox ( ) ;
107116 manifestStub = sandboxInstance . stub ( pacote , "manifest" ) . returns ( Promise . resolve ( manifestResult ) ) ;
108- tarballSourceStream = new MockStream ( ) ;
109- tarballStreamStub = sandboxInstance . stub ( pacote , "tarball" ) . returns ( Promise . resolve ( < any > tarballSourceStream ) ) ;
110- tarExtractDestinationStream = new MockStream ( ) ;
117+ tarballSourceBuffer = new MockBuffer ( ) ;
118+ tarballStreamStub = sandboxInstance . stub ( pacote , "tarball" ) . returns ( Promise . resolve ( < any > tarballSourceBuffer ) ) ;
119+ tarExtractDestinationStream = new MockStream ( ) ;
111120 tarXStub = sandboxInstance . stub ( tar , "x" ) . returns ( < any > tarExtractDestinationStream ) ;
112121 } ) ;
113122
@@ -205,13 +214,11 @@ describe.skip("pacoteService", () => {
205214 } ) ;
206215
207216 describe ( "extractPackage" , ( ) => {
208- it ( "fails with correct error when pacote.tarball.stream raises error event" , async ( ) => {
217+ it ( "fails with correct error when pacote.tarball raises error event" , async ( ) => {
209218 const pacoteService = setupTest ( ) ;
210219
220+ tarballStreamStub . returns ( Promise . reject ( new Error ( errorMessage ) ) ) ;
211221 const pacoteExtractPackagePromise = pacoteService . extractPackage ( packageName , destinationDir ) ;
212- setImmediate ( ( ) => {
213- tarballSourceStream . emit ( "error" , new Error ( errorMessage ) ) ;
214- } ) ;
215222
216223 await assert . isRejected ( pacoteExtractPackagePromise , errorMessage ) ;
217224 } ) ;
0 commit comments