Skip to content

Commit 4007579

Browse files
committed
chore: add ut
1 parent fdde0d6 commit 4007579

File tree

25 files changed

+396
-24
lines changed

25 files changed

+396
-24
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const fs = __non_webpack_require__('fs');
2+
const path = __non_webpack_require__('path');
3+
4+
const statsPath = path.join(__dirname, 'mf-stats.json');
5+
const manifestPath = path.join(__dirname, 'mf-manifest.json');
6+
7+
const stats = JSON.parse(fs.readFileSync(statsPath, 'utf-8'));
8+
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf-8'));
9+
10+
it('should still emit the remote entry', () => {
11+
const remoteEntryFile = stats.metaData.remoteEntry.name;
12+
const remoteEntryPath = path.join(__dirname, remoteEntryFile);
13+
expect(fs.existsSync(remoteEntryPath)).toBe(true);
14+
});
15+
16+
it('should omit asset details from stats when disableAssetsAnalyze is true', () => {
17+
expect(stats.shared).toHaveLength(1);
18+
expect(stats.shared[0].assets.js.sync).toEqual([]);
19+
expect(stats.shared[0].assets.js.async).toEqual([]);
20+
expect(stats.exposes).toHaveLength(1);
21+
expect(stats.exposes[0].assets.js.sync).toEqual([]);
22+
expect(stats.exposes[0].assets.js.async).toEqual([]);
23+
});
24+
25+
it('should omit asset details from manifest when disableAssetsAnalyze is true', () => {
26+
expect(manifest.shared).toHaveLength(1);
27+
expect(manifest.shared[0].assets.js.sync).toEqual([]);
28+
expect(manifest.shared[0].assets.js.async).toEqual([]);
29+
expect(manifest.exposes).toHaveLength(1);
30+
expect(manifest.exposes[0].assets.js.sync).toEqual([]);
31+
expect(manifest.exposes[0].assets.js.async).toEqual([]);
32+
});
33+
34+
it('should mark remote usage locations as UNKNOWN', () => {
35+
expect(stats.remotes).toEqual(
36+
expect.arrayContaining([
37+
expect.objectContaining({
38+
usedIn: ['UNKNOWN'],
39+
}),
40+
]),
41+
);
42+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const lazy = true;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import react from 'react';
2+
import remote from 'remote';
3+
4+
global.react = react;
5+
global.remote = remote;
6+
7+
import('./lazy-module').then((r) => {
8+
console.log('lazy module: ', r);
9+
});
10+
11+
export const ok = true;

packages/enhanced/test/configCases/container/manifest-disable-assets-analyze/node_modules/package.json

Lines changed: 4 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/manifest-disable-assets-analyze/node_modules/react.js

Lines changed: 1 addition & 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": "1.0.0"
4+
}
5+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const { ModuleFederationPlugin } = require('../../../../dist/src');
2+
3+
module.exports = {
4+
optimization: {
5+
chunkIds: 'named',
6+
moduleIds: 'named',
7+
},
8+
output: {
9+
publicPath: '/',
10+
chunkFilename: '[id].js',
11+
},
12+
plugins: [
13+
new ModuleFederationPlugin({
14+
name: 'container',
15+
filename: 'container.[chunkhash:8].js',
16+
library: { type: 'commonjs-module' },
17+
exposes: {
18+
'expose-a': './module.js',
19+
},
20+
remoteType: 'script',
21+
remotes: {
22+
remote: 'remote@http://localhost:8000/remoteEntry.js',
23+
},
24+
shared: {
25+
react: {},
26+
},
27+
manifest: {
28+
disableAssetsAnalyze: true,
29+
},
30+
}),
31+
],
32+
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const fs = __non_webpack_require__('fs');
2+
const path = __non_webpack_require__('path');
3+
4+
const customPath = 'custom-path';
5+
const customManifestPath = path.join(
6+
__dirname,
7+
customPath,
8+
'custom-manifest.json',
9+
);
10+
const customStatsPath = path.join(
11+
__dirname,
12+
customPath,
13+
'custom-manifest-stats.json',
14+
);
15+
const defaultManifestPath = path.join(__dirname, 'mf-manifest.json');
16+
const defaultStatsPath = path.join(__dirname, 'mf-stats.json');
17+
18+
const stats = JSON.parse(fs.readFileSync(customStatsPath, 'utf-8'));
19+
const manifest = JSON.parse(fs.readFileSync(customManifestPath, 'utf-8'));
20+
21+
it('should emit manifest with the configured fileName', () => {
22+
expect(fs.existsSync(customManifestPath)).toBe(true);
23+
expect(fs.existsSync(customStatsPath)).toBe(true);
24+
});
25+
26+
it('should not emit default manifest file names when fileName is set', () => {
27+
expect(fs.existsSync(defaultManifestPath)).toBe(false);
28+
expect(fs.existsSync(defaultStatsPath)).toBe(false);
29+
});
30+
31+
it('should still point to the emitted remote entry', () => {
32+
const remoteEntryFile = stats.metaData.remoteEntry.name;
33+
const remoteEntryPath = path.join(__dirname, remoteEntryFile);
34+
expect(fs.existsSync(remoteEntryPath)).toBe(true);
35+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const lazy = true;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import react from 'react';
2+
import remote from 'remote';
3+
4+
global.react = react;
5+
global.remote = remote;
6+
7+
import('./lazy-module').then((r) => {
8+
console.log('lazy module: ', r);
9+
});
10+
11+
export const ok = true;

0 commit comments

Comments
 (0)