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