Skip to content

Commit 8a391e7

Browse files
tmp
1 parent 7605907 commit 8a391e7

File tree

2 files changed

+46
-57
lines changed

2 files changed

+46
-57
lines changed

react_on_rails_pro/packages/node-renderer/tests/helper.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,23 @@ export function vmSecondaryBundlePath(testName: string) {
5858
}
5959

6060
export async function createVmBundle(testName: string) {
61+
// Build config with module support before creating VM bundle
62+
buildConfig({
63+
bundlePath: bundlePath(testName),
64+
supportModules: true,
65+
stubTimers: false,
66+
});
6167
await safeCopyFileAsync(getFixtureBundle(), vmBundlePath(testName));
6268
await buildExecutionContext([vmBundlePath(testName)], /* buildVmsIfNeeded */ true);
6369
}
6470

6571
export async function createSecondaryVmBundle(testName: string) {
72+
// Build config with module support before creating VM bundle
73+
buildConfig({
74+
bundlePath: bundlePath(testName),
75+
supportModules: true,
76+
stubTimers: false,
77+
});
6678
await safeCopyFileAsync(getFixtureSecondaryBundle(), vmSecondaryBundlePath(testName));
6779
await buildExecutionContext([vmSecondaryBundlePath(testName)], /* buildVmsIfNeeded */ true);
6880
}

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

Lines changed: 34 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ const railsEnv = 'test';
3131

3232
disableHttp2();
3333

