Skip to content

Commit 6c0271a

Browse files
remove promise based incremental tests
1 parent 9cef7d0 commit 6c0271a

File tree

3 files changed

+29
-195
lines changed

3 files changed

+29
-195
lines changed

react_on_rails_pro/packages/node-renderer/tests/fixtures/bundle-incremental.js

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,6 @@ const { PassThrough } = require('stream');
33
global.ReactOnRails = {
44
dummy: { html: 'Dummy Object' },
55

6-
// Get or create async value promise
7-
getAsyncValue: function () {
8-
debugger;
9-
if (!sharedExecutionContext.has('asyncPromise')) {
10-
const promiseData = {};
11-
const promise = new Promise((resolve, reject) => {
12-
promiseData.resolve = resolve;
13-
promiseData.reject = reject;
14-
});
15-
promiseData.promise = promise;
16-
sharedExecutionContext.set('asyncPromise', promiseData);
17-
}
18-
return sharedExecutionContext.get('asyncPromise').promise;
19-
},
20-
21-
// Resolve the async value promise
22-
setAsyncValue: function (value) {
23-
debugger;
24-
if (!sharedExecutionContext.has('asyncPromise')) {
25-
ReactOnRails.getAsyncValue();
26-
}
27-
const promiseData = sharedExecutionContext.get('asyncPromise');
28-
promiseData.resolve(value);
29-
},
30-
316
// Get or create stream
327
getStreamValues: function () {
338
if (!sharedExecutionContext.has('stream')) {
@@ -54,4 +29,13 @@ global.ReactOnRails = {
5429
stream.end();
5530
}
5631
},
32+
33+
// Clear all stream values
34+
clearStreamValues: function () {
35+
if (sharedExecutionContext.has('stream')) {
36+
const { stream } = sharedExecutionContext.get('stream');
37+
stream.destroy();
38+
sharedExecutionContext.delete('stream');
39+
}
40+
},
5741
};

react_on_rails_pro/packages/node-renderer/tests/fixtures/secondary-bundle-incremental.js

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,6 @@ const { PassThrough } = require('stream');
33
global.ReactOnRails = {
44
dummy: { html: 'Dummy Object from secondary bundle' },
55

6-
// Get or create async value promise
7-
getAsyncValue: function () {
8-
if (!sharedExecutionContext.has('secondaryAsyncPromise')) {
9-
const promiseData = {};
10-
const promise = new Promise((resolve, reject) => {
11-
promiseData.resolve = resolve;
12-
promiseData.reject = reject;
13-
});
14-
promiseData.promise = promise;
15-
sharedExecutionContext.set('secondaryAsyncPromise', promiseData);
16-
}
17-
return sharedExecutionContext.get('secondaryAsyncPromise').promise;
18-
},
19-
20-
// Resolve the async value promise
21-
setAsyncValue: function (value) {
22-
if (!sharedExecutionContext.has('secondaryAsyncPromise')) {
23-
ReactOnRails.getAsyncValue();
24-
}
25-
const promiseData = sharedExecutionContext.get('secondaryAsyncPromise');
26-
promiseData.resolve(value);
27-
},
28-
296
// Get or create stream
307
getStreamValues: function () {
318
if (!sharedExecutionContext.has('secondaryStream')) {
@@ -51,4 +28,13 @@ global.ReactOnRails = {
5128
stream.end();
5229
}
5330
},
31+
32+
// Clear all stream values
33+
clearStreamValues: function () {
34+
if (sharedExecutionContext.has('secondaryStream')) {
35+
const { stream } = sharedExecutionContext.get('secondaryStream');
36+
stream.destroy();
37+
sharedExecutionContext.delete('secondaryStream');
38+
}
39+
},
5440
};

react_on_rails_pro/packages/node-renderer/tests/incrementalRender.test.ts

Lines changed: 11 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import packageJson from '../src/shared/packageJson';
66
import * as incremental from '../src/worker/handleIncrementalRenderRequest';
77
import {
88
createVmBundle,
9-
createSecondaryVmBundle,
109
createIncrementalVmBundle,
1110
createIncrementalSecondaryVmBundle,
1211
BUNDLE_TIMESTAMP,
1312
SECONDARY_BUNDLE_TIMESTAMP,
1413
waitFor,
14+
resetForTest,
1515
} from './helper';
1616
import type { ResponseResult } from '../src/shared/utils';
1717

@@ -238,6 +238,10 @@ describe('incremental render NDJSON endpoint', () => {
238238
return { promise, receivedChunks };
239239
};
240240

241+
beforeEach(async () => {
242+
await resetForTest(TEST_NAME);
243+
});
244+
241245
afterEach(() => {
242246
jest.restoreAllMocks();
243247
});
@@ -711,60 +715,6 @@ describe('incremental render NDJSON endpoint', () => {
711715
expect(response.data).toBe('first update'); // Should resolve with the first setAsyncValue call
712716
});
713717

714-
test('incremental updates work with multiple bundles using runOnOtherBundle', async () => {
715-
await createIncrementalVmBundle(TEST_NAME);
716-
await createIncrementalSecondaryVmBundle(TEST_NAME);
717-
const SERVER_BUNDLE_TIMESTAMP = String(BUNDLE_TIMESTAMP);
718-
const SECONDARY_BUNDLE_TIMESTAMP_STR = String(SECONDARY_BUNDLE_TIMESTAMP);
719-
720-
// Create the HTTP request
721-
const req = createHttpRequest(SERVER_BUNDLE_TIMESTAMP);
722-
723-
// Set up response handling
724-
const responsePromise = setupResponseHandler(req, true);
725-
726-
// Send the initial object that gets values from both bundles
727-
const initialObject = {
728-
...createInitialObject(SERVER_BUNDLE_TIMESTAMP),
729-
renderingRequest: `
730-
runOnOtherBundle(${SECONDARY_BUNDLE_TIMESTAMP}, 'ReactOnRails.getAsyncValue()').then((secondaryValue) => ({
731-
mainBundleValue: ReactOnRails.getAsyncValue(),
732-
secondaryBundleValue: JSON.parse(secondaryValue),
733-
}));
734-
`,
735-
dependencyBundleTimestamps: [SECONDARY_BUNDLE_TIMESTAMP_STR],
736-
};
737-
req.write(`${JSON.stringify(initialObject)}\n`);
738-
739-
// Send update chunks to both bundles
740-
const updateMainBundle = {
741-
bundleTimestamp: SERVER_BUNDLE_TIMESTAMP,
742-
updateChunk: 'ReactOnRails.setAsyncValue("main bundle updated")',
743-
};
744-
req.write(`${JSON.stringify(updateMainBundle)}\n`);
745-
746-
const updateSecondaryBundle = {
747-
bundleTimestamp: SECONDARY_BUNDLE_TIMESTAMP_STR,
748-
updateChunk: 'ReactOnRails.setAsyncValue("secondary bundle updated")',
749-
};
750-
req.write(`${JSON.stringify(updateSecondaryBundle)}\n`);
751-
752-
// End the request
753-
req.end();
754-
755-
// Wait for the response
756-
const response = await responsePromise;
757-
758-
// Verify the response
759-
expect(response.statusCode).toBe(200);
760-
const responseData = JSON.parse(response.data || '{}') as {
761-
mainBundleValue: unknown;
762-
secondaryBundleValue: unknown;
763-
};
764-
expect(responseData.mainBundleValue).toBe('main bundle updated');
765-
expect(responseData.secondaryBundleValue).toBe('secondary bundle updated');
766-
});
767-
768718
test('streaming functionality with incremental updates', async () => {
769719
await createIncrementalVmBundle(TEST_NAME);
770720
const SERVER_BUNDLE_TIMESTAMP = String(BUNDLE_TIMESTAMP);
@@ -804,99 +754,12 @@ describe('incremental render NDJSON endpoint', () => {
804754
req.write(`${JSON.stringify(updateChunk)}\n`);
805755
}
806756

807-
// No need to get stream values again since we're already streaming
808-
809-
// End the request
810-
req.end();
811-
812-
// Wait for the response
813-
const response = await responsePromise;
814-
815-
// Verify the response
816-
expect(response.statusCode).toBe(200);
817-
// Since we're returning a stream, the response should indicate streaming
818-
expect(streamedData.length).toBeGreaterThan(0);
819-
});
820-
821-
test('error handling in incremental render updates', async () => {
822-
await createIncrementalVmBundle(TEST_NAME);
823-
const SERVER_BUNDLE_TIMESTAMP = String(BUNDLE_TIMESTAMP);
824-
825-
// Create the HTTP request
826-
const req = createHttpRequest(SERVER_BUNDLE_TIMESTAMP);
827-
828-
// Set up response handling
829-
const responsePromise = setupResponseHandler(req, true);
830-
831-
// Send the initial object
832-
const initialObject = {
833-
...createInitialObject(SERVER_BUNDLE_TIMESTAMP),
834-
renderingRequest: 'ReactOnRails.getAsyncValue()',
835-
};
836-
req.write(`${JSON.stringify(initialObject)}\n`);
837-
838-
// Send a malformed update chunk (missing bundleTimestamp)
839-
const malformedChunk = {
840-
updateChunk: 'ReactOnRails.setAsyncValue("should not work")',
841-
};
842-
req.write(`${JSON.stringify(malformedChunk)}\n`);
843-
844-
// Send a valid update chunk after the malformed one
845-
const validChunk = {
846-
bundleTimestamp: SERVER_BUNDLE_TIMESTAMP,
847-
updateChunk: 'ReactOnRails.setAsyncValue("valid update")',
848-
};
849-
req.write(`${JSON.stringify(validChunk)}\n`);
850-
851-
// Send a chunk with invalid JavaScript
852-
const invalidJSChunk = {
853-
bundleTimestamp: SERVER_BUNDLE_TIMESTAMP,
854-
updateChunk: 'this is not valid javascript syntax !!!',
855-
};
856-
req.write(`${JSON.stringify(invalidJSChunk)}\n`);
857-
858-
// End the request
859-
req.end();
860-
861-
// Wait for the response
862-
const response = await responsePromise;
863-
864-
// Verify the response - should still work despite errors
865-
expect(response.statusCode).toBe(200);
866-
expect(response.data).toBe('"valid update"'); // Should resolve with the valid update
867-
});
868-
869-
test('update chunks with non-existent bundle timestamp', async () => {
870-
await createIncrementalVmBundle(TEST_NAME);
871-
const SERVER_BUNDLE_TIMESTAMP = String(BUNDLE_TIMESTAMP);
872-
const NON_EXISTENT_TIMESTAMP = '9999999999999';
873-
874-
// Create the HTTP request
875-
const req = createHttpRequest(SERVER_BUNDLE_TIMESTAMP);
876-
877-
// Set up response handling
878-
const responsePromise = setupResponseHandler(req, true);
879-
880-
// Send the initial object
881-
const initialObject = {
882-
...createInitialObject(SERVER_BUNDLE_TIMESTAMP),
883-
renderingRequest: 'ReactOnRails.getAsyncValue()',
884-
};
885-
req.write(`${JSON.stringify(initialObject)}\n`);
886-
887-
// Send update chunk with non-existent bundle timestamp
888-
const updateChunk = {
889-
bundleTimestamp: NON_EXISTENT_TIMESTAMP,
890-
updateChunk: 'ReactOnRails.setAsyncValue("should not work")',
891-
};
892-
req.write(`${JSON.stringify(updateChunk)}\n`);
893-
894-
// Send a valid update chunk
895-
const validChunk = {
757+
// End the stream to signal completion
758+
const endStreamChunk = {
896759
bundleTimestamp: SERVER_BUNDLE_TIMESTAMP,
897-
updateChunk: 'ReactOnRails.setAsyncValue("valid update")',
760+
updateChunk: 'ReactOnRails.endStream()',
898761
};
899-
req.write(`${JSON.stringify(validChunk)}\n`);
762+
req.write(`${JSON.stringify(endStreamChunk)}\n`);
900763

901764
// End the request
902765
req.end();
@@ -906,7 +769,8 @@ describe('incremental render NDJSON endpoint', () => {
906769

907770
// Verify the response
908771
expect(response.statusCode).toBe(200);
909-
expect(response.data).toBe('"valid update"'); // Should resolve with the valid update
772+
// Since we're returning a stream, the response should indicate streaming
773+
expect(streamedData.length).toBeGreaterThan(0);
910774
});
911775

912776
test('complex multi-bundle streaming scenario', async () => {

0 commit comments

Comments
 (0)