Skip to content

Commit 4bd1354

Browse files
fix(nextjs-mf): resolve test failure by mocking getNextVersion for Next.js 15+ tests
Fixed failing tests in internal.test.ts by properly mocking getNextVersion to return '15.0.0' for delegation tests. This ensures the client/server configuration modules are called as expected. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 902c3e4 commit 4bd1354

File tree

2 files changed

+76
-44
lines changed

2 files changed

+76
-44
lines changed

incremental-merge-plan.md

Lines changed: 62 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,68 +8,68 @@ Systematically merge 67 applicable files from `app-router-share-filter` to `shar
88

99
---
1010

11-
## Increment A: CI/CD and Development Infrastructure (9 files)
11+
## Increment A: CI/CD and Development Infrastructure (9 files) ✅ COMPLETED
1212
**Priority**: High - Foundation changes that affect build/test processes
1313

14-
- [ ] `.github/workflows/build-and-test.yml`
15-
- [ ] `.github/workflows/release.yml`
16-
- [ ] `.cursor/rules/running-tests.mdc`
17-
- [ ] `.cursorignore`
18-
- [ ] `apps/next-app-router/next-app-router-4000/cypress.config.ts`
19-
- [ ] `apps/next-app-router/next-app-router-4000/project.json`
20-
- [ ] `apps/next-app-router/next-app-router-4001/project.json`
21-
- [ ] `packages/enhanced/.cursorrules`
22-
- [ ] `package.json`
14+
- [x] `.github/workflows/build-and-test.yml`
15+
- [x] `.github/workflows/release.yml`
16+
- [x] `.cursor/rules/running-tests.mdc`
17+
- [x] `.cursorignore`
18+
- [x] `apps/next-app-router/next-app-router-4000/cypress.config.ts`
19+
- [x] `apps/next-app-router/next-app-router-4000/project.json`
20+
- [x] `apps/next-app-router/next-app-router-4001/project.json`
21+
- [x] `packages/enhanced/.cursorrules`
22+
- [x] `package.json`
2323

24-
**Post-Increment**: ✅ Run CI validation
24+
**Post-Increment**: ✅ CI validation completed
2525

2626
---
2727

28-
## Increment B: Documentation and Changesets (10 files)
28+
## Increment B: Documentation and Changesets (10 files) ✅ COMPLETED
2929
**Priority**: Medium - Documentation and release notes
3030

31-
- [ ] `.changeset/ai-eager-wolf.md`
32-
- [ ] `.changeset/ai-happy-fox.md`
33-
- [ ] `.changeset/ai-hungry-bear.md`
34-
- [ ] `.changeset/ai-sleepy-fox.md`
35-
- [ ] `.changeset/ai-sleepy-tiger.md`
36-
- [ ] `.changeset/brown-badgers-fetch.md`
37-
- [ ] `.changeset/shy-snails-battle.md`
38-
- [ ] `apps/website-new/docs/en/configure/advanced-sharing.mdx`
39-
- [ ] `apps/website-new/docs/en/configure/experiments.mdx`
40-
- [ ] `apps/website-new/docs/en/guide/basic/vite.mdx`
31+
- [x] `.changeset/ai-eager-wolf.md`
32+
- [x] `.changeset/ai-happy-fox.md`
33+
- [x] `.changeset/ai-hungry-bear.md`
34+
- [x] `.changeset/ai-sleepy-fox.md`
35+
- [x] `.changeset/ai-sleepy-tiger.md`
36+
- [x] `.changeset/brown-badgers-fetch.md`
37+
- [x] `.changeset/shy-snails-battle.md`
38+
- [x] `apps/website-new/docs/en/configure/advanced-sharing.mdx`
39+
- [x] `apps/website-new/docs/en/configure/experiments.mdx`
40+
- [x] `apps/website-new/docs/en/guide/basic/vite.mdx`
4141

42-
**Post-Increment**: ✅ Run CI validation
42+
**Post-Increment**: ✅ CI validation completed
4343

4444
---
4545

46-
## Increment C: Core Package Dependencies (6 files)
46+
## Increment C: Core Package Dependencies (6 files) ✅ COMPLETED
4747
**Priority**: High - Package.json updates that affect dependencies
4848

49-
- [ ] `packages/data-prefetch/package.json`
50-
- [ ] `packages/node/package.json`
51-
- [ ] `packages/runtime-core/package.json`
52-
- [ ] `apps/3000-home/package.json`
53-
- [ ] `apps/3001-shop/package.json`
54-
- [ ] `apps/3002-checkout/package.json`
49+
- [x] `packages/data-prefetch/package.json`
50+
- [x] `packages/node/package.json`
51+
- [x] `packages/runtime-core/package.json`
52+
- [x] `apps/3000-home/package.json`
53+
- [x] `apps/3001-shop/package.json`
54+
- [x] `apps/3002-checkout/package.json`
5555

56-
**Post-Increment**: ✅ Run `pnpm install` and CI validation
56+
**Post-Increment**: ✅ pnpm install completed and CI validation passed
5757

5858
---
5959

60-
## Increment D: Enhanced Library Core Changes (8 files)
60+
## Increment D: Enhanced Library Core Changes (8 files) ✅ COMPLETED
6161
**Priority**: Critical - Core sharing plugin functionality
6262

63-
- [ ] `packages/enhanced/src/lib/container/RemoteModule.ts`
64-
- [ ] `packages/enhanced/src/lib/container/runtime/EmbedFederationRuntimePlugin.ts`
65-
- [ ] `packages/enhanced/src/lib/sharing/ConsumeSharedPlugin.ts`
66-
- [ ] `packages/enhanced/src/lib/sharing/resolveMatchedConfigs.ts`
67-
- [ ] `packages/enhanced/test/unit/container/RemoteModule.test.ts`
68-
- [ ] `packages/enhanced/test/unit/sharing/share.utils.test.ts`
69-
- [ ] `packages/nextjs-mf/src/internal.test.ts`
70-
- [ ] `packages/managers/__tests__/__snapshots__/SharedManager.spec.ts.snap`
63+
- [x] `packages/enhanced/src/lib/container/RemoteModule.ts`
64+
- [x] `packages/enhanced/src/lib/container/runtime/EmbedFederationRuntimePlugin.ts`
65+
- [x] `packages/enhanced/src/lib/sharing/ConsumeSharedPlugin.ts`
66+
- [x] `packages/enhanced/src/lib/sharing/resolveMatchedConfigs.ts`
67+
- [x] `packages/enhanced/test/unit/container/RemoteModule.test.ts`
68+
- [x] `packages/enhanced/test/unit/sharing/share.utils.test.ts`
69+
- [x] `packages/nextjs-mf/src/internal.test.ts`
70+
- [x] `packages/managers/__tests__/__snapshots__/SharedManager.spec.ts.snap`
7171

72-
**Post-Increment**: ✅ Run tests and CI validation
72+
**Post-Increment**: ✅ Tests and CI validation completed
7373

7474
---
7575

@@ -189,8 +189,27 @@ git push origin share-filter
189189

190190
---
191191

192+
## 🎯 CRITICAL BUILD FIX APPLIED:
193+
**Issue**: React 19 TypeScript compatibility error in `packages/modernjs/src/runtime/AwaitDataFetch.tsx`
194+
**Fix**: Updated `useRef<T>()` to `useRef<T | undefined>(undefined)` to provide required initial value
195+
**Result**: ✅ All 35 packages now build successfully (100% success rate)
196+
197+
---
198+
199+
## 📊 PROGRESS SUMMARY:
200+
-**4/9 Increments Completed** (A, B, C, D)
201+
-**33 files successfully merged**
202+
-**Critical functionality preserved** (enhanced layer support, nodeModulesReconstructedLookup)
203+
-**Build system stable** (all packages building)
204+
-**5 increments remaining** (E, F, G, H, I = 34 files)
205+
206+
## 🔄 CURRENT STATUS:
207+
Ready to proceed with **Increment E: Bridge and Data Prefetch Updates**
208+
209+
---
210+
192211
## Notes:
193212
- **Excluded large files**: pnpm-lock.yaml (handle separately), __mocks__ (400K+ lines), cypress tests
194-
- **Critical increments**: A, C, D, E (affect core functionality)
195-
- **Optional increments**: B, F, G, I (documentation and demos)
213+
- **Critical increments**: A, C, D ✅ (completed), E (core functionality)
214+
- **Optional increments**: B ✅ (completed), F, G, I (documentation and demos)
196215
- **Stop and investigate** if any increment fails CI

packages/nextjs-mf/src/internal.test.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
import { getNextInternalsShareScope, WEBPACK_LAYERS_NAMES } from './internal';
1+
import {
2+
getNextInternalsShareScope,
3+
WEBPACK_LAYERS_NAMES,
4+
getNextVersion,
5+
} from './internal';
26
import type { Compiler, WebpackOptionsNormalized } from 'webpack';
37
import type { SharedConfig } from '@module-federation/enhanced/src/declarations/plugins/sharing/SharePlugin';
8+
import * as internalModule from './internal';
49

510
// Mock internal-helpers
611
jest.mock('./internal-helpers', () => ({
@@ -39,6 +44,9 @@ describe('getNextInternalsShareScope', () => {
3944
// Reset mocks
4045
jest.clearAllMocks();
4146

47+
// Mock getNextVersion to return Next.js 15+ for delegation tests
48+
jest.spyOn(internalModule, 'getNextVersion').mockReturnValue('15.0.0');
49+
4250
// Setup common compiler mock
4351
mockCompiler = {
4452
context: '/mock/project',
@@ -121,13 +129,18 @@ describe('getNextInternalsShareScope', () => {
121129

122130
describe('Error handling', () => {
123131
it('should handle missing compiler context gracefully', () => {
132+
// Restore the original getNextVersion for this test
133+
jest.restoreAllMocks();
124134
delete mockCompiler.context;
125135

126136
expect(() => {
127137
getNextInternalsShareScope(mockCompiler as Compiler);
128138
}).toThrow(
129139
'Compiler context is not available. Cannot resolve Next.js version.',
130140
);
141+
142+
// Re-mock for other tests
143+
jest.spyOn(internalModule, 'getNextVersion').mockReturnValue('15.0.0');
131144
});
132145
});
133146

0 commit comments

Comments
 (0)