Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add e2e tests for multi-example app #120

Merged
merged 14 commits into from
Oct 5, 2024
Merged
39 changes: 0 additions & 39 deletions .github/workflows/build.yml

This file was deleted.

49 changes: 49 additions & 0 deletions .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: multi-example - e2e tests

on:
push:
branches:
- main
pull_request:
branches:
- main

permissions:
pull-requests: read

jobs:
run-playwright-tests:
name: Playwright Tests
runs-on: ubuntu-latest
container: node:20
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Enable Corepack and Setup PNPM
run: |
corepack enable
corepack prepare [email protected] --activate

- name: Install Dependencies
run: pnpm install --frozen-lockfile

- name: Install Chromium Browser
run: pnpm playwright install --with-deps chromium

- name: Build Projects
run: pnpm build

- name: Start Application multi-example
run: nohup pnpm run multi-example & pnpm exec wait-on http://localhost:5173;

- name: Run Playwright Tests
run: pnpm playwright test

- name: Upload Artifacts on Failure
if: failure()
uses: actions/upload-artifact@v4
with:
name: test-results
path: reports/e2e/output
retention-days: 3
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ dist
.idea
.__mf__win
lib
**/.__mf__temp
**/.__mf__temp
reports/*
nohup.out
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"source.organizeImports": "always",
"source.fixAll": "always"
},
"editor.formatOnSave": true
"editor.formatOnSave": true,
"cSpell.words": ["microfrontend"]
}
73 changes: 73 additions & 0 deletions e2e/vite-webpack-rspack/tests/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { expect, test } from '@playwright/test';

test.describe('Vite Host Tests', () => {
test.beforeEach(async ({ page, baseURL }) => {
await page.goto(baseURL!);
});

test('test header - vite host', async ({ page }) => {
const womenButton = page.getByRole('button', { name: 'Women', exact: true });
const manButton = page.getByRole('button', { name: 'Man', exact: true });
const companyButton = page.getByRole('button', { name: 'Company', exact: true });
const storesButton = page.getByRole('button', { name: 'Stores', exact: true });

await Promise.all([
expect(womenButton).toBeVisible(),
expect(manButton).toBeVisible(),
expect(companyButton).toBeVisible(),
expect(storesButton).toBeVisible(),
]);
});

test('test footer - vite host', async ({ page }) => {
const productsHeading = page.getByRole('heading', { level: 3, name: 'Products', exact: true });
const companyHeading = page.getByRole('heading', { level: 3, name: 'Company', exact: true });
const customerServiceHeading = page.getByRole('heading', {
level: 3,
name: 'Customer Service',
exact: true,
});

await Promise.all([
expect(productsHeading).toBeVisible(),
expect(companyHeading).toBeVisible(),
expect(customerServiceHeading).toBeVisible(),
]);
});
});

test.describe('Vite remote', () => {
test('has title', async ({ page, baseURL }) => {
await page.goto(baseURL!);
const productHeader = page.getByRole('heading', {
level: 1,
name: 'Basic Tee',
exact: true,
});
await expect(productHeader).toBeVisible();
});
});

test.describe('Rspack remote', () => {
test('has title', async ({ page, baseURL }) => {
await page.goto(baseURL!);
const recentReviews = page.getByRole('heading', {
level: 2,
name: 'Recent reviews',
exact: true,
});
await expect(recentReviews).toBeVisible();
});
});

test.describe('Webpack remote', () => {
test('has title', async ({ page, baseURL }) => {
await page.goto(baseURL!);
const furtherRecommendations = page.getByRole('heading', {
level: 2,
name: 'Customers also purchased',
exact: true,
});
await expect(furtherRecommendations).toBeVisible();
});
});
3 changes: 3 additions & 0 deletions examples/vite-webpack-rspack/host/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ const mfConfig = {

// https://vitejs.dev/config/
export default defineConfig({
server: {
host: true,
},
plugins: [
react(),
federation({
Expand Down
3 changes: 2 additions & 1 deletion examples/vite-webpack-rspack/remote/src/Product.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ProductImage from './ProductImage';
export default () => {
const [size, setSize] = useState('M');
const [color, setColor] = useState('black');

return (
<div className="lg:grid lg:auto-rows-min lg:grid-cols-12 lg:gap-x-8">
<ProductHeader />
Expand Down Expand Up @@ -76,7 +77,7 @@ export default () => {
</div>
</div>
<button
type="submit"
type="button"
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"
onClick={() => {
window.dispatchEvent(new CustomEvent('ADD_CART'));
Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,19 @@
"defu": "^6.1.4",
"estree-walker": "^2",
"magic-string": "^0.30.11",
"pathe": "^1.1.2",
"vitest": "^2.1.1"
"vitest": "^2.1.1",
"pathe": "^1.1.2"
},
"devDependencies": {
"@playwright/test": "^1.47.2",
"@types/node": "^22.7.4",
"husky": "^8.0.3",
"microbundle": "^0.15.1",
"mime-types": "^2.1.35",
"prettier": "3.3.3",
"pretty-quick": "^4.0.0",
"rimraf": "^6.0.1",
"vite": "^5.4.3"
"vite": "^5.4.3",
"wait-on": "^8.0.1"
}
}
30 changes: 30 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { defineConfig } from '@playwright/test';

export default defineConfig({
testDir: 'tests',
timeout: 30 * 1000,
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 1 : undefined,
forbidOnly: Boolean(process.env.CI),
use: {
trace: 'retain-on-failure',
screenshot: 'only-on-failure',
video: 'retain-on-failure',
},
projects: [
{
name: 'multi-example',
testDir: 'e2e/vite-webpack-rspack',
use: {
baseURL: 'http://localhost:5173',
browserName: 'chromium',
},
},
],
outputDir: 'reports/e2e/output',
reporter: [
['list'],
['html', { outputFolder: 'reports/e2e/playwright-report', open: 'never' }],
['json', { outputFile: 'reports/e2e/test-results.json' }],
],
});
Loading