Skip to content

Commit 1a4ad8e

Browse files
committed
chore: covered varFileName example with e2e
1 parent 462d135 commit 1a4ad8e

File tree

8 files changed

+58
-44
lines changed

8 files changed

+58
-44
lines changed

e2e/vite-webpack-rspack/tests/index.spec.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ test.describe('Vite Host Tests', () => {
3838
});
3939
});
4040

41-
test.describe('Vite remote', () => {
41+
test.describe('Vite module remote', () => {
4242
test('has title', async ({ page, baseURL }) => {
4343
await page.goto(baseURL!);
4444
const productHeader = page.getByRole('heading', {
@@ -78,6 +78,19 @@ test.describe('Vite remote', () => {
7878
});
7979
});
8080

81+
test.describe('Vite var remote', () => {
82+
test('has title', async ({ page, baseURL }) => {
83+
await page.goto(baseURL!);
84+
const purchasesCountHeader = page.getByRole('heading', {
85+
level: 2,
86+
name: 'Count of purchases',
87+
exact: true,
88+
});
89+
90+
await expect(purchasesCountHeader).toBeVisible();
91+
});
92+
});
93+
8194
test.describe('Rspack remote', () => {
8295
test('has title', async ({ page, baseURL }) => {
8396
await page.goto(baseURL!);
@@ -139,7 +152,11 @@ test.describe('Dynamic remote', () => {
139152
// Check that lodash version is displayed in SpecialPromo banner
140153
await showAdToggle.check({ force: true });
141154

142-
const specialPromoBanner = page.getByRole('heading', { level: 2, name: 'Up to 50% off!', exact: true });
155+
const specialPromoBanner = page.getByRole('heading', {
156+
level: 2,
157+
name: 'Up to 50% off!',
158+
exact: true,
159+
});
143160
await expect(specialPromoBanner).toBeVisible();
144161

145162
const lodashVersionDisplay = page.getByTestId('lodash-version-display');

examples/vite-vite/vite-host/src/App.jsx

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,9 @@ import { MuiDemo } from '@namespace/viteViteRemote/MuiDemo';
1010
import StyledDemo from '@namespace/viteViteRemote/StyledDemo';
1111
import { ref } from 'vue';
1212

13-
import { mf } from './mf';
14-
1513
console.log('Share Vue', ref);
1614
console.log('Share React', R, RD);
1715

18-
// @namespace/viteViteRemote is not valid name variable, thus we have to load it with loadRemote instaed of basic usage
19-
const LazyVarApp = R.lazy(() => {
20-
return mf.loadRemote('@namespace/viteViteRemote')
21-
})
22-
2316
export default function () {
2417
return (
2518
<div style={{ background: 'lightgray' }}>
@@ -51,11 +44,6 @@ export default function () {
5144
<EmotionDemo />
5245

5346
<hr />
54-
55-
<h2>LazyVarApp</h2>
56-
<R.Suspense fallback="loading...">
57-
<LazyVarApp />
58-
</R.Suspense>
5947
</div>
6048
);
6149
}

examples/vite-vite/vite-host/src/mf.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

examples/vite-vite/vite-remote/vite.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default defineConfig({
2929
},
3030
dts: false,
3131
filename: 'remoteEntry-[hash].js',
32-
varFilename: 'varRemoteEntry.js',
32+
varFilename: 'varRemoteEntry.js', // in cases when host's config requires remote's "type": "var"
3333
manifest: true,
3434
shared: {
3535
vue: {},

examples/vite-webpack-rspack/host/src/App.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@ import './index.css';
1010
import _ from 'lodash';
1111
_.VERSION;
1212

13-
const RemoteProduct = lazy(
13+
const ModuleRemoteProduct = lazy(
1414
() =>
1515
// @ts-ignore
16-
import('remote/Product')
16+
import('moduleRemote/Product')
17+
);
18+
const VarRemotePurchasesCount = lazy(
19+
() =>
20+
// @ts-ignore
21+
import('remote/PurchasesCount')
1722
);
1823
const RspackReviews = lazy(
1924
() =>
@@ -68,7 +73,10 @@ const App = () => {
6873
<Toggle label="Show Dynamic Ad" checked={showAd} onValueChange={setShowAd} />
6974
{showAd && <Suspense fallback="Loading...">{Banner ? <Banner /> : null}</Suspense>}
7075
<Suspense fallback="Loading...">
71-
<RemoteProduct />
76+
<ModuleRemoteProduct />
77+
</Suspense>
78+
<Suspense fallback="Loading...">
79+
<VarRemotePurchasesCount />
7280
</Suspense>
7381
<Suspense fallback="Loading...">
7482
<RspackReviews />

examples/vite-webpack-rspack/host/vite.config.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,17 @@ import { defineConfig } from 'vite';
55
const mfConfig = {
66
name: 'host',
77
remotes: {
8-
remote: {
8+
// vite remote (module)
9+
moduleRemote: {
10+
name: 'moduleRemote', // should not conflict with "var" remote name // todo: related to https://github.com/module-federation/vite/issues/352
911
entry: 'http://localhost:4001/custom-filename.js',
1012
type: 'module',
1113
},
14+
// vite remote (var)
15+
remote: {
16+
entry: 'http://localhost:4001/varRemoteEntry.js',
17+
type: 'var',
18+
},
1219
webpack: {
1320
entry: 'http://localhost:8080/remoteEntry.js',
1421
type: 'var',
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export default () => {
2+
return (
3+
<section aria-labelledby="purchases-count" className="mt-16 sm:mt-24">
4+
<h2 className="text-lg font-medium text-gray-900">Count of purchases </h2>
5+
6+
<div className="mt-6">
7+
<h3 className="text-sm font-medium text-gray-900">Total</h3>
8+
<div className="mt-3 space-y-6 text-sm text-gray-500">1928</div>
9+
</div>
10+
11+
<div className="mt-6">
12+
<h3 className="text-sm font-medium text-gray-900">For the last 30 days</h3>
13+
<div className="mt-3 space-y-6 text-sm text-gray-500">155</div>
14+
</div>
15+
</section>
16+
);
17+
};

examples/vite-webpack-rspack/remote/vite.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ export default defineConfig({
99
federation({
1010
name: 'remote',
1111
filename: 'custom-filename.js',
12+
varFilename: 'varRemoteEntry.js',
1213
// Modules to expose
1314
exposes: {
1415
'./Product': './src/Product.jsx',
16+
'./PurchasesCount': './src/PurchasesCount.jsx',
1517
},
1618
shared: ['react', 'react-dom'],
1719
}),

0 commit comments

Comments
 (0)