Skip to content

Commit 3bd1185

Browse files
chore: migrate downstream tests from Cypress to Playwright
1 parent 6265281 commit 3bd1185

20 files changed

Lines changed: 365 additions & 363 deletions

test-angular-versions/scaffold.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@ DIR=v$VERSION
1212

1313
npx -y -p @angular/cli@$VERSION ng new --package-manager=yarn --style=css --routing=false --skip-git --skip-install --skip-tests $DIR
1414
rm -rf $DIR/src/app
15-
cp -Rp scaffold/* $DIR
15+
cp -Rp scaffold/src $DIR/
16+
cp -Rp scaffold/e2e $DIR/
17+
cp scaffold/playwright.config.ts $DIR/
1618

1719
$JSON write $DIR/package.json name "$VERSION"
1820
$JSON write $DIR/package.json dependencies.@uirouter/angular "*"
19-
$JSON write $DIR/package.json dependencies.@uirouter/cypress-runner "*"
21+
$JSON write $DIR/package.json devDependencies.@playwright/test "^1.49.0"
22+
$JSON write $DIR/package.json devDependencies.serve "^14.2.4"
2023
$JSON write $DIR/package.json scripts.test "npm run test:dev && npm run test:prod"
21-
$JSON write $DIR/package.json scripts.test:dev "ng build --configuration development && cypress-runner run --path dist/$DIR"
22-
$JSON write $DIR/package.json scripts.test:prod "ng build --configuration production && cypress-runner run --path dist/$DIR"
24+
$JSON write $DIR/package.json scripts.test:dev "ng build --configuration development && DIST_PATH=dist/$DIR/browser npx playwright test"
25+
$JSON write $DIR/package.json scripts.test:prod "ng build --configuration production && DIST_PATH=dist/$DIR/browser npx playwright test"
2326

2427
$JSON write ../downstream_projects.json "projects.angular$VERSION" "./test-angular-versions/$DIR"

test-angular-versions/scaffold/cypress.config.ts

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

test-angular-versions/scaffold/cypress/e2e/sample_app.cy.js

Lines changed: 0 additions & 69 deletions
This file was deleted.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
test.describe('Angular app', () => {
4+
test('loads', async ({ page }) => {
5+
await page.goto('/');
6+
});
7+
8+
test('loads home state by default', async ({ page }) => {
9+
await page.goto('/');
10+
await expect(page).toHaveURL(/\/home/);
11+
});
12+
13+
test('renders uisref as links', async ({ page }) => {
14+
await page.goto('/');
15+
await expect(page.locator('a', { hasText: 'home' })).toBeVisible();
16+
await expect(page.locator('a', { hasText: 'about' })).toBeVisible();
17+
await expect(page.locator('a', { hasText: 'lazy' }).first()).toBeVisible();
18+
await expect(page.locator('a', { hasText: 'lazy.child' }).first()).toBeVisible();
19+
await expect(page.locator('a', { hasText: 'lazy.child.viewtarget' })).toBeVisible();
20+
});
21+
22+
test('renders home', async ({ page }) => {
23+
await page.goto('/home');
24+
await expect(page.locator('a', { hasText: 'home' })).toHaveClass(/active/);
25+
await expect(page.locator('a', { hasText: 'about' })).not.toHaveClass(/active/);
26+
await expect(page.locator('#default')).toContainText('home works');
27+
});
28+
29+
test('renders about', async ({ page }) => {
30+
await page.goto('/home');
31+
await page.goto('/about');
32+
await expect(page.locator('a', { hasText: 'home' })).not.toHaveClass(/active/);
33+
await expect(page.locator('a', { hasText: 'about' })).toHaveClass(/active/);
34+
await expect(page.locator('#default')).toContainText('about works');
35+
});
36+
37+
test('loads lazy routes', async ({ page }) => {
38+
await page.goto('/home');
39+
await page.goto('/lazy');
40+
await expect(page.locator('a', { hasText: 'home' })).not.toHaveClass(/active/);
41+
await expect(page.locator('a', { hasText: 'lazy' }).first()).toHaveClass(/active/);
42+
await expect(page.locator('#default')).toContainText('lazy works');
43+
});
44+
45+
test('routes to lazy routes', async ({ page }) => {
46+
await page.goto('/lazy');
47+
await expect(page.locator('a', { hasText: 'home' })).not.toHaveClass(/active/);
48+
await expect(page.locator('a', { hasText: 'lazy' }).first()).toHaveClass(/active/);
49+
await expect(page.locator('#default')).toContainText('lazy works');
50+
});
51+
52+
test('routes to lazy child routes', async ({ page }) => {
53+
await page.goto('/lazy/child');
54+
await expect(page.locator('a', { hasText: 'home' })).not.toHaveClass(/active/);
55+
await expect(page.locator('a', { hasText: 'lazy.child' }).first()).toHaveClass(/active/);
56+
await expect(page.locator('#default')).toContainText('lazy.child works');
57+
});
58+
59+
test('targets named views', async ({ page }) => {
60+
await page.goto('/lazy/child/viewtarget');
61+
await expect(page.locator('a', { hasText: 'home' })).not.toHaveClass(/active/);
62+
await expect(page.locator('a', { hasText: 'lazy.child' }).first()).toHaveClass(/active/);
63+
await expect(page.locator('#default')).toContainText('lazy.child works');
64+
await expect(page.locator('#header')).toContainText('lazy.child.viewtarget works');
65+
await expect(page.locator('#footer')).toContainText('lazy.child.viewtarget works');
66+
});
67+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { defineConfig } from '@playwright/test';
2+
3+
const distPath = process.env.DIST_PATH || 'dist';
4+
5+
export default defineConfig({
6+
testDir: './e2e',
7+
fullyParallel: true,
8+
forbidOnly: !!process.env.CI,
9+
reporter: 'list',
10+
use: {
11+
baseURL: 'http://localhost:4000',
12+
trace: 'on-first-retry',
13+
},
14+
webServer: {
15+
command: `npx serve ${distPath} -l 4000 -s`,
16+
url: 'http://localhost:4000',
17+
reuseExistingServer: !process.env.CI,
18+
},
19+
});

test-angular-versions/v21-standalone/cypress.config.js

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

test-angular-versions/v21-standalone/cypress/e2e/sample_app.cy.js

Lines changed: 0 additions & 70 deletions
This file was deleted.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
test.describe('Angular app', () => {
4+
test('loads', async ({ page }) => {
5+
await page.goto('/');
6+
});
7+
8+
test('loads home state by default', async ({ page }) => {
9+
await page.goto('/');
10+
await expect(page).toHaveURL(/\/home/);
11+
});
12+
13+
test('renders uisref as links', async ({ page }) => {
14+
await page.goto('/');
15+
await expect(page.locator('a', { hasText: 'home' })).toBeVisible();
16+
await expect(page.locator('a', { hasText: 'about' })).toBeVisible();
17+
await expect(page.locator('a', { hasText: 'lazy' }).first()).toBeVisible();
18+
await expect(page.locator('a', { hasText: 'lazy.child' }).first()).toBeVisible();
19+
await expect(page.locator('a', { hasText: 'lazy.child.viewtarget' })).toBeVisible();
20+
});
21+
22+
test('renders home', async ({ page }) => {
23+
await page.goto('/home');
24+
await expect(page.locator('a', { hasText: 'home' })).toHaveClass(/active/);
25+
await expect(page.locator('a', { hasText: 'about' })).not.toHaveClass(/active/);
26+
await expect(page.locator('#default')).toContainText('home works');
27+
});
28+
29+
test('renders about', async ({ page }) => {
30+
await page.goto('/home');
31+
await page.goto('/about');
32+
await expect(page.locator('a', { hasText: 'home' })).not.toHaveClass(/active/);
33+
await expect(page.locator('a', { hasText: 'about' })).toHaveClass(/active/);
34+
await expect(page.locator('#default')).toContainText('about works');
35+
});
36+
37+
test('loads lazy routes', async ({ page }) => {
38+
await page.goto('/home');
39+
await page.goto('/lazy');
40+
await expect(page.locator('a', { hasText: 'home' })).not.toHaveClass(/active/);
41+
await expect(page.locator('a', { hasText: 'lazy' }).first()).toHaveClass(/active/);
42+
await expect(page.locator('#default')).toContainText('lazy works');
43+
});
44+
45+
test('routes to lazy routes', async ({ page }) => {
46+
await page.goto('/lazy');
47+
await expect(page.locator('a', { hasText: 'home' })).not.toHaveClass(/active/);
48+
await expect(page.locator('a', { hasText: 'lazy' }).first()).toHaveClass(/active/);
49+
await expect(page.locator('#default')).toContainText('lazy works');
50+
});
51+
52+
test('routes to lazy child routes', async ({ page }) => {
53+
await page.goto('/lazy/child');
54+
await expect(page.locator('a', { hasText: 'home' })).not.toHaveClass(/active/);
55+
await expect(page.locator('a', { hasText: 'lazy.child' }).first()).toHaveClass(/active/);
56+
await expect(page.locator('#default')).toContainText('lazy.child works');
57+
await expect(page.locator('#lazy-child-provided')).toContainText('provided value');
58+
});
59+
60+
test('targets named views', async ({ page }) => {
61+
await page.goto('/lazy/child/viewtarget');
62+
await expect(page.locator('a', { hasText: 'home' })).not.toHaveClass(/active/);
63+
await expect(page.locator('a', { hasText: 'lazy.child' }).first()).toHaveClass(/active/);
64+
await expect(page.locator('#default')).toContainText('lazy.child works');
65+
await expect(page.locator('#header')).toContainText('lazy.child.viewtarget works');
66+
await expect(page.locator('#footer')).toContainText('lazy.child.viewtarget works');
67+
});
68+
});

test-angular-versions/v21-standalone/package.json

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"build": "ng build",
88
"watch": "ng build --watch --configuration development",
99
"test": "npm run test:dev && npm run test:prod",
10-
"test:dev": "ng build --configuration development && cypress-runner run --path dist/v21-standalone/browser",
11-
"test:prod": "ng build --configuration production && cypress-runner run --path dist/v21-standalone/browser"
10+
"test:dev": "ng build --configuration development && DIST_PATH=dist/v21-standalone/browser npx playwright test",
11+
"test:prod": "ng build --configuration production && DIST_PATH=dist/v21-standalone/browser npx playwright test"
1212
},
1313
"private": true,
1414
"dependencies": {
@@ -18,7 +18,6 @@
1818
"@angular/platform-browser": "^21.0.3",
1919
"@angular/platform-browser-dynamic": "^21.0.3",
2020
"@uirouter/angular": "*",
21-
"@uirouter/cypress-runner": "*",
2221
"@uirouter/core": "*",
2322
"@uirouter/rx": "*",
2423
"rxjs": "~7.8.0",
@@ -29,19 +28,8 @@
2928
"@angular/build": "^21.0.2",
3029
"@angular/cli": "^21.0.2",
3130
"@angular/compiler-cli": "^21.0.3",
32-
"@types/jasmine": "~5.1.0",
33-
"jasmine-core": "~5.1.0",
34-
"karma": "~6.4.0",
35-
"karma-chrome-launcher": "~3.2.0",
36-
"karma-coverage": "~2.2.0",
37-
"karma-jasmine": "~5.1.0",
38-
"karma-jasmine-html-reporter": "~2.1.0",
31+
"@playwright/test": "^1.49.0",
32+
"serve": "^14.2.4",
3933
"typescript": "~5.9.3"
40-
},
41-
"checkPeerDependencies": {
42-
"ignore": [
43-
"ajv",
44-
"terser"
45-
]
4634
}
4735
}

0 commit comments

Comments
 (0)