Skip to content

Commit 6dadff8

Browse files
fix: clear nodeRuntimeImportCache between tests to prevent interference
Export the cache and clear it in beforeEach to ensure test isolation. The caching mechanism was causing tests to reuse cached promises from previous tests instead of running the intended mocked behavior. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent f69e51d commit 6dadff8

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

packages/node/src/__tests__/runtimePlugin.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import runtimePlugin, {
1111
setupScriptLoader,
1212
setupChunkHandler,
1313
setupWebpackRequirePatching,
14+
nodeRuntimeImportCache,
1415
} from '../runtimePlugin';
1516
import type {
1617
ModuleFederationRuntimePlugin,
@@ -139,6 +140,8 @@ describe('runtimePlugin', () => {
139140
beforeEach(() => {
140141
originalFunction = global.Function;
141142
console.error = jest.fn();
143+
// Clear the import cache to ensure fresh tests
144+
nodeRuntimeImportCache.clear();
142145
});
143146

144147
afterEach(() => {

packages/node/src/runtimePlugin.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ declare const __non_webpack_require__: (id: string) => any;
4141

4242
const nodeRuntimeImportCache = new Map<string, Promise<any>>();
4343

44+
// Export cache for testing
45+
export { nodeRuntimeImportCache };
46+
4447
export function importNodeModule<T>(name: string): Promise<T> {
4548
if (!name) {
4649
throw new Error('import specifier is required');

0 commit comments

Comments
 (0)