Skip to content

Commit 9417a97

Browse files
Refine CRA Playwright migration (#4381)
* Refine CRA Playwright migration * Merge branch 'master' into work
1 parent d825f55 commit 9417a97

File tree

8 files changed

+197
-204
lines changed

8 files changed

+197
-204
lines changed

cra/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
# testing
99
/coverage
1010

11+
# Playwright artifacts
12+
playwright-report/
13+
test-results/
14+
blob-report/
15+
1116
# production
1217
/build
1318

cra/README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@ This example demos a basic host application loading remote component.
77

88
# Running Demo
99

10-
Run `pnpm run start`. This will build and serve both `host` and `remote` on ports 3001 and 3002 respectively.
10+
Run `pnpm run start`. This will build and serve both `host` and `remote` on ports 3000 and 3002 respectively.
1111

12-
- [localhost:3001](http://localhost:3000/) (HOST)
12+
- [localhost:3000](http://localhost:3000/) (HOST)
1313
- [localhost:3002](http://localhost:3002/) (STANDALONE REMOTE)
1414

15-
# Running Cypress E2E Tests
15+
# Running Playwright E2E Tests
1616

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)
17+
Run the following commands from this directory:
1818

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.
19+
- `pnpm test:e2e`: launches the host and remote servers and runs the Playwright suite headlessly.
20+
- `pnpm test:e2e:ui`: opens the Playwright test runner UI for local development.
21+
- `pnpm test:e2e:debug`: starts the suite in headed mode with Playwright's inspector attached.
22+
- `pnpm e2e:ci`: installs the required browsers (when needed) and executes the suite with a list reporter while collecting failure artifacts (traces, screenshots, videos).
2023

21-
["Best Practices, Rules amd more interesting information here](../../cypress-e2e/README.md)
24+
> **Note:** The first Playwright run may require downloading browser binaries. If they are not already installed you can run `pnpm exec playwright install` once to prepare the environment.

cra/cypress.env.json

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

cra/e2e/checkCraApps.cy.ts

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

cra/e2e/checkCraApps.spec.ts

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

cra/package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
"start": "pnpm --filter cra_* start",
1111
"build": "pnpm --filter cra_* build",
1212
"preview": "pnpm run build && pnpm --filter cra_* preview",
13-
"e2e:ci": "pnpm start & sleep 3 && (wait-on tcp:3000 tcp:3002 --timeout 30000 || echo 'wait-on timed out, proceeding with Cypress') && 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"
13+
"test:e2e": "pnpm exec playwright test",
14+
"test:e2e:ui": "pnpm exec playwright test --ui",
15+
"test:e2e:debug": "pnpm exec playwright test --debug",
16+
"e2e:ci": "pnpm exec playwright install --with-deps && pnpm exec playwright test --reporter=list"
1417
},
1518
"devDependencies": {
16-
"wait-on": "7.2.0",
17-
"concurrently": "8.2.2",
18-
"forever": "4.0.3"
19+
"@playwright/test": "^1.54.2",
20+
"playwright": "^1.54.2"
1921
}
2022
}

cra/playwright.config.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
baseURL: 'http://localhost:3000',
19+
trace: 'on-first-retry',
20+
screenshot: 'only-on-failure',
21+
video: 'retain-on-failure',
22+
viewport: { width: 1920, height: 1080 },
23+
},
24+
25+
projects: [
26+
{
27+
name: 'chromium',
28+
use: { ...devices['Desktop Chrome'] },
29+
},
30+
],
31+
32+
webServer: [
33+
{
34+
command: 'pnpm start',
35+
cwd: 'remote',
36+
port: 3002,
37+
reuseExistingServer: !process.env.CI,
38+
timeout: 120000,
39+
},
40+
{
41+
command: 'pnpm start',
42+
cwd: 'host',
43+
port: 3000,
44+
reuseExistingServer: !process.env.CI,
45+
timeout: 120000,
46+
},
47+
],
48+
});

0 commit comments

Comments
 (0)