Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16943 from snitin315/fix/mf-sharescope
test: add case for ModuleFederationPlugin usage with shareScope option
- Loading branch information
Showing
10 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
test/configCases/container/module-federation-with-shareScope/App.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React from "react"; | ||
import ComponentA from "containerA/ComponentA"; | ||
import ComponentB from "containerB/ComponentB"; | ||
import LocalComponentB from "./ComponentB"; | ||
|
||
export default () => { | ||
return `App rendered with [${React()}] and [${ComponentA()}] and [${ComponentB()}]`; | ||
}; | ||
|
||
expect(ComponentB).not.toBe(LocalComponentB); |
5 changes: 5 additions & 0 deletions
5
test/configCases/container/module-federation-with-shareScope/ComponentB.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import React from "react"; | ||
|
||
export default () => { | ||
return `ComponentB rendered with [${React()}]`; | ||
}; |
7 changes: 7 additions & 0 deletions
7
test/configCases/container/module-federation-with-shareScope/ComponentC.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import React from "react"; | ||
import ComponentA from "containerA/ComponentA"; | ||
import ComponentB from "containerB/ComponentB"; | ||
|
||
export default () => { | ||
return `ComponentC rendered with [${React()}] and [${ComponentA()}] and [${ComponentB()}]`; | ||
}; |
20 changes: 20 additions & 0 deletions
20
test/configCases/container/module-federation-with-shareScope/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
it("should load the component from container", async () => { | ||
await __webpack_init_sharing__("test-scope"); | ||
|
||
// 2 scopes for "0-container-full-mjs" & "mf-with-shareScope-mjs" | ||
expect(Object.keys(__webpack_share_scopes__["test-scope"].react).length).toBe(2); | ||
|
||
return import("./App").then(({ default: App }) => { | ||
const rendered = App(); | ||
expect(rendered).toBe( | ||
"App rendered with [This is react 2.1.0] and [ComponentA rendered with [This is react 2.1.0]] and [ComponentB rendered with [This is react 2.1.0]]" | ||
); | ||
return import("./upgrade-react").then(({ default: upgrade }) => { | ||
upgrade(); | ||
const rendered = App(); | ||
expect(rendered).toBe( | ||
"App rendered with [This is react 3.2.1] and [ComponentA rendered with [This is react 3.2.1]] and [ComponentB rendered with [This is react 3.2.1]]" | ||
); | ||
}); | ||
}); | ||
}); |
3 changes: 3 additions & 0 deletions
3
test/configCases/container/module-federation-with-shareScope/node_modules/package.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
test/configCases/container/module-federation-with-shareScope/node_modules/react.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
test/configCases/container/module-federation-with-shareScope/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"private": true, | ||
"engines": { | ||
"node": ">=10.13.0" | ||
}, | ||
"dependencies": { | ||
"react": "*" | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
test/configCases/container/module-federation-with-shareScope/test.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
findBundle: function (i, options) { | ||
return i === 0 ? "./main.js" : "./module/main.mjs"; | ||
} | ||
}; |
5 changes: 5 additions & 0 deletions
5
test/configCases/container/module-federation-with-shareScope/upgrade-react.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { setVersion } from "react"; | ||
|
||
export default function upgrade() { | ||
setVersion("3.2.1"); | ||
} |
68 changes: 68 additions & 0 deletions
68
test/configCases/container/module-federation-with-shareScope/webpack.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// eslint-disable-next-line node/no-unpublished-require | ||
const { ModuleFederationPlugin } = require("../../../../").container; | ||
|
||
const common = { | ||
entry: { | ||
main: "./index.js" | ||
}, | ||
optimization: { | ||
runtimeChunk: "single" | ||
} | ||
}; | ||
|
||
/** @type {ConstructorParameters<typeof ModuleFederationPlugin>[0]} */ | ||
const commonMF = { | ||
runtime: false, | ||
exposes: { | ||
"./ComponentB": "./ComponentB", | ||
"./ComponentC": "./ComponentC" | ||
}, | ||
shared: ["react"], | ||
shareScope: "test-scope" | ||
}; | ||
|
||
/** @type {import("../../../../types").Configuration[]} */ | ||
module.exports = [ | ||
{ | ||
...common, | ||
output: { | ||
filename: "[name].js", | ||
uniqueName: "mf-with-shareScope" | ||
}, | ||
plugins: [ | ||
new ModuleFederationPlugin({ | ||
name: "container", | ||
library: { type: "commonjs-module" }, | ||
filename: "container.js", | ||
remotes: { | ||
containerA: "../0-container-full/container.js", | ||
containerB: "./container.js" | ||
}, | ||
...commonMF | ||
}) | ||
] | ||
}, | ||
{ | ||
...common, | ||
experiments: { | ||
outputModule: true | ||
}, | ||
output: { | ||
filename: "module/[name].mjs", | ||
uniqueName: "mf-with-shareScope-mjs" | ||
}, | ||
plugins: [ | ||
new ModuleFederationPlugin({ | ||
name: "container", | ||
library: { type: "module" }, | ||
filename: "module/container.mjs", | ||
remotes: { | ||
containerA: "../../0-container-full/module/container.mjs", | ||
containerB: "./container.mjs" | ||
}, | ||
...commonMF | ||
}) | ||
], | ||
target: "node14" | ||
} | ||
]; |