Skip to content

Commit 0e76c31

Browse files
test(enhanced): remove invalid sharing cases lacking webpack.config.js and stabilize enhanced tests
1 parent 65a9725 commit 0e76c31

File tree

10 files changed

+173
-0
lines changed

10 files changed

+173
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
it('unifies React/DOM/JSX via pages-dir aliases with full federation', () => {
2+
// Important: use a dynamic import to create an async boundary so
3+
// federation runtime initializes before we touch shared consumes.
4+
return import('./suite').then(({ run }) => run());
5+
});
6+
7+
module.exports = {
8+
testName: 'next-pages-layer-unify',
9+
};

packages/enhanced/test/configCases/sharing/next-pages-layer-unify/node_modules/next/package.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/enhanced/test/configCases/sharing/next-pages-layer-unify/node_modules/react-dom/index.js

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/enhanced/test/configCases/sharing/next-pages-layer-unify/node_modules/react-dom/package.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/enhanced/test/configCases/sharing/next-pages-layer-unify/node_modules/react/index.js

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/enhanced/test/configCases/sharing/next-pages-layer-unify/node_modules/react/jsx-runtime/index.js

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/enhanced/test/configCases/sharing/next-pages-layer-unify/node_modules/react/package.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "next-pages-layer-unify",
3+
"version": "1.0.0"
4+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
export async function run() {
2+
// Require ids unify to the shared targets
3+
const reactId = require.resolve('react');
4+
const reactTargetId = require.resolve('next/dist/compiled/react');
5+
expect(reactId).toBe(reactTargetId);
6+
expect(reactId).toMatch(/webpack\/sharing/);
7+
8+
const domId = require.resolve('react-dom');
9+
const domTargetId = require.resolve('next/dist/compiled/react-dom');
10+
expect(domId).toBe(domTargetId);
11+
expect(domId).toMatch(/webpack\/sharing/);
12+
13+
const jsxId = require.resolve('react/jsx-runtime');
14+
const jsxTargetId = require.resolve('next/dist/compiled/react/jsx-runtime');
15+
expect(jsxId).toBe(jsxTargetId);
16+
17+
// Imports resolve to compiled Next stubs and are identical via alias or direct
18+
const React = await import('react');
19+
const ReactDirect = await import('next/dist/compiled/react');
20+
expect(React.id).toBe('compiled-react');
21+
expect(React).toEqual(ReactDirect);
22+
23+
const ReactDOM = await import('react-dom');
24+
const ReactDOMDirect = await import('next/dist/compiled/react-dom');
25+
expect(ReactDOM.id).toBe('compiled-react-dom');
26+
expect(ReactDOM).toEqual(ReactDOMDirect);
27+
28+
const jsx = await import('react/jsx-runtime');
29+
const jsxDirect = await import('next/dist/compiled/react/jsx-runtime');
30+
expect(jsx.jsx).toBe('compiled-jsx');
31+
expect(jsx).toEqual(jsxDirect);
32+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
const { ModuleFederationPlugin } = require('../../../../dist/src');
2+
const path = require('path');
3+
const fs = require('fs');
4+
5+
const ensureStub = (relativeTarget, source) => {
6+
const target = path.resolve(__dirname, relativeTarget);
7+
fs.mkdirSync(path.dirname(target), { recursive: true });
8+
fs.writeFileSync(target, source);
9+
};
10+
11+
const exportStub = (bodyLines) =>
12+
[
13+
...bodyLines,
14+
'stub.__esModule = true;',
15+
'stub.default = stub;',
16+
'module.exports = stub;',
17+
'',
18+
].join('\n');
19+
20+
ensureStub(
21+
'node_modules/next/dist/compiled/react.js',
22+
exportStub([
23+
"const stub = { id: 'compiled-react', marker: 'compiled-react', jsx: 'compiled-jsx' };",
24+
]),
25+
);
26+
27+
ensureStub(
28+
'node_modules/next/dist/compiled/react-dom/index.js',
29+
exportStub([
30+
"const stub = { id: 'compiled-react-dom', marker: 'compiled-react-dom' };",
31+
]),
32+
);
33+
34+
ensureStub(
35+
'node_modules/next/dist/compiled/react/jsx-runtime.js',
36+
[
37+
"const stub = { id: 'compiled-react', marker: 'compiled-react', jsx: 'compiled-jsx' };",
38+
'stub.__esModule = true;',
39+
'stub.default = stub;',
40+
'module.exports = stub;',
41+
'',
42+
].join('\n'),
43+
);
44+
45+
module.exports = {
46+
mode: 'development',
47+
devtool: false,
48+
experiments: {
49+
layers: true,
50+
},
51+
module: {
52+
rules: [
53+
{
54+
test: /\.(js|jsx)$/,
55+
include: __dirname,
56+
layer: 'pages-dir-browser',
57+
},
58+
],
59+
},
60+
resolve: {
61+
alias: {
62+
react: path.resolve(__dirname, 'node_modules/next/dist/compiled/react'),
63+
'react-dom': path.resolve(
64+
__dirname,
65+
'node_modules/next/dist/compiled/react-dom',
66+
),
67+
'react/jsx-runtime': path.resolve(
68+
__dirname,
69+
'node_modules/next/dist/compiled/react/jsx-runtime.js',
70+
),
71+
},
72+
},
73+
plugins: [
74+
new ModuleFederationPlugin({
75+
name: 'next-pages-layer-unify',
76+
experiments: { asyncStartup: false, aliasConsumption: true },
77+
shared: {
78+
'next/dist/compiled/react': {
79+
singleton: true,
80+
eager: true,
81+
requiredVersion: false,
82+
allowNodeModulesSuffixMatch: true,
83+
},
84+
'next/dist/compiled/react-dom': {
85+
singleton: true,
86+
eager: true,
87+
requiredVersion: false,
88+
allowNodeModulesSuffixMatch: true,
89+
},
90+
},
91+
}),
92+
],
93+
};

0 commit comments

Comments
 (0)