34+
// Helper to create worker with standard options
35+
const createWorker = (options: Parameters<typeof worker>[0] = {}) =>
36+
worker({
37+
serverBundleCachePath: serverBundleCachePathForTest(),
38+
supportModules: true,
39+
stubTimers: false,
40+
...options,
41+
});
42+
3443
describe('worker', () => {
3544
beforeEach(async () => {
3645
await resetForTest(testName);
@@ -41,9 +50,7 @@ describe('worker', () => {
4150
});
4251

4352
test('POST /bundles/:bundleTimestamp/render/:renderRequestDigest when bundle is provided and did not yet exist', async () => {
44-
const app = worker({
45-
serverBundleCachePath: serverBundleCachePathForTest(),
46-
});
53+
const app = createWorker();
4754

4855
const form = formAutoContent({
4956
gemVersion,
@@ -69,9 +76,7 @@ describe('worker', () => {
6976
});
7077

7178
test('POST /bundles/:bundleTimestamp/render/:renderRequestDigest', async () => {
72-
const app = worker({
73-
serverBundleCachePath: serverBundleCachePathForTest(),
74-
});
79+
const app = createWorker();
7580

7681
const form = formAutoContent({
7782
gemVersion,
@@ -105,8 +110,7 @@ describe('worker', () => {
105110
async () => {
106111
await createVmBundleForTest();
107112

108-
const app = worker({
109-
serverBundleCachePath: serverBundleCachePathForTest(),
113+
const app = createWorker({
110114
password: 'password',
111115
});
112116

@@ -132,8 +136,7 @@ describe('worker', () => {
132136
async () => {
133137
await createVmBundleForTest();
134138

135-
const app = worker({
136-
serverBundleCachePath: serverBundleCachePathForTest(),
139+
const app = createWorker({
137140
password: 'password',
138141
});
139142

@@ -159,8 +162,7 @@ describe('worker', () => {
159162
async () => {
160163
await createVmBundleForTest();
161164

162-
const app = worker({
163-
serverBundleCachePath: serverBundleCachePathForTest(),
165+
const app = createWorker({
164166
password: 'my_password',
165167
});
166168

@@ -187,9 +189,7 @@ describe('worker', () => {
187189
async () => {
188190
await createVmBundleForTest();
189191

190-
const app = worker({
191-
serverBundleCachePath: serverBundleCachePathForTest(),
192-
});
192+
const app = createWorker();
193193

194194
const res = await app
195195
.inject()
@@ -211,8 +211,7 @@ describe('worker', () => {
211211
const bundleHash = 'some-bundle-hash';
212212
await createAsset(testName, bundleHash);
213213

214-
const app = worker({
215-
serverBundleCachePath: serverBundleCachePathForTest(),
214+
const app = createWorker({
216215
password: 'my_password',
217216
});
218217

@@ -237,8 +236,7 @@ describe('worker', () => {
237236
const bundleHash = 'some-bundle-hash';
238237
await createAsset(testName, bundleHash);
239238

240-
const app = worker({
241-
serverBundleCachePath: serverBundleCachePathForTest(),
239+
const app = createWorker({
242240
password: 'my_password',
243241
});
244242

@@ -261,8 +259,7 @@ describe('worker', () => {
261259

262260
test('post /asset-exists requires targetBundles (protocol version 2.0.0)', async () => {
263261
await createAsset(testName, String(BUNDLE_TIMESTAMP));
264-
const app = worker({
265-
serverBundleCachePath: serverBundleCachePathForTest(),
262+
const app = createWorker({
266263
password: 'my_password',
267264
});
268265

@@ -283,8 +280,7 @@ describe('worker', () => {
283280
test('post /upload-assets', async () => {
284281
const bundleHash = 'some-bundle-hash';
285282

286-
const app = worker({
287-
serverBundleCachePath: serverBundleCachePathForTest(),
283+
const app = createWorker({
288284
password: 'my_password',
289285
});
290286

@@ -307,8 +303,7 @@ describe('worker', () => {
307303
const bundleHash = 'some-bundle-hash';
308304
const bundleHashOther = 'some-other-bundle-hash';
309305

310-
const app = worker({
311-
serverBundleCachePath: serverBundleCachePathForTest(),
306+
const app = createWorker({
312307
password: 'my_password',
313308
});
314309

@@ -334,9 +329,7 @@ describe('worker', () => {
334329
test('allows request when gem version matches package version', async () => {
335330
await createVmBundleForTest();
336331

337-
const app = worker({
338-
serverBundleCachePath: serverBundleCachePathForTest(),
339-
});
332+
const app = createWorker();
340333

341334
const res = await app
342335
.inject()
@@ -355,9 +348,7 @@ describe('worker', () => {
355348
test('rejects request in development when gem version does not match', async () => {
356349
await createVmBundleForTest();
357350

358-
const app = worker({
359-
serverBundleCachePath: serverBundleCachePathForTest(),
360-
});
351+
const app = createWorker();
361352

362353
const res = await app
363354
.inject()
@@ -379,9 +370,7 @@ describe('worker', () => {
379370
test('allows request in production when gem version does not match (with warning)', async () => {
380371
await createVmBundleForTest();
381372

382-
const app = worker({
383-
serverBundleCachePath: serverBundleCachePathForTest(),
384-
});
373+
const app = createWorker();
385374

386375
const res = await app
387376
.inject()
@@ -400,9 +389,7 @@ describe('worker', () => {
400389
test('normalizes gem version with dot before prerelease (4.0.0.rc.1 == 4.0.0-rc.1)', async () => {
401390
await createVmBundleForTest();
402391

403-
const app = worker({
404-
serverBundleCachePath: serverBundleCachePathForTest(),
405-
});
392+
const app = createWorker();
406393

407394
// If package version is 4.0.0, this tests that 4.0.0.rc.1 gets normalized to 4.0.0-rc.1
408395
// For this test to work properly, we need to use a version that when normalized matches
@@ -426,9 +413,7 @@ describe('worker', () => {
426413
test('normalizes gem version case-insensitively (4.0.0-RC.1 == 4.0.0-rc.1)', async () => {
427414
await createVmBundleForTest();
428415

429-
const app = worker({
430-
serverBundleCachePath: serverBundleCachePathForTest(),
431-
});
416+
const app = createWorker();
432417

433418
const gemVersionUpperCase = packageJson.version.toUpperCase();
434419

@@ -449,9 +434,7 @@ describe('worker', () => {
449434
test('handles whitespace in gem version', async () => {
450435
await createVmBundleForTest();
451436

452-
const app = worker({
453-
serverBundleCachePath: serverBundleCachePathForTest(),
454-
});
437+
const app = createWorker();
455438

456439
const gemVersionWithWhitespace = ` ${packageJson.version} `;
457440

@@ -474,8 +457,7 @@ describe('worker', () => {
474457
const bundleHash = 'some-bundle-hash';
475458
const secondaryBundleHash = 'secondary-bundle-hash';
476459

477-
const app = worker({
478-
serverBundleCachePath: serverBundleCachePathForTest(),
460+
const app = createWorker({
479461
password: 'my_password',
480462
});
481463

@@ -529,8 +511,7 @@ describe('worker', () => {
529511
test('post /upload-assets with only bundles (no assets)', async () => {
530512
const bundleHash = 'bundle-only-hash';
531513

532-
const app = worker({
533-
serverBundleCachePath: serverBundleCachePathForTest(),
514+
const app = createWorker({
534515
password: 'my_password',
535516
});
536517

@@ -565,8 +546,7 @@ describe('worker', () => {
565546
test('post /upload-assets with no assets and no bundles (empty request)', async () => {
566547
const bundleHash = 'empty-request-hash';
567548

568-
const app = worker({
569-
serverBundleCachePath: serverBundleCachePathForTest(),
549+
const app = createWorker({
570550
password: 'my_password',
571551
});
572552

@@ -593,8 +573,7 @@ describe('worker', () => {
593573
test('post /upload-assets with duplicate bundle hash silently skips overwrite and returns 200', async () => {
594574
const bundleHash = 'duplicate-bundle-hash';
595575

596-
const app = worker({
597-
serverBundleCachePath: serverBundleCachePathForTest(),
576+
const app = createWorker({
598577
password: 'my_password',
599578
});
600579

@@ -669,16 +648,15 @@ describe('worker', () => {
669648
expect(files).toHaveLength(1);
670649
expect(files[0]).toBe(`${bundleHash}.js`);
671650

672-
// Verify the original content is preserved (62 bytes from bundle.js, not 84 from secondary-bundle.js)
673-
expect(secondBundleSize).toBe(62); // Size of getFixtureBundle(), not getFixtureSecondaryBundle()
651+
// Verify the original content is preserved (1646 bytes from bundle.js, not 1689 from secondary-bundle.js)
652+
expect(secondBundleSize).toBe(1646); // Size of getFixtureBundle(), not getFixtureSecondaryBundle()
674653
});
675654

676655
test('post /upload-assets with bundles placed in their own hash directories, not targetBundles directories', async () => {
677656
const bundleHash = 'actual-bundle-hash';
678657
const targetBundleHash = 'target-bundle-hash'; // Different from actual bundle hash
679658

680-
const app = worker({
681-
serverBundleCachePath: serverBundleCachePathForTest(),
659+
const app = createWorker({
682660
password: 'my_password',
683661
});
684662

@@ -723,8 +701,7 @@ describe('worker', () => {
723701
describe('incremental render endpoint', () => {
724702
// Helper functions to reduce code duplication
725703
const createWorkerApp = (password = 'my_password') =>
726-
worker({
727-
serverBundleCachePath: serverBundleCachePathForTest(),
704+
createWorker({
728705
password,
729706
});
730707

0 commit comments

Comments
 (0)