Skip to content

Commit 756750e

Browse files
feat(enhanced): implement layer-aware module sharing with comprehensive test coverage (PR9) (#3915)
Co-authored-by: Claude <[email protected]>
1 parent 5d90a4c commit 756750e

26 files changed

+6121
-1616
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
"@module-federation/enhanced": patch
3+
---
4+
5+
test: add test coverage for ConsumeSharedPlugin
6+
7+
- Add 70+ tests for createConsumeSharedModule method covering all critical business logic
8+
- Implement tests for import resolution logic including error handling and direct fallback regex matching
9+
- Add requiredVersion resolution tests for package name extraction and version resolution
10+
- Implement include/exclude version filtering tests with fallback version support
11+
- Add singleton warning generation tests for version filters as specified
12+
- Implement package.json reading error scenarios and edge case handling
13+
- Add apply method tests for plugin registration logic and hook setup
14+
- Achieve test coverage parity with ProvideSharedPlugin (70+ tests each)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
"@module-federation/enhanced": patch
3+
---
4+
5+
test: add test coverage for ProvideSharedPlugin
6+
7+
- Add 73 tests covering all critical business logic and edge cases
8+
- Implement complete shouldProvideSharedModule method coverage (15 tests) for version filtering with semver validation
9+
- Add provideSharedModule method tests (16 tests) covering version resolution, request pattern filtering, and warning generation
10+
- Implement module matching and resolution stage tests (20 tests) for multi-stage resolution logic
11+
- Validate business rules: warnings only for version filters with singleton, not request filters
12+
- Cover all critical private methods with proper TypeScript handling using @ts-ignore
13+
- Fix container utils mock for dependency factory operations
14+
- Add performance and memory usage tests for large-scale scenarios
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
"@module-federation/enhanced": patch
3+
---
4+
5+
test: add test coverage for ConsumeSharedPlugin and ProvideSharedPlugin
6+
7+
- Add 70+ tests for ConsumeSharedPlugin covering all critical business logic including multi-stage module resolution, import resolution logic, version filtering, and error handling
8+
- Add 73 tests for ProvideSharedPlugin covering shouldProvideSharedModule method, provideSharedModule method, module matching, and resolution stages
9+
- Fix minor bug in ProvideSharedPlugin where originalRequestString was used instead of modulePathAfterNodeModules for prefix matching
10+
- Add layer property to resolved provide map entries for better layer support
11+
- Improve test infrastructure stability and CI reliability with better assertions and mocking

packages/enhanced/jest.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ export default {
3737
'<rootDir>/test/*.basictest.js',
3838
'<rootDir>/test/unit/**/*.test.ts',
3939
],
40-
40+
silent: true,
41+
verbose: false,
4142
testEnvironment: path.resolve(__dirname, './test/patch-node-env.js'),
4243
setupFilesAfterEnv: ['<rootDir>/test/setupTestFramework.js'],
4344
};

packages/enhanced/src/lib/sharing/ProvideSharedPlugin.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export type ResolvedProvideMap = Map<
4444
config: ProvidesConfig;
4545
version: string | undefined | false;
4646
resource?: string;
47+
layer?: string;
4748
}
4849
>;
4950

@@ -380,11 +381,13 @@ class ProvideSharedPlugin {
380381
}
381382
// If moduleLayer exists but config.layer does not, allow (non-layered option matches layered request)
382383

383-
if (originalRequestString.startsWith(configuredPrefix)) {
384+
if (
385+
modulePathAfterNodeModules.startsWith(configuredPrefix)
386+
) {
384387
if (resolvedProvideMap.has(lookupKeyForResource))
385388
continue;
386389

387-
const remainder = originalRequestString.slice(
390+
const remainder = modulePathAfterNodeModules.slice(
388391
configuredPrefix.length,
389392
);
390393
if (
@@ -812,6 +815,7 @@ class ProvideSharedPlugin {
812815
config,
813816
version,
814817
resource,
818+
layer: config.layer,
815819
});
816820
}
817821

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ export function createWebpackMock() {
394394
};
395395

396396
const RuntimeModule = class extends Module {
397-
static STAGE_NORMAL = 5;
397+
static STAGE_NORMAL = 0;
398398
static STAGE_BASIC = 10;
399399
static STAGE_ATTACH = 20;
400400
static STAGE_TRIGGER = 30;

0 commit comments

Comments
 (0)