Skip to content

Commit

Permalink
chore: add tests for share plugin recursive search
Browse files Browse the repository at this point in the history
  • Loading branch information
robdonn committed Sep 3, 2024
1 parent b39656c commit a4c6d41
Show file tree
Hide file tree
Showing 17 changed files with 139 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/lucky-fans-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@module-federation/enhanced': minor
---

Enable recursive search for shared dependency version
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
it('should provide and consume a normal nested library async', async () => {
expect(await import('lib1')).toEqual(
expect.objectContaining({
default: 'lib1',
}),
);
});

it('should provide and consume a normal library async', async () => {
expect(await import('lib4')).toEqual(
expect.objectContaining({
default: 'lib4',
}),
);
});

it('should provide and consume a renamed nested library sync', () => {
expect(require('lib-two')).toEqual(
expect.objectContaining({
default: 'lib2',
}),
);
});

it('should provide and consume a renamed library sync', () => {
expect(require('lib-five')).toEqual(
expect.objectContaining({
default: 'lib5',
}),
);
});

it('should provide and consume a normal nested library async in a separate shareScope', async () => {
expect(await import('lib3')).toEqual(
expect.objectContaining({
default: 'lib3',
}),
);
expect(
__webpack_share_scopes__.default && __webpack_share_scopes__.default.lib3,
).toBe(undefined);
expect(typeof __webpack_share_scopes__.other.lib3).toBe('object');
});

it('should provide and consume a relative request async', async () => {
expect(await import('./relative1')).toEqual(
expect.objectContaining({
default: 'rel1',
}),
);
});

it('should consume a remapped relative request async', async () => {
if (Math.random() < 0) require('store');
expect(await import('./relative2')).toEqual(
expect.objectContaining({
default: 'store',
}),
);
});

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"devDependencies": {
"lib3": "^1.1.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'rel1';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'rel2';

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"devDependencies": {
"lib3": "^1.1.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const { SharePlugin } = require('../../../../dist/src');

module.exports = {
mode: 'development',
devtool: false,
context: `${__dirname}/app1`,
plugins: [
new SharePlugin({
shared: {
lib1: '^1.0.0',
'lib-two': {
import: 'lib2',
requiredVersion: '^1.0.0',
version: '1.3.4',
strictVersion: true,
eager: true,
},
lib3: {
shareScope: 'other',
},
lib4: '^1.0.0',
'lib-five': {
import: 'lib5',
requiredVersion: '^1.0.0',
version: '1.3.4',
strictVersion: true,
eager: true,
},
'./relative1': {
import: './relative1',
version: false,
},
'./relative2': {
import: false,
shareKey: 'store',
version: '0',
requiredVersion: false,
strictVersion: true,
},
store: '0',
},
}),
],
};

0 comments on commit a4c6d41

Please sign in to comment.