Skip to content

Commit e465941

Browse files
chore: stage tests
1 parent f7a167d commit e465941

File tree

394 files changed

+5053
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

394 files changed

+5053
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from 'container-with-shared/b';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './shared';
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
it('should work normally (a)', () => {
2+
return import('./a').then(({ value }) => {
3+
expect(value).toBe('shared');
4+
});
5+
});
6+
7+
it('should work normally (b)', () => {
8+
return import('./b').then(({ value }) => {
9+
expect(value).toBe('shared');
10+
});
11+
});
12+
13+
it('should work normally (container-with-shared/a)', () => {
14+
return import('container-with-shared/a').then(({ value }) => {
15+
expect(value).toBe('shared');
16+
});
17+
});
18+
19+
it('should work normally (container-with-shared/b)', () => {
20+
return import('container-with-shared/b').then(({ value }) => {
21+
expect(value).toBe('shared');
22+
});
23+
});
24+
25+
it('should work normally (container-no-shared/a)', () => {
26+
return import('container-no-shared/a').then(({ value }) => {
27+
expect(value).toBe('shared');
28+
});
29+
});
30+
31+
it('should work normally (container-no-shared/b)', () => {
32+
return import('container-no-shared/b').then(({ value }) => {
33+
expect(value).toBe('shared');
34+
});
35+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from 'container-with-shared/modules';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default Object.keys(__webpack_modules__).sort();
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const value = 'shared';
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const { ModuleFederationPlugin } = require('../../../../dist/src');
2+
3+
module.exports = {
4+
optimization: {
5+
chunkIds: 'named',
6+
moduleIds: 'named',
7+
},
8+
plugins: [
9+
new ModuleFederationPlugin({
10+
name: 'container-no-shared',
11+
library: { type: 'commonjs-module' },
12+
filename: 'container-no-shared.js',
13+
exposes: ['./a', './b', './modules', './modules-from-remote'],
14+
remotes: {
15+
'container-with-shared':
16+
'../0-transitive-overriding/container-with-shared.js',
17+
'container-no-shared': './container-no-shared.js',
18+
},
19+
}),
20+
],
21+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import OldReact from 'old-react';
2+
import OldReactSingleton from 'old-react-singleton';
3+
import React from 'react';
4+
import ComponentC from 'containerB/ComponentC';
5+
6+
export default () => {
7+
return `App rendered with [${React()}] and [${OldReact()}] and [${OldReactSingleton()}] and [${ComponentC()}]`;
8+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default {
2+
in: __filename,
3+
};
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
let warnings = [];
2+
let oldWarn;
3+
4+
if (global.__FEDERATION__) {
5+
global.__GLOBAL_LOADING_REMOTE_ENTRY__ = {};
6+
//@ts-ignore
7+
global.__FEDERATION__.__INSTANCES__.map((i) => {
8+
i.moduleCache.clear();
9+
if (global[i.name]) {
10+
delete global[i.name];
11+
}
12+
});
13+
global.__FEDERATION__.__INSTANCES__ = [];
14+
}
15+
16+
beforeEach((done) => {
17+
oldWarn = console.warn;
18+
console.warn = (m) => warnings.push(m);
19+
done();
20+
});
21+
22+
afterEach((done) => {
23+
// expectWarning();
24+
console.warn = oldWarn;
25+
done();
26+
});
27+
28+
const expectWarning = (regexp) => {
29+
if (!regexp) {
30+
expect(warnings).toEqual([]);
31+
} else {
32+
expect(warnings).toEqual(
33+
expect.objectContaining({
34+
0: expect.stringMatching(regexp),
35+
length: 1,
36+
}),
37+
);
38+
}
39+
warnings.length = 0;
40+
};
41+
42+
it('should load the component from container', () => {
43+
return import('./App').then(({ default: App }) => {
44+
// FIXME: Federation runtime 打印的 warning 和原先不一致
45+
// expectWarning(
46+
// /Unsatisfied version 8 from 2-container-full of shared singleton module react \(required \^2\)/
47+
// );
48+
const rendered = App();
49+
expect(rendered).toBe(
50+
'App rendered with [This is react 8] and [This is react 2.1.0] and [This is react 8] and [ComponentC rendered with [This is react 8] and [ComponentA rendered with [This is react 8]] and [ComponentB rendered with [This is react 8]]]',
51+
);
52+
return import('./upgrade-react').then(({ default: upgrade }) => {
53+
upgrade();
54+
const rendered = App();
55+
expect(rendered).toBe(
56+
'App rendered with [This is react 9] and [This is react 2.1.0] and [This is react 9] and [ComponentC rendered with [This is react 9] and [ComponentA rendered with [This is react 9]] and [ComponentB rendered with [This is react 9]]]',
57+
);
58+
});
59+
});
60+
});
61+
62+
import Self from './Self';
63+
64+
it('should load itself from its own container', () => {
65+
return import('self/Self').then(({ default: RemoteSelf }) => {
66+
expect(RemoteSelf).toBe(Self);
67+
});
68+
});

packages/enhanced/test/configCases/container/2-container-full/node_modules/package.json

Lines changed: 3 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/container/2-container-full/node_modules/react.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dependencies": {
3+
"react": "*"
4+
}
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { setVersion } from 'react';
2+
3+
export default function upgrade() {
4+
setVersion('9');
5+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const { ModuleFederationPlugin } = require('../../../../dist/src');
2+
3+
/** @type {import("../../../../").Configuration} */
4+
module.exports = {
5+
output: {
6+
uniqueName: '2-container-full',
7+
},
8+
plugins: [
9+
new ModuleFederationPlugin({
10+
name: 'main',
11+
library: { type: 'commonjs-module' },
12+
remotes: {
13+
containerB: '../1-container-full/container.js',
14+
self: [
15+
'var undefined',
16+
'var (() => { throw new Error(); })()',
17+
'var { then: (a, b) => b(new Error()) }',
18+
'./bundle0.js',
19+
],
20+
},
21+
exposes: ['./Self'],
22+
shared: {
23+
react: 'react',
24+
'old-react': {
25+
import: false,
26+
shareKey: 'react',
27+
requiredVersion: '^2',
28+
},
29+
'old-react-singleton': {
30+
import: false,
31+
shareKey: 'react',
32+
requiredVersion: '^2',
33+
singleton: true,
34+
},
35+
},
36+
}),
37+
],
38+
};
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
it('should allow transitive overrides (container-no-shared/a)', () => {
2+
return import('container-no-shared/a').then(({ value }) => {
3+
expect(value).toBe('new shared');
4+
});
5+
});
6+
7+
it('should not override non-overridables (container-no-shared/b)', () => {
8+
return import('container-no-shared/b').then(({ value }) => {
9+
expect(value).toBe('shared');
10+
});
11+
});
12+
13+
it('should have good module ids', async () => {
14+
const { default: m0 } = await import(
15+
'container-no-shared/modules-from-remote'
16+
);
17+
const { default: m1 } = await import('container-no-shared/modules');
18+
const m2 = Object.keys(__webpack_modules__).sort();
19+
[
20+
'./b.js',
21+
'./modules.js',
22+
'webpack/container/entry/container-with-shared',
23+
'webpack/sharing/consume/default/shared/./shared',
24+
].forEach((id) => {
25+
expect(m0.includes(id)).toEqual(true);
26+
});
27+
28+
[
29+
'./a.js',
30+
'./b.js',
31+
'./modules-from-remote.js',
32+
'./modules.js',
33+
'webpack/container/entry/container-no-shared',
34+
'webpack/container/reference/container-with-shared',
35+
'webpack/container/remote/container-with-shared/b',
36+
'webpack/container/remote/container-with-shared/modules',
37+
].forEach((id) => {
38+
expect(m1.includes(id)).toEqual(true);
39+
});
40+
41+
[
42+
'./index.js',
43+
'./shared.js',
44+
'webpack/container/reference/container-no-shared',
45+
'webpack/container/remote/container-no-shared/a',
46+
'webpack/container/remote/container-no-shared/b',
47+
'webpack/container/remote/container-no-shared/modules',
48+
'webpack/container/remote/container-no-shared/modules-from-remote',
49+
].forEach((id) => {
50+
expect(m2.includes(id)).toEqual(true);
51+
});
52+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const value = 'new shared';
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const { ModuleFederationPlugin } = require('../../../../dist/src');
2+
3+
module.exports = {
4+
optimization: {
5+
chunkIds: 'named',
6+
moduleIds: 'named',
7+
},
8+
plugins: [
9+
new ModuleFederationPlugin({
10+
remoteType: 'commonjs-module',
11+
remotes: {
12+
'container-no-shared':
13+
'../1-transitive-overriding/container-no-shared.js',
14+
},
15+
shared: {
16+
'./shared': {
17+
shareKey: 'shared',
18+
version: '2',
19+
},
20+
},
21+
}),
22+
],
23+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import React from 'react';
2+
import ComponentC from 'containerB/ComponentC';
3+
4+
export default () => {
5+
return `App rendered with [${React()}] and [${ComponentC()}]`;
6+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
if (global.__FEDERATION__) {
2+
global.__GLOBAL_LOADING_REMOTE_ENTRY__ = {};
3+
//@ts-ignore
4+
global.__FEDERATION__.__INSTANCES__.map((i) => {
5+
i.moduleCache.clear();
6+
if (global[i.name]) {
7+
delete global[i.name];
8+
}
9+
});
10+
global.__FEDERATION__.__INSTANCES__ = [];
11+
}
12+
13+
it('should load the component from container', () => {
14+
return import('./App').then(({ default: App }) => {
15+
const rendered = App();
16+
expect(rendered).toBe(
17+
'App rendered with [This is react 2.1.0] and [ComponentC 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]]]',
18+
);
19+
return import('./upgrade-react').then(({ default: upgrade }) => {
20+
upgrade();
21+
const rendered = App();
22+
expect(rendered).toBe(
23+
'App rendered with [This is react 9] and [ComponentC rendered with [This is react 9] and [ComponentA rendered with [This is react 9]] and [ComponentB rendered with [This is react 9]]]',
24+
);
25+
});
26+
});
27+
});

packages/enhanced/test/configCases/container/3-container-full/node_modules/react.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dependencies": {
3+
"react": "*"
4+
}
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { setVersion } from 'react';
2+
3+
export default function upgrade() {
4+
setVersion('9');
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = [
2+
[/No version specified and unable to automatically determine one/],
3+
];
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const { ModuleFederationPlugin } = require('../../../../dist/src');
2+
3+
module.exports = {
4+
plugins: [
5+
new ModuleFederationPlugin({
6+
remoteType: 'commonjs-module',
7+
remotes: {
8+
containerB: '../1-container-full/container.js',
9+
},
10+
shared: ['react'],
11+
}),
12+
],
13+
};
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export default 'a';
2+
export { default as b, a as ba } from 'container2/b';
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export default 'b';
2+
export { default as a, b as ab } from 'container/a';
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
it('should allow circular dependencies between containers (a)', async () => {
2+
const { default: value, b, ba } = await import('container/a');
3+
expect(value).toBe('a');
4+
expect(b).toBe('b');
5+
expect(ba).toBe('a');
6+
});
7+
8+
it('should allow circular dependencies between containers (b)', async () => {
9+
const { default: value, a, ab } = await import('container2/b');
10+
expect(value).toBe('b');
11+
expect(a).toBe('a');
12+
expect(ab).toBe('b');
13+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
findBundle() {
3+
return './main.js';
4+
},
5+
};

0 commit comments

Comments
 (0)