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 7 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
16 changes: 16 additions & 0 deletions .changeset/comprehensive-consume-shared-tests.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
"@module-federation/enhanced": patch
---

test: implement comprehensive test coverage for ConsumeSharedPlugin

- Add 70+ comprehensive tests for createConsumeSharedModule method covering all critical business logic
- Implement tests for import resolution logic including error handling and direct fallback regex matching
- Add comprehensive 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)

This addresses the requirement for "immense test coverage for consume share plugin and provide share plugin to cover all its very complex logic" and ensures comprehensive testing of multi-stage module resolution, layer matching, version filtering, and error handling.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this line

16 changes: 16 additions & 0 deletions .changeset/comprehensive-provide-shared-tests.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
"@module-federation/enhanced": patch
---

test: add comprehensive test coverage for ProvideSharedPlugin

- Add 73 comprehensive 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

This ensures comprehensive test coverage for ProvideSharedPlugin's complex module sharing logic and prevents regressions.
14 changes: 14 additions & 0 deletions .changeset/pr9-enhanced-layer-support.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
"@module-federation/enhanced": minor
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make this a patch and update it based on the actual changes in the pr (if any) otherwise delete

---

feat: implement enhanced layer support with issuerLayer fallback logic

- Add issuerLayer parameter support throughout ConsumeSharedPlugin and related modules
- Implement issuerLayer fallback pattern in module resolution (tries issuerLayer first, then falls back to undefined)
- Add createLookupKeyForSharing utility to generate layer-aware lookup keys (e.g., "(client)react")
- Support layer-specific module sharing configuration with proper precedence rules
- Add comprehensive unit tests for issuerLayer fallback behavior and utility functions
- Fix test infrastructure issues and improve test assertions for better CI stability

This completes PR9: Enhanced Layer Support as defined in the incremental PR plan, enabling more granular control over shared module resolution based on issuer layers.
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