@@ -12,16 +12,24 @@ const globalThis = require('../../src/globalthis')
12
12
chai . use ( dirtyChai )
13
13
const expect = chai . expect
14
14
15
- const STRING = 'hello world'
16
- const BUFFER = Buffer . from ( STRING )
17
- const ARRAY = Array . from ( BUFFER )
18
- const TYPEDARRAY = Uint8Array . from ( ARRAY )
15
+ const STRING = ( ) => 'hello world'
16
+ const BUFFER = ( ) => Buffer . from ( STRING ( ) )
17
+ const ARRAY = ( ) => Array . from ( BUFFER ( ) )
18
+ const TYPEDARRAY = ( ) => Uint8Array . from ( ARRAY ( ) )
19
19
let BLOB
20
+ let WINDOW_READABLE_STREAM
20
21
21
22
if ( supportsFileReader ) {
22
- BLOB = new globalThis . Blob ( [
23
- STRING
23
+ BLOB = ( ) => new globalThis . Blob ( [
24
+ STRING ( )
24
25
] )
26
+
27
+ WINDOW_READABLE_STREAM = ( ) => new globalThis . ReadableStream ( {
28
+ start ( controller ) {
29
+ controller . enqueue ( BUFFER ( ) )
30
+ controller . close ( )
31
+ }
32
+ } )
25
33
}
26
34
27
35
async function verifyNormalisation ( input ) {
@@ -31,7 +39,7 @@ async function verifyNormalisation (input) {
31
39
chai . assert . fail ( 'Content should have been an iterable or an async iterable' )
32
40
}
33
41
34
- expect ( await all ( input [ 0 ] . content ) ) . to . deep . equal ( [ BUFFER ] )
42
+ expect ( await all ( input [ 0 ] . content ) ) . to . deep . equal ( [ BUFFER ( ) ] )
35
43
expect ( input [ 0 ] . path ) . to . equal ( '' )
36
44
}
37
45
@@ -54,56 +62,56 @@ function asyncIterableOf (thing) {
54
62
describe ( 'normalise-input' , function ( ) {
55
63
function testInputType ( content , name , isBytes ) {
56
64
it ( name , async function ( ) {
57
- await testContent ( content )
65
+ await testContent ( content ( ) )
58
66
} )
59
67
60
68
if ( isBytes ) {
61
69
it ( `Iterable<${ name } >` , async function ( ) {
62
- await testContent ( iterableOf ( content ) )
70
+ await testContent ( iterableOf ( content ( ) ) )
63
71
} )
64
72
65
73
it ( `AsyncIterable<${ name } >` , async function ( ) {
66
- await testContent ( asyncIterableOf ( content ) )
74
+ await testContent ( asyncIterableOf ( content ( ) ) )
67
75
} )
68
76
}
69
77
70
78
it ( `{ path: '', content: ${ name } }` , async function ( ) {
71
- await testContent ( { path : '' , content } )
79
+ await testContent ( { path : '' , content : content ( ) } )
72
80
} )
73
81
74
82
if ( isBytes ) {
75
83
it ( `{ path: '', content: Iterable<${ name } > }` , async function ( ) {
76
- await testContent ( { path : '' , content : iterableOf ( content ) } )
84
+ await testContent ( { path : '' , content : iterableOf ( content ( ) ) } )
77
85
} )
78
86
79
87
it ( `{ path: '', content: AsyncIterable<${ name } > }` , async function ( ) {
80
- await testContent ( { path : '' , content : asyncIterableOf ( content ) } )
88
+ await testContent ( { path : '' , content : asyncIterableOf ( content ( ) ) } )
81
89
} )
82
90
}
83
91
84
92
it ( `Iterable<{ path: '', content: ${ name } }` , async function ( ) {
85
- await testContent ( iterableOf ( { path : '' , content } ) )
93
+ await testContent ( iterableOf ( { path : '' , content : content ( ) } ) )
86
94
} )
87
95
88
96
it ( `AsyncIterable<{ path: '', content: ${ name } }` , async function ( ) {
89
- await testContent ( asyncIterableOf ( { path : '' , content } ) )
97
+ await testContent ( asyncIterableOf ( { path : '' , content : content ( ) } ) )
90
98
} )
91
99
92
100
if ( isBytes ) {
93
101
it ( `Iterable<{ path: '', content: Iterable<${ name } > }>` , async function ( ) {
94
- await testContent ( iterableOf ( { path : '' , content : iterableOf ( content ) } ) )
102
+ await testContent ( iterableOf ( { path : '' , content : iterableOf ( content ( ) ) } ) )
95
103
} )
96
104
97
105
it ( `Iterable<{ path: '', content: AsyncIterable<${ name } > }>` , async function ( ) {
98
- await testContent ( iterableOf ( { path : '' , content : asyncIterableOf ( content ) } ) )
106
+ await testContent ( iterableOf ( { path : '' , content : asyncIterableOf ( content ( ) ) } ) )
99
107
} )
100
108
101
109
it ( `AsyncIterable<{ path: '', content: Iterable<${ name } > }>` , async function ( ) {
102
- await testContent ( asyncIterableOf ( { path : '' , content : iterableOf ( content ) } ) )
110
+ await testContent ( asyncIterableOf ( { path : '' , content : iterableOf ( content ( ) ) } ) )
103
111
} )
104
112
105
113
it ( `AsyncIterable<{ path: '', content: AsyncIterable<${ name } > }>` , async function ( ) {
106
- await testContent ( asyncIterableOf ( { path : '' , content : asyncIterableOf ( content ) } ) )
114
+ await testContent ( asyncIterableOf ( { path : '' , content : asyncIterableOf ( content ( ) ) } ) )
107
115
} )
108
116
}
109
117
}
@@ -124,6 +132,14 @@ describe('normalise-input', function () {
124
132
testInputType ( BLOB , 'Blob' , false )
125
133
} )
126
134
135
+ describe ( 'window.ReadableStream' , ( ) => {
136
+ if ( ! supportsFileReader ) {
137
+ return
138
+ }
139
+
140
+ testInputType ( WINDOW_READABLE_STREAM , 'window.ReadableStream' , false )
141
+ } )
142
+
127
143
describe ( 'Iterable<Number>' , ( ) => {
128
144
testInputType ( ARRAY , 'Iterable<Number>' , false )
129
145
} )
0 commit comments