@@ -90,24 +90,33 @@ class MockStream extends EventEmitter {
90
90
public pipe ( destination : any , options ?: { end ?: boolean ; } ) : any {
91
91
// Nothing to do here, just mock the method.
92
92
}
93
+ public end ( ) : any {
94
+ //
95
+ }
96
+ }
97
+
98
+ class MockBuffer {
99
+ constructor ( ) {
100
+ return Buffer . from ( [ ] ) ;
101
+ }
93
102
}
94
103
95
- describe . skip ( "pacoteService" , ( ) => {
104
+ describe ( "pacoteService" , ( ) => {
96
105
const manifestResult : any = { } ;
97
106
const manifestOptions : IPacoteManifestOptions = { fullMetadata : true } ;
98
107
let sandboxInstance : sinon . SinonSandbox = null ;
99
108
let manifestStub : sinon . SinonStub = null ;
100
109
let tarballStreamStub : sinon . SinonStub = null ;
101
110
let tarXStub : sinon . SinonStub = null ;
102
- let tarballSourceStream : MockStream = null ;
111
+ let tarballSourceBuffer : MockBuffer = null ;
103
112
let tarExtractDestinationStream : MockStream = null ;
104
113
105
114
beforeEach ( ( ) => {
106
115
sandboxInstance = sinon . createSandbox ( ) ;
107
116
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 ( ) ;
111
120
tarXStub = sandboxInstance . stub ( tar , "x" ) . returns ( < any > tarExtractDestinationStream ) ;
112
121
} ) ;
113
122
@@ -205,13 +214,11 @@ describe.skip("pacoteService", () => {
205
214
} ) ;
206
215
207
216
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 ( ) => {
209
218
const pacoteService = setupTest ( ) ;
210
219
220
+ tarballStreamStub . returns ( Promise . reject ( new Error ( errorMessage ) ) ) ;
211
221
const pacoteExtractPackagePromise = pacoteService . extractPackage ( packageName , destinationDir ) ;
212
- setImmediate ( ( ) => {
213
- tarballSourceStream . emit ( "error" , new Error ( errorMessage ) ) ;
214
- } ) ;
215
222
216
223
await assert . isRejected ( pacoteExtractPackagePromise , errorMessage ) ;
217
224
} ) ;
0 commit comments