Skip to content

Commit

Permalink
Fix gates
Browse files Browse the repository at this point in the history
  • Loading branch information
sebmarkbage committed Apr 16, 2024
1 parent e8d5dea commit 561970b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 28 deletions.
3 changes: 3 additions & 0 deletions packages/react-client/src/__tests__/ReactFlight-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2347,6 +2347,9 @@ describe('ReactFlight', () => {
},
);

if (gate(flag => !flag.enableFlightReadableStream)) {
return;
}
// Wait for the iterator to finish
await iteratorPromise;
await 0; // One more tick for the return value / closing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ describe('ReactFlightDOMEdge', () => {
expect(result.get('value')).toBe('hello');
});

// @gate enableFlightReadableStream
it('can pass an async import to a ReadableStream while enqueuing in order', async () => {
let resolve;
const promise = new Promise(r => (resolve = r));
Expand Down Expand Up @@ -496,6 +497,7 @@ describe('ReactFlightDOMEdge', () => {
expect(await reader.read()).toEqual({value: undefined, done: true});
});

// @gate enableFlightReadableStream
it('can pass an async import a AsyncIterable while allowing peaking at future values', async () => {
let resolve;
const promise = new Promise(r => (resolve = r));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,33 +109,35 @@ describe('ReactFlightDOMReplyEdge', () => {
expect(await result.arrayBuffer()).toEqual(await blob.arrayBuffer());
});

it('can transport FormData (blobs)', async () => {
const bytes = new Uint8Array([
123, 4, 10, 5, 100, 255, 244, 45, 56, 67, 43, 124, 67, 89, 100, 20,
]);
const blob = new Blob([bytes, bytes], {
type: 'application/x-test',
if (typeof FormData !== 'undefined' && typeof File !== 'undefined') {
it('can transport FormData (blobs)', async () => {
const bytes = new Uint8Array([
123, 4, 10, 5, 100, 255, 244, 45, 56, 67, 43, 124, 67, 89, 100, 20,
]);
const blob = new Blob([bytes, bytes], {
type: 'application/x-test',
});

const formData = new FormData();
formData.append('hi', 'world');
formData.append('file', blob, 'filename.test');

expect(formData.get('file') instanceof File).toBe(true);
expect(formData.get('file').name).toBe('filename.test');

const body = await ReactServerDOMClient.encodeReply(formData);
const result = await ReactServerDOMServer.decodeReply(
body,
webpackServerMap,
);

expect(result instanceof FormData).toBe(true);
expect(result.get('hi')).toBe('world');
const resultBlob = result.get('file');
expect(resultBlob instanceof Blob).toBe(true);
expect(resultBlob.name).toBe('filename.test'); // In this direction we allow file name to pass through but not other direction.
expect(resultBlob.size).toBe(bytes.length * 2);
expect(await resultBlob.arrayBuffer()).toEqual(await blob.arrayBuffer());
});

const formData = new FormData();
formData.append('hi', 'world');
formData.append('file', blob, 'filename.test');

expect(formData.get('file') instanceof File).toBe(true);
expect(formData.get('file').name).toBe('filename.test');

const body = await ReactServerDOMClient.encodeReply(formData);
const result = await ReactServerDOMServer.decodeReply(
body,
webpackServerMap,
);

expect(result instanceof FormData).toBe(true);
expect(result.get('hi')).toBe('world');
const resultBlob = result.get('file');
expect(resultBlob instanceof Blob).toBe(true);
expect(resultBlob.name).toBe('filename.test'); // In this direction we allow file name to pass through but not other direction.
expect(resultBlob.size).toBe(bytes.length * 2);
expect(await resultBlob.arrayBuffer()).toEqual(await blob.arrayBuffer());
});
}
});

0 comments on commit 561970b

Please sign in to comment.