Skip to content

Commit 8589e62

Browse files
committed
test: add tests
1 parent e8200dd commit 8589e62

2 files changed

Lines changed: 38 additions & 8 deletions

File tree

packages/repack/src/plugins/__tests__/ModuleFederationPluginV1.test.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { Compiler } from '@rspack/core';
2-
import { Federated } from '../../utils/federated.js';
32
import { ModuleFederationPluginV1 } from '../ModuleFederationPluginV1.js';
43

54
const mockPlugin = jest.fn().mockImplementation(() => ({
@@ -129,8 +128,8 @@ describe('ModuleFederationPlugin', () => {
129128
new ModuleFederationPluginV1({
130129
name: 'test',
131130
shared: {
132-
react: Federated.SHARED_REACT,
133-
'react-native': Federated.SHARED_REACT_NATIVE,
131+
react: { singleton: true, eager: true },
132+
'react-native': { singleton: true, eager: true },
134133
},
135134
}).apply(mockCompiler);
136135

@@ -144,8 +143,8 @@ describe('ModuleFederationPlugin', () => {
144143
name: 'test',
145144
reactNativeDeepImports: false,
146145
shared: {
147-
react: Federated.SHARED_REACT,
148-
'react-native': Federated.SHARED_REACT_NATIVE,
146+
react: { singleton: true, eager: true },
147+
'react-native': { singleton: true, eager: true },
149148
},
150149
}).apply(mockCompiler);
151150

@@ -158,7 +157,7 @@ describe('ModuleFederationPlugin', () => {
158157
new ModuleFederationPluginV1({
159158
name: 'test',
160159
shared: {
161-
react: Federated.SHARED_REACT,
160+
react: { singleton: true, eager: true },
162161
},
163162
}).apply(mockCompiler);
164163

@@ -182,8 +181,8 @@ describe('ModuleFederationPlugin', () => {
182181
new ModuleFederationPluginV1({
183182
name: 'test',
184183
shared: {
185-
react: Federated.SHARED_REACT,
186-
'react-native': Federated.SHARED_REACT_NATIVE,
184+
react: { singleton: true, eager: true },
185+
'react-native': { singleton: true, eager: true },
187186
'react-native/': { singleton: true, eager: true },
188187
},
189188
}).apply(mockCompiler);
@@ -213,6 +212,21 @@ describe('ModuleFederationPlugin', () => {
213212
expect(config.shared['@react-native/'].eager).toBe(false);
214213
});
215214

215+
it('should propagate import=false to deep react-native imports', () => {
216+
new ModuleFederationPluginV1({
217+
name: 'test',
218+
shared: {
219+
'react-native': { singleton: true, eager: false, import: false },
220+
},
221+
}).apply(mockCompiler);
222+
223+
const config = mockPlugin.mock.calls[0][0];
224+
expect(config.shared).toHaveProperty('react-native/');
225+
expect(config.shared).toHaveProperty('@react-native/');
226+
expect(config.shared['react-native/'].import).toBe(false);
227+
expect(config.shared['@react-native/'].import).toBe(false);
228+
});
229+
216230
it('should set default federated entry filename', () => {
217231
new ModuleFederationPluginV1({
218232
name: 'test',

packages/repack/src/plugins/__tests__/ModuleFederationPluginV2.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,22 @@ describe('ModuleFederationPlugin', () => {
150150
expect(config.shared['@react-native/'].eager).toBe(false);
151151
});
152152

153+
it('should propagate import=false to deep react-native imports', () => {
154+
new ModuleFederationPluginV2({
155+
name: 'test',
156+
shared: {
157+
react: { singleton: true, eager: true },
158+
'react-native': { singleton: true, eager: false, import: false },
159+
},
160+
}).apply(mockCompiler);
161+
162+
const config = mockPlugin.mock.calls[0][0];
163+
expect(config.shared).toHaveProperty('react-native/');
164+
expect(config.shared).toHaveProperty('@react-native/');
165+
expect(config.shared['react-native/'].import).toBe(false);
166+
expect(config.shared['@react-native/'].import).toBe(false);
167+
});
168+
153169
it('should add CorePlugin & ResolverPlugin to runtime plugins by default', () => {
154170
new ModuleFederationPluginV2({ name: 'test' }).apply(mockCompiler);
155171

0 commit comments

Comments
 (0)