Skip to content

Commit 3c639e7

Browse files
Fix clo Playwright e2e by setting public path and handling fetch errors (#4370)
* chore(clo): manage workspace from repo root * chore: regenerate pnpm lockfile 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
1 parent 4982fd9 commit 3c639e7

11 files changed

+206
-121
lines changed

clo/README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@ This example demos a basic host application loading remote component.
55
- `host` is the host application (cra-based).
66
- `remote` standalone application (cra-based) which exposes `Button` component.
77

8-
# Running Demo
8+
## Setup
99

10-
Run `pnpm run start`. This will build and serve both `host` and `remote` on ports 3001 and 3002 respectively.
10+
Run `pnpm install` in this directory to install dependencies for both `host` and `remote`.
1111

12-
- [localhost:3001](http://localhost:3000/) (HOST)
13-
- [localhost:3002](http://localhost:3002/) (STANDALONE REMOTE)
12+
## Running Demo
13+
14+
Run `pnpm run start`. This will build and serve both `host` and `remote` on ports 3000 and 3002 respectively.
1415

15-
# Running Cypress E2E Tests
16+
- [localhost:3000](http://localhost:3000/) (HOST)
17+
- [localhost:3002](http://localhost:3002/) (STANDALONE REMOTE)
1618

17-
To run tests in interactive mode, run `npm run cypress:debug` from the root directory of the project. It will open Cypress Test Runner and allow to run tests in interactive mode. [More info about "How to run tests"](../../cypress-e2e/README.md#how-to-run-tests)
19+
## Running Playwright E2E Tests
1820

19-
To build app and run test in headless mode, run `yarn e2e:ci`. It will build app and run tests for this workspace in headless mode. If tets failed cypress will create `cypress` directory in sample root folder with screenshots and videos.
21+
To run tests in interactive UI mode, run `pnpm test:e2e:ui`.
2022

21-
["Best Practices, Rules amd more interesting information here](../../cypress-e2e/README.md)
23+
To build the apps, start both servers, and run tests in headless mode, run `pnpm e2e:ci`.

clo/cypress.env.json

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

clo/e2e/checkCraApps.cy.ts

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

clo/e2e/checkCraApps.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
const apps = [
4+
{ port: 3000, name: 'Host' },
5+
{ port: 3002, name: 'Remote' },
6+
];
7+
8+
apps.forEach(({ port, name }) => {
9+
test.describe(`Check ${name}`, () => {
10+
test(`Check ${name} elements exist on the page`, async ({ page }) => {
11+
await page.goto(`http://localhost:${port}`);
12+
await expect(page.getByRole('heading', { level: 1 })).toContainText('Basic Host-Remote');
13+
await expect(page.getByRole('heading', { level: 2, name })).toBeVisible();
14+
await expect(page.getByRole('button')).toContainText('Hello from remote');
15+
});
16+
});
17+
});

clo/host/rsbuild.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,11 @@ export default defineConfig({
99
},
1010
moduleFederation: { options: mfConfig },
1111
plugins: [pluginReact()],
12+
tools: {
13+
rspack: {
14+
output: {
15+
publicPath: 'auto',
16+
},
17+
},
18+
},
1219
});

clo/package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@
99
"scripts": {
1010
"start": "pnpm --filter clo_* start",
1111
"build": "pnpm --filter clo_* build",
12-
"preview": "pnpm run build && pnpm --filter clo_* preview",
13-
"e2e:ci": "pnpm start & npx cypress run --config-file ../cypress-e2e/config/cypress.config.ts --config '{\"supportFile\": \"../cypress-e2e/support/e2e.ts\"}' --spec \"./e2e/*.cy.ts\" --browser=chrome && lsof -ti tcp:3000,3001,3002 | xargs kill"
12+
"preview": "pnpm run build && concurrently \"pnpm --filter clo_host preview\" \"pnpm --filter clo_remote preview\"",
13+
"test:e2e": "npx playwright test",
14+
"test:e2e:ui": "npx playwright test --ui",
15+
"test:e2e:debug": "npx playwright test --debug",
16+
"e2e:ci": "pnpm install && npx playwright install --with-deps && npx playwright test --reporter=list"
1417
},
1518
"devDependencies": {
1619
"wait-on": "7.2.0",
1720
"concurrently": "8.2.2",
18-
"forever": "4.0.3"
21+
"forever": "4.0.3",
22+
"@playwright/test": "^1.54.2",
23+
"playwright": "^1.54.2"
1924
}
2025
}

clo/playwright.config.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { defineConfig, devices } from '@playwright/test';
2+
3+
export default defineConfig({
4+
testDir: './e2e',
5+
timeout: 60000,
6+
expect: {
7+
timeout: 15000,
8+
},
9+
fullyParallel: true,
10+
forbidOnly: !!process.env.CI,
11+
retries: process.env.CI ? 1 : 0,
12+
workers: process.env.CI ? 1 : undefined,
13+
reporter: [
14+
['html', { outputFolder: 'playwright-report', open: 'never' }],
15+
['list'],
16+
],
17+
use: {
18+
trace: 'on-first-retry',
19+
screenshot: 'only-on-failure',
20+
video: 'retain-on-failure',
21+
viewport: { width: 1920, height: 1080 },
22+
},
23+
projects: [
24+
{
25+
name: 'chromium',
26+
use: { ...devices['Desktop Chrome'] },
27+
},
28+
],
29+
webServer: {
30+
command: 'pnpm preview',
31+
port: 3000,
32+
reuseExistingServer: !process.env.CI,
33+
timeout: 120000,
34+
},
35+
});

clo/remote/rsbuild.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,11 @@ export default defineConfig({
99
},
1010
moduleFederation: { options: mfConfig },
1111
plugins: [pluginReact()],
12+
tools: {
13+
rspack: {
14+
output: {
15+
publicPath: 'auto',
16+
},
17+
},
18+
},
1219
});

clo/remote/src/ServiceComponent.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function fetchData(url) {
2121
if (status === 'pending') {
2222
throw suspender;
2323
} else if (status === 'error') {
24-
throw result;
24+
return { error: result };
2525
} else if (status === 'success') {
2626
return result;
2727
}
@@ -33,6 +33,9 @@ const resource = fetchData('https://jsonplaceholder.typicode.com/todos/1');
3333

3434
function HelloWorld() {
3535
const data = resource.read(); // This will suspend if the data isn't ready
36+
if (data?.error) {
37+
return <pre>Error loading data</pre>;
38+
}
3639
return <pre>{JSON.stringify(data)}</pre>;
3740
}
3841

0 commit comments

Comments
 (0)