Skip to content

feat(enhanced): implement layer-aware module sharing with comprehensive test coverage (PR9) #3915

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .changeset/comprehensive-consume-shared-tests.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
"@module-federation/enhanced": patch
---

test: add test coverage for ConsumeSharedPlugin

- Add 70+ tests for createConsumeSharedModule method covering all critical business logic
- Implement tests for import resolution logic including error handling and direct fallback regex matching
- Add requiredVersion resolution tests for package name extraction and version resolution
- Implement include/exclude version filtering tests with fallback version support
- Add singleton warning generation tests for version filters as specified
- Implement package.json reading error scenarios and edge case handling
- Add apply method tests for plugin registration logic and hook setup
- Achieve test coverage parity with ProvideSharedPlugin (70+ tests each)
14 changes: 14 additions & 0 deletions .changeset/comprehensive-provide-shared-tests.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
"@module-federation/enhanced": patch
---

test: add test coverage for ProvideSharedPlugin

- Add 73 tests covering all critical business logic and edge cases
- Implement complete shouldProvideSharedModule method coverage (15 tests) for version filtering with semver validation
- Add provideSharedModule method tests (16 tests) covering version resolution, request pattern filtering, and warning generation
- Implement module matching and resolution stage tests (20 tests) for multi-stage resolution logic
- Validate business rules: warnings only for version filters with singleton, not request filters
- Cover all critical private methods with proper TypeScript handling using @ts-ignore
- Fix container utils mock for dependency factory operations
- Add performance and memory usage tests for large-scale scenarios
6 changes: 2 additions & 4 deletions .changeset/enhance-filtering-test-coverage.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
"@module-federation/enhanced": patch
---

test: add comprehensive test coverage for request pattern filtering
test: add test coverage for request pattern filtering

- Add integration tests for request pattern filtering in provide-filters test case
- Add test cases verifying modules match/don't match request include filters
- Add unit tests for `extractPathAfterNodeModules` utility function
- Add unit tests for `createLookupKeyForSharing` utility function
- Add test files for request filtering scenarios (components/Button.js, utils/helper.js, etc.)

This enhances test coverage to ensure request pattern filtering functionality works correctly and prevents regressions.
- Add test files for request filtering scenarios (components/Button.js, utils/helper.js, etc.)
2 changes: 1 addition & 1 deletion .changeset/fix-node-runtime-recursion.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ fix(node): prevent infinite recursion in module imports
- Add import cache to prevent infinite recursion when modules have circular dependencies
- Cache import promises to ensure each module is only imported once
- Clear cache on import errors to allow retry attempts
- Add comprehensive test coverage for recursion scenarios
- Add test coverage for recursion scenarios
11 changes: 11 additions & 0 deletions .changeset/pr9-enhanced-layer-support.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"@module-federation/enhanced": patch
---

test: add test coverage for ConsumeSharedPlugin and ProvideSharedPlugin

- Add 70+ tests for ConsumeSharedPlugin covering all critical business logic including multi-stage module resolution, import resolution logic, version filtering, and error handling
- Add 73 tests for ProvideSharedPlugin covering shouldProvideSharedModule method, provideSharedModule method, module matching, and resolution stages
- Fix minor bug in ProvideSharedPlugin where originalRequestString was used instead of modulePathAfterNodeModules for prefix matching
- Add layer property to resolved provide map entries for better layer support
- Improve test infrastructure stability and CI reliability with better assertions and mocking
3 changes: 2 additions & 1 deletion packages/enhanced/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export default {
'<rootDir>/test/*.basictest.js',
'<rootDir>/test/unit/**/*.test.ts',
],

silent: true,
verbose: false,
testEnvironment: path.resolve(__dirname, './test/patch-node-env.js'),
setupFilesAfterEnv: ['<rootDir>/test/setupTestFramework.js'],
};
8 changes: 6 additions & 2 deletions packages/enhanced/src/lib/sharing/ProvideSharedPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export type ResolvedProvideMap = Map<
config: ProvidesConfig;
version: string | undefined | false;
resource?: string;
layer?: string;
}
>;

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

if (originalRequestString.startsWith(configuredPrefix)) {
if (
modulePathAfterNodeModules.startsWith(configuredPrefix)
) {
if (resolvedProvideMap.has(lookupKeyForResource))
continue;

const remainder = originalRequestString.slice(
const remainder = modulePathAfterNodeModules.slice(
configuredPrefix.length,
);
if (
Expand Down Expand Up @@ -812,6 +815,7 @@ class ProvideSharedPlugin {
config,
version,
resource,
layer: config.layer,
});
}

Expand Down
Loading
Loading