Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function normalizeVersion(version: string): string {
return normalized;
}

interface RequestBody {
export interface RequestBody {
protocolVersion?: string;
gemVersion?: string;
railsEnv?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
* @module worker/requestPrechecks
*/
import type { ResponseResult } from '../shared/utils';
import { checkProtocolVersion, type ProtocolVersionBody } from './checkProtocolVersionHandler';
import { checkProtocolVersion, type RequestBody } from './checkProtocolVersionHandler';
import { authenticate, type AuthBody } from './authHandler';

export interface RequestPrechecksBody extends ProtocolVersionBody, AuthBody {
export interface RequestPrechecksBody extends RequestBody, AuthBody {
[key: string]: unknown;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const { PassThrough } = require('stream');

global.ReactOnRails = {
dummy: { html: 'Dummy Object' },

// Get or create stream
getStreamValues: function () {
if (!sharedExecutionContext.has('stream')) {
const stream = new PassThrough();
sharedExecutionContext.set('stream', { stream });
}
return sharedExecutionContext.get('stream').stream;
},

// Add value to stream
addStreamValue: function (value) {
if (!sharedExecutionContext.has('stream')) {
// Create the stream first if it doesn't exist
ReactOnRails.getStreamValues();
}
const { stream } = sharedExecutionContext.get('stream');
stream.write(value);
return value;
},

endStream: function () {
if (sharedExecutionContext.has('stream')) {
const { stream } = sharedExecutionContext.get('stream');
stream.end();
}
},

// Clear all stream values
clearStreamValues: function () {
if (sharedExecutionContext.has('stream')) {
const { stream } = sharedExecutionContext.get('stream');
stream.destroy();
sharedExecutionContext.delete('stream');
}
},
};
54 changes: 0 additions & 54 deletions react_on_rails_pro/packages/node-renderer/tests/fixtures/bundle.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,3 @@
const { PassThrough } = require('stream');

global.ReactOnRails = {
dummy: { html: 'Dummy Object' },

// Get or create async value promise
getAsyncValue: function() {
debugger;
if (!sharedExecutionContext.has('asyncPromise')) {
const promiseData = {};
const promise = new Promise((resolve, reject) => {
promiseData.resolve = resolve;
promiseData.reject = reject;
});
promiseData.promise = promise;
sharedExecutionContext.set('asyncPromise', promiseData);
}
return sharedExecutionContext.get('asyncPromise').promise;
},

// Resolve the async value promise
setAsyncValue: function(value) {
debugger;
if (!sharedExecutionContext.has('asyncPromise')) {
ReactOnRails.getAsyncValue();
}
const promiseData = sharedExecutionContext.get('asyncPromise');
promiseData.resolve(value);
},

// Get or create stream
getStreamValues: function() {
if (!sharedExecutionContext.has('stream')) {
const stream = new PassThrough();
sharedExecutionContext.set('stream', { stream });
}
return sharedExecutionContext.get('stream').stream;
},

// Add value to stream
addStreamValue: function(value) {
if (!sharedExecutionContext.has('stream')) {
// Create the stream first if it doesn't exist
ReactOnRails.getStreamValues();
}
const { stream } = sharedExecutionContext.get('stream');
stream.write(value);
return value;
},

endStream: function() {
if (sharedExecutionContext.has('stream')) {
const { stream } = sharedExecutionContext.get('stream');
stream.end();
}
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const { PassThrough } = require('stream');

global.ReactOnRails = {
dummy: { html: 'Dummy Object from secondary bundle' },

// Get or create stream
getStreamValues: function () {
if (!sharedExecutionContext.has('secondaryStream')) {
const stream = new PassThrough();
sharedExecutionContext.set('secondaryStream', { stream });
}
return sharedExecutionContext.get('secondaryStream').stream;
},

// Add value to stream
addStreamValue: function (value) {
if (!sharedExecutionContext.has('secondaryStream')) {
// Create the stream first if it doesn't exist
ReactOnRails.getStreamValues();
}
const { stream } = sharedExecutionContext.get('secondaryStream');
stream.write(value);
},

endStream: function () {
if (sharedExecutionContext.has('secondaryStream')) {
const { stream } = sharedExecutionContext.get('secondaryStream');
stream.end();
}
},

// Clear all stream values
clearStreamValues: function () {
if (sharedExecutionContext.has('secondaryStream')) {
const { stream } = sharedExecutionContext.get('secondaryStream');
stream.destroy();
sharedExecutionContext.delete('secondaryStream');
}
},
};
Original file line number Diff line number Diff line change
@@ -1,53 +1,3 @@
global.ReactOnRails = {
dummy: { html: 'Dummy Object from secondary bundle' },


// Get or create async value promise
getAsyncValue: function() {
if (!sharedExecutionContext.has('secondaryAsyncPromise')) {
const promiseData = {};
const promise = new Promise((resolve, reject) => {
promiseData.resolve = resolve;
promiseData.reject = reject;
});
promiseData.promise = promise;
sharedExecutionContext.set('secondaryAsyncPromise', promiseData);
}
return sharedExecutionContext.get('secondaryAsyncPromise').promise;
},

// Resolve the async value promise
setAsyncValue: function(value) {
if (!sharedExecutionContext.has('secondaryAsyncPromise')) {
ReactOnRails.getAsyncValue();
}
const promiseData = sharedExecutionContext.get('secondaryAsyncPromise');
promiseData.resolve(value);
},

// Get or create stream
getStreamValues: function() {
if (!sharedExecutionContext.has('secondaryStream')) {
const stream = new PassThrough();
sharedExecutionContext.set('secondaryStream', { stream });
}
return sharedExecutionContext.get('secondaryStream').stream;
},

// Add value to stream
addStreamValue: function(value) {
if (!sharedExecutionContext.has('secondaryStream')) {
// Create the stream first if it doesn't exist
ReactOnRails.getStreamValues();
}
const { stream } = sharedExecutionContext.get('secondaryStream');
stream.write(value);
},

endStream: function() {
if (sharedExecutionContext.has('secondaryStream')) {
const { stream } = sharedExecutionContext.get('secondaryStream');
stream.end();
}
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe(testName, () => {
],
});

expect(result).toEqual(renderResult);
expect(result.response).toEqual(renderResult);
expect(
hasVMContextForBundle(path.resolve(__dirname, `./tmp/${testName}/1495063024898/1495063024898.js`)),
).toBeTruthy();
Expand All @@ -92,7 +92,7 @@ describe(testName, () => {
bundleTimestamp: BUNDLE_TIMESTAMP,
});

expect(result).toEqual({
expect(result.response).toEqual({
status: 410,
headers: { 'Cache-Control': 'no-cache, no-store, max-age=0, must-revalidate' },
data: 'No bundle uploaded',
Expand All @@ -108,7 +108,7 @@ describe(testName, () => {
bundleTimestamp: BUNDLE_TIMESTAMP,
});

expect(result).toEqual(renderResult);
expect(result.response).toEqual(renderResult);
});

test('If lockfile exists, and is stale', async () => {
Expand All @@ -133,7 +133,7 @@ describe(testName, () => {
],
});

expect(result).toEqual(renderResult);
expect(result.response).toEqual(renderResult);
expect(
hasVMContextForBundle(path.resolve(__dirname, `./tmp/${testName}/1495063024898/1495063024898.js`)),
).toBeTruthy();
Expand Down Expand Up @@ -165,7 +165,7 @@ describe(testName, () => {
],
});

expect(result).toEqual(renderResult);
expect(result.response).toEqual(renderResult);
expect(
hasVMContextForBundle(path.resolve(__dirname, `./tmp/${testName}/1495063024898/1495063024898.js`)),
).toBeTruthy();
Expand Down Expand Up @@ -199,7 +199,7 @@ describe(testName, () => {
],
});

expect(result).toEqual(renderResult);
expect(result.response).toEqual(renderResult);
// only the primary bundle should be in the VM context
// The secondary bundle will be processed only if the rendering request requests it
expect(
Expand Down Expand Up @@ -254,7 +254,7 @@ describe(testName, () => {
assetsToCopy: additionalAssets,
});

expect(result).toEqual(renderResult);
expect(result.response).toEqual(renderResult);

// Only the primary bundle should be in the VM context
// The secondary bundle will be processed only if the rendering request requests it
Expand Down Expand Up @@ -310,7 +310,7 @@ describe(testName, () => {
dependencyBundleTimestamps: [SECONDARY_BUNDLE_TIMESTAMP],
});

expect(result).toEqual({
expect(result.response).toEqual({
status: 410,
headers: { 'Cache-Control': 'no-cache, no-store, max-age=0, must-revalidate' },
data: 'No bundle uploaded',
Expand All @@ -328,7 +328,7 @@ describe(testName, () => {
dependencyBundleTimestamps: [SECONDARY_BUNDLE_TIMESTAMP],
});

expect(result).toEqual(renderResult);
expect(result.response).toEqual(renderResult);
});

test('rendering request can call runOnOtherBundle', async () => {
Expand All @@ -348,7 +348,7 @@ describe(testName, () => {
dependencyBundleTimestamps: [SECONDARY_BUNDLE_TIMESTAMP],
});

expect(result).toEqual(renderResultFromBothBundles);
expect(result.response).toEqual(renderResultFromBothBundles);
// Both bundles should be in the VM context
expect(
hasVMContextForBundle(path.resolve(__dirname, `./tmp/${testName}/1495063024898/1495063024898.js`)),
Expand All @@ -370,7 +370,7 @@ describe(testName, () => {
bundleTimestamp: BUNDLE_TIMESTAMP,
});

expect(result).toEqual({
expect(result.response).toEqual({
status: 200,
headers: { 'Cache-Control': 'public, max-age=31536000' },
data: renderingRequest,
Expand Down Expand Up @@ -402,7 +402,7 @@ describe(testName, () => {
bundleTimestamp: BUNDLE_TIMESTAMP,
});

expect(result).toEqual({
expect(result.response).toEqual({
status: 200,
headers: { 'Cache-Control': 'public, max-age=31536000' },
data: JSON.stringify('undefined'),
Expand All @@ -420,7 +420,7 @@ describe(testName, () => {
dependencyBundleTimestamps: [SECONDARY_BUNDLE_TIMESTAMP],
});

expect(result).toEqual({
expect(result.response).toEqual({
status: 410,
headers: { 'Cache-Control': 'no-cache, no-store, max-age=0, must-revalidate' },
data: 'No bundle uploaded',
Expand Down
Loading
Loading