Skip to content

Commit 2a23407

Browse files
chore: fix conflicts
1 parent b8d7c28 commit 2a23407

File tree

3 files changed

+111
-22
lines changed

3 files changed

+111
-22
lines changed

packages/enhanced/src/lib/container/ContainerReferencePlugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class ContainerReferencePlugin {
135135
//@ts-ignore
136136
config.shareScope,
137137
);
138-
hooks.addRemoteDependency.call(remoteModule);
138+
// Note: RemoteModule will call hooks.addRemoteDependency itself during build
139139
return remoteModule;
140140
}
141141
}

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

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ jest.mock('../../../src/lib/container/runtime/FederationModulesPlugin', () => {
4242
})),
4343
};
4444

45-
return mockFederationModulesPlugin;
45+
return {
46+
default: mockFederationModulesPlugin,
47+
...mockFederationModulesPlugin,
48+
};
4649
});
4750

4851
describe('RemoteModule', () => {
@@ -159,25 +162,21 @@ describe('RemoteModule', () => {
159162
let mockGetCompilationHooks: jest.SpyInstance;
160163

161164
beforeEach(() => {
162-
const FederationModulesPlugin =
163-
require('../../../src/lib/container/runtime/FederationModulesPlugin').default;
164-
// Mock the SyncHook instances more accurately
165-
const mockHook = () => ({
166-
tap: jest.fn(),
167-
call: jest.fn(), // Add the call method
168-
});
169-
170-
mockGetCompilationHooks = jest
171-
.spyOn(FederationModulesPlugin, 'getCompilationHooks')
172-
.mockReturnValue({
173-
addContainerEntryDependency: mockHook() as any,
174-
addFederationRuntimeDependency: mockHook() as any,
175-
addRemoteDependency: mockHook() as any,
176-
});
165+
// The mock is already set up in the module mock above
166+
// Just reference it for spying if needed
167+
const FederationModulesPlugin = require('../../../src/lib/container/runtime/FederationModulesPlugin');
168+
169+
// Since we already have a mock, we can just access it directly
170+
mockGetCompilationHooks =
171+
FederationModulesPlugin.getCompilationHooks ||
172+
FederationModulesPlugin.default?.getCompilationHooks;
177173
});
178174

179175
afterEach(() => {
180-
mockGetCompilationHooks.mockRestore();
176+
// Clear mocks but don't restore since it's a module mock
177+
if (mockGetCompilationHooks && mockGetCompilationHooks.mockClear) {
178+
mockGetCompilationHooks.mockClear();
179+
}
181180
});
182181

183182
it('should set buildInfo and buildMeta', () => {

packages/enhanced/test/unit/sharing/SharePlugin.test.ts

Lines changed: 94 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ describe('SharePlugin', () => {
846846
ProvideSharedPluginMock.mockClear();
847847
});
848848

849-
it('should transform all properties from SharedConfig to ConsumesConfig', () => {
849+
it('should transform all properties from SharedConfig to ConsumesConfig with exclude', () => {
850850
const sharedConfig = {
851851
import: './path/to/module',
852852
shareKey: 'customKey',
@@ -861,7 +861,6 @@ describe('SharePlugin', () => {
861861
layer: 'layer',
862862
request: 'custom-request',
863863
exclude: { version: '^0.9.0' },
864-
include: { version: '^1.0.0' },
865864
};
866865

867866
const plugin = new SharePlugin({
@@ -893,11 +892,59 @@ describe('SharePlugin', () => {
893892
layer: sharedConfig.layer,
894893
request: sharedConfig.request,
895894
exclude: sharedConfig.exclude,
895+
});
896+
});
897+
898+
it('should transform all properties from SharedConfig to ConsumesConfig with include', () => {
899+
const sharedConfig = {
900+
import: './path/to/module',
901+
shareKey: 'customKey',
902+
shareScope: 'customScope',
903+
requiredVersion: '^1.0.0',
904+
strictVersion: true,
905+
singleton: true,
906+
packageName: 'my-package',
907+
eager: true,
908+
version: '1.0.0',
909+
issuerLayer: 'issuerLayer',
910+
layer: 'layer',
911+
request: 'custom-request',
912+
include: { version: '^1.0.0' },
913+
};
914+
915+
const plugin = new SharePlugin({
916+
shared: {
917+
react: sharedConfig,
918+
},
919+
});
920+
921+
plugin.apply(mockCompiler);
922+
923+
// Check ConsumeSharedPlugin properties
924+
expect(ConsumeSharedPluginMock).toHaveBeenCalledTimes(1);
925+
const consumeOptions = ConsumeSharedPluginMock.mock.calls[0][0];
926+
const reactConsume = consumeOptions.consumes.find(
927+
(consume) => Object.keys(consume)[0] === 'react',
928+
);
929+
930+
// All expected properties should be passed through
931+
expect(reactConsume.react).toMatchObject({
932+
import: sharedConfig.import,
933+
shareKey: sharedConfig.shareKey,
934+
shareScope: sharedConfig.shareScope,
935+
requiredVersion: sharedConfig.requiredVersion,
936+
strictVersion: sharedConfig.strictVersion,
937+
singleton: sharedConfig.singleton,
938+
packageName: sharedConfig.packageName,
939+
eager: sharedConfig.eager,
940+
issuerLayer: sharedConfig.issuerLayer,
941+
layer: sharedConfig.layer,
942+
request: sharedConfig.request,
896943
include: sharedConfig.include,
897944
});
898945
});
899946

900-
it('should transform all properties from SharedConfig to ProvidesConfig', () => {
947+
it('should transform all properties from SharedConfig to ProvidesConfig with exclude', () => {
901948
const sharedConfig = {
902949
import: './path/to/module',
903950
shareKey: 'customKey',
@@ -910,7 +957,6 @@ describe('SharePlugin', () => {
910957
layer: 'layer',
911958
request: 'custom-request',
912959
exclude: { version: '^0.9.0' },
913-
include: { version: '^1.0.0' },
914960
};
915961

916962
const plugin = new SharePlugin({
@@ -940,6 +986,50 @@ describe('SharePlugin', () => {
940986
layer: sharedConfig.layer,
941987
request: sharedConfig.request,
942988
exclude: sharedConfig.exclude,
989+
});
990+
});
991+
992+
it('should transform all properties from SharedConfig to ProvidesConfig with include', () => {
993+
const sharedConfig = {
994+
import: './path/to/module',
995+
shareKey: 'customKey',
996+
shareScope: 'customScope',
997+
version: '1.0.0',
998+
eager: true,
999+
requiredVersion: '^1.0.0',
1000+
strictVersion: true,
1001+
singleton: true,
1002+
layer: 'layer',
1003+
request: 'custom-request',
1004+
include: { version: '^1.0.0' },
1005+
};
1006+
1007+
const plugin = new SharePlugin({
1008+
shared: {
1009+
react: sharedConfig,
1010+
},
1011+
});
1012+
1013+
plugin.apply(mockCompiler);
1014+
1015+
// Check ProvideSharedPlugin properties
1016+
expect(ProvideSharedPluginMock).toHaveBeenCalledTimes(1);
1017+
const provideOptions = ProvideSharedPluginMock.mock.calls[0][0];
1018+
const reactProvide = provideOptions.provides.find(
1019+
(provide) => Object.keys(provide)[0] === './path/to/module',
1020+
);
1021+
1022+
// All expected properties should be passed through
1023+
expect(reactProvide['./path/to/module']).toMatchObject({
1024+
shareKey: sharedConfig.shareKey,
1025+
shareScope: sharedConfig.shareScope,
1026+
version: sharedConfig.version,
1027+
eager: sharedConfig.eager,
1028+
requiredVersion: sharedConfig.requiredVersion,
1029+
strictVersion: sharedConfig.strictVersion,
1030+
singleton: sharedConfig.singleton,
1031+
layer: sharedConfig.layer,
1032+
request: sharedConfig.request,
9431033
include: sharedConfig.include,
9441034
});
9451035
});

0 commit comments

Comments
 (0)