@@ -109,33 +109,36 @@ describe('ReactFlightDOMReplyEdge', () => {
109
109
expect ( await result . arrayBuffer ( ) ) . toEqual ( await blob . arrayBuffer ( ) ) ;
110
110
} ) ;
111
111
112
- it ( 'can transport FormData (blobs)' , async ( ) => {
113
- const bytes = new Uint8Array ( [
114
- 123 , 4 , 10 , 5 , 100 , 255 , 244 , 45 , 56 , 67 , 43 , 124 , 67 , 89 , 100 , 20 ,
115
- ] ) ;
116
- const blob = new Blob ( [ bytes , bytes ] , {
117
- type : 'application/x-test' ,
112
+ if ( typeof FormData !== 'undefined' && typeof File !== 'undefined' ) {
113
+ // @gate enableBinaryFlight
114
+ it ( 'can transport FormData (blobs)' , async ( ) => {
115
+ const bytes = new Uint8Array ( [
116
+ 123 , 4 , 10 , 5 , 100 , 255 , 244 , 45 , 56 , 67 , 43 , 124 , 67 , 89 , 100 , 20 ,
117
+ ] ) ;
118
+ const blob = new Blob ( [ bytes , bytes ] , {
119
+ type : 'application/x-test' ,
120
+ } ) ;
121
+
122
+ const formData = new FormData ( ) ;
123
+ formData . append ( 'hi' , 'world' ) ;
124
+ formData . append ( 'file' , blob , 'filename.test' ) ;
125
+
126
+ expect ( formData . get ( 'file' ) instanceof File ) . toBe ( true ) ;
127
+ expect ( formData . get ( 'file' ) . name ) . toBe ( 'filename.test' ) ;
128
+
129
+ const body = await ReactServerDOMClient . encodeReply ( formData ) ;
130
+ const result = await ReactServerDOMServer . decodeReply (
131
+ body ,
132
+ webpackServerMap ,
133
+ ) ;
134
+
135
+ expect ( result instanceof FormData ) . toBe ( true ) ;
136
+ expect ( result . get ( 'hi' ) ) . toBe ( 'world' ) ;
137
+ const resultBlob = result . get ( 'file' ) ;
138
+ expect ( resultBlob instanceof Blob ) . toBe ( true ) ;
139
+ expect ( resultBlob . name ) . toBe ( 'filename.test' ) ; // In this direction we allow file name to pass through but not other direction.
140
+ expect ( resultBlob . size ) . toBe ( bytes . length * 2 ) ;
141
+ expect ( await resultBlob . arrayBuffer ( ) ) . toEqual ( await blob . arrayBuffer ( ) ) ;
118
142
} ) ;
119
-
120
- const formData = new FormData ( ) ;
121
- formData . append ( 'hi' , 'world' ) ;
122
- formData . append ( 'file' , blob , 'filename.test' ) ;
123
-
124
- expect ( formData . get ( 'file' ) instanceof File ) . toBe ( true ) ;
125
- expect ( formData . get ( 'file' ) . name ) . toBe ( 'filename.test' ) ;
126
-
127
- const body = await ReactServerDOMClient . encodeReply ( formData ) ;
128
- const result = await ReactServerDOMServer . decodeReply (
129
- body ,
130
- webpackServerMap ,
131
- ) ;
132
-
133
- expect ( result instanceof FormData ) . toBe ( true ) ;
134
- expect ( result . get ( 'hi' ) ) . toBe ( 'world' ) ;
135
- const resultBlob = result . get ( 'file' ) ;
136
- expect ( resultBlob instanceof Blob ) . toBe ( true ) ;
137
- expect ( resultBlob . name ) . toBe ( 'filename.test' ) ; // In this direction we allow file name to pass through but not other direction.
138
- expect ( resultBlob . size ) . toBe ( bytes . length * 2 ) ;
139
- expect ( await resultBlob . arrayBuffer ( ) ) . toEqual ( await blob . arrayBuffer ( ) ) ;
140
- } ) ;
143
+ }
141
144
} ) ;
0 commit comments