Skip to content

Commit b299408

Browse files
tmp
1 parent befe24a commit b299408

File tree

2 files changed

+46
-57
lines changed

2 files changed

+46
-57
lines changed

packages/react-on-rails-pro-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
}

packages/react-on-rails-pro-node-renderer/tests/worker.test.ts

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

3333
disableHttp2();
3434

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

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

4956
const form = formAutoContent({
5057
gemVersion,
@@ -70,9 +77,7 @@ describe('worker', () => {
7077
});
7178

7279
test('POST /bundles/:bundleTimestamp/render/:renderRequestDigest', async () => {
73-
const app = worker({
74-
serverBundleCachePath: serverBundleCachePathForTest(),
75-
});
80+
const app = createWorker();
7681

7782
const form = formAutoContent({
7883
gemVersion,
@@ -106,8 +111,7 @@ describe('worker', () => {
106111
async () => {
107112
await createVmBundleForTest();
108113

109-
const app = worker({
110-
serverBundleCachePath: serverBundleCachePathForTest(),
114+
const app = createWorker({
111115
password: 'password',
112116
});
113117

@@ -133,8 +137,7 @@ describe('worker', () => {
133137
async () => {
134138
await createVmBundleForTest();
135139

136-
const app = worker({
137-
serverBundleCachePath: serverBundleCachePathForTest(),
140+
const app = createWorker({
138141
password: 'password',
139142
});
140143

@@ -160,8 +163,7 @@ describe('worker', () => {
160163
async () => {
161164
await createVmBundleForTest();
162165

163-
const app = worker({
164-
serverBundleCachePath: serverBundleCachePathForTest(),
166+
const app = createWorker({
165167
password: 'my_password',
166168
});
167169

@@ -188,9 +190,7 @@ describe('worker', () => {
188190
async () => {
189191
await createVmBundleForTest();
190192

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

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

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

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

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

@@ -262,8 +260,7 @@ describe('worker', () => {
262260

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

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

287-
const app = worker({
288-
serverBundleCachePath: serverBundleCachePathForTest(),
284+
const app = createWorker({
289285
password: 'my_password',
290286
});
291287

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

311-
const app = worker({
312-
serverBundleCachePath: serverBundleCachePathForTest(),
307+
const app = createWorker({
313308
password: 'my_password',
314309
});
315310

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

338-
const app = worker({
339-
serverBundleCachePath: serverBundleCachePathForTest(),
340-
});
333+
const app = createWorker();
341334

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

359-
const app = worker({
360-
serverBundleCachePath: serverBundleCachePathForTest(),
361-
});
352+
const app = createWorker();
362353

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

383-
const app = worker({
384-
serverBundleCachePath: serverBundleCachePathForTest(),
385-
});
374+
const app = createWorker();
386375

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

404-
const app = worker({
405-
serverBundleCachePath: serverBundleCachePathForTest(),
406-
});
393+
const app = createWorker();
407394

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

430-
const app = worker({
431-
serverBundleCachePath: serverBundleCachePathForTest(),
432-
});
417+
const app = createWorker();
433418

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

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

453-
const app = worker({
454-
serverBundleCachePath: serverBundleCachePathForTest(),
455-
});
438+
const app = createWorker();
456439

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

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

478-
const app = worker({
479-
serverBundleCachePath: serverBundleCachePathForTest(),
461+
const app = createWorker({
480462
password: 'my_password',
481463
});
482464

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

533-
const app = worker({
534-
serverBundleCachePath: serverBundleCachePathForTest(),
515+
const app = createWorker({
535516
password: 'my_password',
536517
});
537518

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

569-
const app = worker({
570-
serverBundleCachePath: serverBundleCachePathForTest(),
550+
const app = createWorker({
571551
password: 'my_password',
572552
});
573553

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

597-
const app = worker({
598-
serverBundleCachePath: serverBundleCachePathForTest(),
577+
const app = createWorker({
599578
password: 'my_password',
600579
});
601580

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

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

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

681-
const app = worker({
682-
serverBundleCachePath: serverBundleCachePathForTest(),
660+
const app = createWorker({
683661
password: 'my_password',
684662
});
685663

@@ -724,8 +702,7 @@ describe('worker', () => {
724702
describe('incremental render endpoint', () => {
725703
// Helper functions to reduce code duplication
726704
const createWorkerApp = (password = 'my_password') =>
727-
worker({
728-
serverBundleCachePath: serverBundleCachePathForTest(),
705+
createWorker({
729706
password,
730707
});
731708

0 commit comments

Comments
 (0)