Skip to content

Commit dd525d8

Browse files
bidodevgioboa
andauthored
ci: add e2e tests for multi-example app (module-federation#120)
--------- Co-authored-by: gioboa <[email protected]>
1 parent 1817082 commit dd525d8

File tree

11 files changed

+561
-184
lines changed

11 files changed

+561
-184
lines changed

.github/workflows/build.yml

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

.github/workflows/e2e-test.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: multi-example - e2e tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
permissions:
12+
pull-requests: read
13+
14+
jobs:
15+
run-playwright-tests:
16+
name: Playwright Tests
17+
runs-on: ubuntu-latest
18+
container: node:20
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
23+
- name: Enable Corepack and Setup PNPM
24+
run: |
25+
corepack enable
26+
corepack prepare [email protected] --activate
27+
28+
- name: Install Dependencies
29+
run: pnpm install --frozen-lockfile
30+
31+
- name: Install Chromium Browser
32+
run: pnpm playwright install --with-deps chromium
33+
34+
- name: Build Projects
35+
run: pnpm build
36+
37+
- name: Start Application multi-example
38+
run: nohup pnpm run multi-example & pnpm exec wait-on http://localhost:5173;
39+
40+
- name: Run Playwright Tests
41+
run: pnpm playwright test
42+
43+
- name: Upload Artifacts on Failure
44+
if: failure()
45+
uses: actions/upload-artifact@v4
46+
with:
47+
name: test-results
48+
path: reports/e2e/output
49+
retention-days: 3

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ dist
44
.idea
55
.__mf__win
66
lib
7-
**/.__mf__temp
7+
**/.__mf__temp
8+
reports/*
9+
nohup.out

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"source.organizeImports": "always",
44
"source.fixAll": "always"
55
},
6-
"editor.formatOnSave": true
6+
"editor.formatOnSave": true,
7+
"cSpell.words": ["microfrontend"]
78
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { expect, test } from '@playwright/test';
2+
3+
test.describe('Vite Host Tests', () => {
4+
test.beforeEach(async ({ page, baseURL }) => {
5+
await page.goto(baseURL!);
6+
});
7+
8+
test('test header - vite host', async ({ page }) => {
9+
const womenButton = page.getByRole('button', { name: 'Women', exact: true });
10+
const manButton = page.getByRole('button', { name: 'Man', exact: true });
11+
const companyButton = page.getByRole('button', { name: 'Company', exact: true });
12+
const storesButton = page.getByRole('button', { name: 'Stores', exact: true });
13+
14+
await Promise.all([
15+
expect(womenButton).toBeVisible(),
16+
expect(manButton).toBeVisible(),
17+
expect(companyButton).toBeVisible(),
18+
expect(storesButton).toBeVisible(),
19+
]);
20+
});
21+
22+
test('test footer - vite host', async ({ page }) => {
23+
const productsHeading = page.getByRole('heading', { level: 3, name: 'Products', exact: true });
24+
const companyHeading = page.getByRole('heading', { level: 3, name: 'Company', exact: true });
25+
const customerServiceHeading = page.getByRole('heading', {
26+
level: 3,
27+
name: 'Customer Service',
28+
exact: true,
29+
});
30+
31+
await Promise.all([
32+
expect(productsHeading).toBeVisible(),
33+
expect(companyHeading).toBeVisible(),
34+
expect(customerServiceHeading).toBeVisible(),
35+
]);
36+
});
37+
});
38+
39+
test.describe('Vite remote', () => {
40+
test('has title', async ({ page, baseURL }) => {
41+
await page.goto(baseURL!);
42+
const productHeader = page.getByRole('heading', {
43+
level: 1,
44+
name: 'Basic Tee',
45+
exact: true,
46+
});
47+
await expect(productHeader).toBeVisible();
48+
});
49+
});
50+
51+
test.describe('Rspack remote', () => {
52+
test('has title', async ({ page, baseURL }) => {
53+
await page.goto(baseURL!);
54+
const recentReviews = page.getByRole('heading', {
55+
level: 2,
56+
name: 'Recent reviews',
57+
exact: true,
58+
});
59+
await expect(recentReviews).toBeVisible();
60+
});
61+
});
62+
63+
test.describe('Webpack remote', () => {
64+
test('has title', async ({ page, baseURL }) => {
65+
await page.goto(baseURL!);
66+
const furtherRecommendations = page.getByRole('heading', {
67+
level: 2,
68+
name: 'Customers also purchased',
69+
exact: true,
70+
});
71+
await expect(furtherRecommendations).toBeVisible();
72+
});
73+
});

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ const mfConfig = {
2323

2424
// https://vitejs.dev/config/
2525
export default defineConfig({
26+
server: {
27+
host: true,
28+
},
2629
plugins: [
2730
react(),
2831
federation({

examples/vite-webpack-rspack/remote/src/Product.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import ProductImage from './ProductImage';
55
export default () => {
66
const [size, setSize] = useState('M');
77
const [color, setColor] = useState('black');
8+
89
return (
910
<div className="lg:grid lg:auto-rows-min lg:grid-cols-12 lg:gap-x-8">
1011
<ProductHeader />
@@ -76,7 +77,7 @@ export default () => {
7677
</div>
7778
</div>
7879
<button
79-
type="submit"
80+
type="button"
8081
className="mt-8 flex w-full items-center justify-center rounded-md border border-transparent bg-slate-600 px-8 py-3 text-base font-medium text-white hover:bg-slate-700 focus:outline-none focus:ring-2 focus:ring-slate-500 focus:ring-offset-2"
8182
onClick={() => {
8283
window.dispatchEvent(new CustomEvent('ADD_CART'));

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,19 @@
5050
"defu": "^6.1.4",
5151
"estree-walker": "^2",
5252
"magic-string": "^0.30.11",
53-
"pathe": "^1.1.2",
54-
"vitest": "^2.1.1"
53+
"vitest": "^2.1.1",
54+
"pathe": "^1.1.2"
5555
},
5656
"devDependencies": {
57+
"@playwright/test": "^1.47.2",
58+
"@types/node": "^22.7.4",
5759
"husky": "^8.0.3",
5860
"microbundle": "^0.15.1",
5961
"mime-types": "^2.1.35",
6062
"prettier": "3.3.3",
6163
"pretty-quick": "^4.0.0",
6264
"rimraf": "^6.0.1",
63-
"vite": "^5.4.3"
65+
"vite": "^5.4.3",
66+
"wait-on": "^8.0.1"
6467
}
6568
}

playwright.config.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { defineConfig } from '@playwright/test';
2+
3+
export default defineConfig({
4+
testDir: 'tests',
5+
timeout: 30 * 1000,
6+
retries: process.env.CI ? 2 : 0,
7+
workers: process.env.CI ? 1 : undefined,
8+
forbidOnly: Boolean(process.env.CI),
9+
use: {
10+
trace: 'retain-on-failure',
11+
screenshot: 'only-on-failure',
12+
video: 'retain-on-failure',
13+
},
14+
projects: [
15+
{
16+
name: 'multi-example',
17+
testDir: 'e2e/vite-webpack-rspack',
18+
use: {
19+
baseURL: 'http://localhost:5173',
20+
browserName: 'chromium',
21+
},
22+
},
23+
],
24+
outputDir: 'reports/e2e/output',
25+
reporter: [
26+
['list'],
27+
['html', { outputFolder: 'reports/e2e/playwright-report', open: 'never' }],
28+
['json', { outputFile: 'reports/e2e/test-results.json' }],
29+
],
30+
});

0 commit comments

Comments
 (0)