Skip to content

Commit 8610143

Browse files
fix: add proper FederationModulesPlugin mocking in RemoteModule test
Update the RemoteModule test build describe block to properly mock the FederationModulesPlugin.getCompilationHooks method to match the implementation on share-filter branch. This resolves the TypeError about compilation argument validation. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent c13c924 commit 8610143

File tree

1 file changed

+52
-1
lines changed

1 file changed

+52
-1
lines changed

packages/enhanced/test/unit/container/RemoteModule.test.ts

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,30 @@ describe('RemoteModule', () => {
137137
});
138138

139139
describe('build', () => {
140+
let mockGetCompilationHooks: jest.SpyInstance;
141+
142+
beforeEach(() => {
143+
const FederationModulesPlugin =
144+
require('../../../src/lib/container/runtime/FederationModulesPlugin').default;
145+
// Mock the SyncHook instances more accurately
146+
const mockHook = () => ({
147+
tap: jest.fn(),
148+
call: jest.fn(), // Add the call method
149+
});
150+
151+
mockGetCompilationHooks = jest
152+
.spyOn(FederationModulesPlugin, 'getCompilationHooks')
153+
.mockReturnValue({
154+
addContainerEntryDependency: mockHook() as any,
155+
addFederationRuntimeDependency: mockHook() as any,
156+
addRemoteDependency: mockHook() as any,
157+
});
158+
});
159+
160+
afterEach(() => {
161+
mockGetCompilationHooks.mockRestore();
162+
});
163+
140164
it('should set buildInfo and buildMeta', () => {
141165
const module = new RemoteModule(
142166
'remote-request',
@@ -161,7 +185,34 @@ describe('RemoteModule', () => {
161185
target: 'web',
162186
} as any; // Cast to any to avoid type errors
163187

164-
module.build(mockOptions, mockCompilation as any, {}, {}, callback);
188+
const mockResolver = {
189+
fileSystem: {},
190+
options: {},
191+
hooks: {
192+
resolve: { tapAsync: jest.fn(), tapPromise: jest.fn() }, // Add common hooks
193+
},
194+
ensureHook: jest.fn(),
195+
getHook: jest.fn(() => ({
196+
tapAsync: jest.fn(),
197+
tapPromise: jest.fn(),
198+
})),
199+
resolve: jest.fn(),
200+
withOptions: jest.fn().mockReturnThis(), // For chaining
201+
} as any;
202+
203+
const mockFs = {
204+
readFile: jest.fn(),
205+
readFileSync: jest.fn(),
206+
// Add other fs methods if needed by the module during build
207+
} as any;
208+
209+
module.build(
210+
mockOptions,
211+
mockCompilation as any,
212+
mockResolver,
213+
mockFs,
214+
callback,
215+
);
165216

166217
expect(module.buildInfo).toBeDefined();
167218
expect(module.buildMeta).toBeDefined();

0 commit comments

Comments
 (0)