@@ -53,11 +53,7 @@ describe(readableStreamHasher.name, () => {
53
53
} ) ;
54
54
55
55
it ( "creates a copy in case of fileStream" , ( ) => {
56
- ( fsCreateReadStream as jest . Mock ) . mockReturnValue (
57
- new Readable ( {
58
- read : ( size ) => { } ,
59
- } )
60
- ) ;
56
+ ( fsCreateReadStream as jest . Mock ) . mockReturnValue ( new Readable ( { read : ( size ) => { } } ) ) ;
61
57
( isFileStream as unknown as jest . Mock ) . mockReturnValue ( true ) ;
62
58
63
59
const fsReadStream = createReadStream ( __filename ) ;
@@ -68,9 +64,7 @@ describe(readableStreamHasher.name, () => {
68
64
} ) ;
69
65
70
66
it ( "computes hash for a readable stream" , async ( ) => {
71
- const readableStream = new Readable ( {
72
- read : ( size ) => { } ,
73
- } ) ;
67
+ const readableStream = new Readable ( { read : ( size ) => { } } ) ;
74
68
const hashPromise = readableStreamHasher ( mockHashCtor , readableStream ) ;
75
69
76
70
// @ts -ignore Property '_readableState' does not exist on type 'Readable'.
@@ -92,6 +86,20 @@ describe(readableStreamHasher.name, () => {
92
86
expect ( mockHashCalculatorEnd ) . toHaveBeenCalledTimes ( 1 ) ;
93
87
} ) ;
94
88
89
+ it ( "throws if readable stream is not a file stream and has started reading" , async ( ) => {
90
+ const readableStream = new Readable ( { read : ( size ) => { } } ) ;
91
+ // Simulate readableFlowing to true.
92
+ readableStream . resume ( ) ;
93
+
94
+ const expectedError = new Error ( "Unable to calculate hash for flowing readable stream" ) ;
95
+ try {
96
+ readableStreamHasher ( mockHashCtor , readableStream ) ;
97
+ fail ( `expected ${ expectedError } ` ) ;
98
+ } catch ( error ) {
99
+ expect ( error ) . toStrictEqual ( expectedError ) ;
100
+ }
101
+ } ) ;
102
+
95
103
it ( "throws error if readable stream throws error" , async ( ) => {
96
104
const readableStream = new Readable ( {
97
105
read : ( size ) => { } ,
0 commit comments