Skip to content

Commit 1c3f284

Browse files
authored
Merge pull request #423 from KevinBatdorf/fix/cache-browsers-and-types
2 parents b123f2d + f610653 commit 1c3f284

7 files changed

Lines changed: 67 additions & 19 deletions

File tree

.github/workflows/playwright-nightly.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,25 @@ jobs:
4747

4848
- run: npm ci --prefer-offline --no-audit --no-fund
4949

50+
- name: Get Playwright version
51+
id: pw-version
52+
run: echo "version=$(npx playwright --version | awk '{print $2}')" >> "$GITHUB_OUTPUT"
53+
54+
- name: Cache Playwright browsers
55+
uses: actions/cache@v4
56+
id: pw-cache
57+
with:
58+
path: ~/.cache/ms-playwright
59+
key: playwright-${{ steps.pw-version.outputs.version }}
60+
5061
- name: Install Playwright Browsers
62+
if: steps.pw-cache.outputs.cache-hit != 'true'
5163
run: npx playwright install --with-deps
5264

65+
- name: Install Playwright deps only
66+
if: steps.pw-cache.outputs.cache-hit == 'true'
67+
run: npx playwright install-deps
68+
5369
- name: Build project
5470
run: npm run build
5571
env:

.github/workflows/playwright.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,25 @@ jobs:
4646

4747
- run: npm ci --prefer-offline --no-audit --no-fund
4848

49+
- name: Get Playwright version
50+
id: pw-version
51+
run: echo "version=$(npx playwright --version | awk '{print $2}')" >> "$GITHUB_OUTPUT"
52+
53+
- name: Cache Playwright browsers
54+
uses: actions/cache@v4
55+
id: pw-cache
56+
with:
57+
path: ~/.cache/ms-playwright
58+
key: playwright-${{ steps.pw-version.outputs.version }}
59+
4960
- name: Install Playwright Browsers
61+
if: steps.pw-cache.outputs.cache-hit != 'true'
5062
run: npx playwright install --with-deps
5163

64+
- name: Install Playwright deps only
65+
if: steps.pw-cache.outputs.cache-hit == 'true'
66+
run: npx playwright install-deps
67+
5268
- name: Build project
5369
run: npm run build
5470
env:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"scripts": {
99
"build": "wp-scripts build",
1010
"format": "biome format --write .",
11-
"lint": "biome check .",
11+
"lint": "biome check . && tsc --noEmit",
1212
"lint:fix": "biome check --fix .",
1313
"packages-update": "wp-scripts packages-update",
1414
"plugin-zip": "wp-scripts plugin-zip",

playwright.config.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
import { existsSync, globSync } from 'node:fs';
1+
import { existsSync } from 'node:fs';
22
import { basename, dirname, join } from 'node:path';
33
import { defineConfig, devices } from '@playwright/test';
4+
import fg from 'fast-glob';
45

56
const BASE_PORT = 9400;
67
const WP_VERSION = process.env.WP_VERSION || 'latest';
78
const RUN_PROJECT = process.env.RUN_PROJECT;
89

910
// Discover spec files that have a blueprint.json in the same directory
10-
const specs = globSync('**/*.spec.ts', { ignore: ['node_modules/**'] })
11+
const specs = fg
12+
.sync('**/*.spec.ts', { ignore: ['node_modules/**'] })
1113
.map((spec) => {
1214
const dir = dirname(spec);
1315
const blueprint = join(dir, 'blueprint.json');
@@ -19,7 +21,16 @@ const specs = globSync('**/*.spec.ts', { ignore: ['node_modules/**'] })
1921
blueprint,
2022
};
2123
})
22-
.filter(Boolean);
24+
.filter(
25+
(
26+
s,
27+
): s is {
28+
name: string;
29+
dir: string;
30+
spec: string;
31+
blueprint: string;
32+
} => s !== null,
33+
);
2334

2435
const active = RUN_PROJECT
2536
? specs.filter((p) => p.name === RUN_PROJECT)

tests/helpers.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import type { Admin, Editor, Page } from '@wordpress/e2e-test-utils-playwright';
1+
import type { Page } from '@playwright/test';
2+
import type {
3+
Admin,
4+
Editor,
5+
RequestUtils,
6+
} from '@wordpress/e2e-test-utils-playwright';
27
import { expect } from '@wordpress/e2e-test-utils-playwright';
38

49
/** Get the block locator within the editor canvas */
@@ -147,7 +152,7 @@ export async function setupCodeBlock({
147152
admin: Admin;
148153
editor: Editor;
149154
page: Page;
150-
requestUtils: { login: () => Promise<void> };
155+
requestUtils: RequestUtils;
151156
}) {
152157
await requestUtils.login();
153158
await admin.createNewPost({ title: 'Test post' });

tests/themes-and-languages/themes-and-languages.spec.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ test.describe('Theme switching', () => {
8989
test('Theme CTA can be removed via filter hook', async ({ page, editor }) => {
9090
// Use wp.hooks.addFilter to replace themes with only Nord
9191
await page.evaluate(() => {
92-
// @ts-expect-error wp is global in WP admin
93-
window.wp.hooks.addFilter(
92+
// biome-ignore lint/suspicious/noExplicitAny: WP global
93+
(window as any).wp.hooks.addFilter(
9494
'blocks.codeBlockPro.themes',
9595
'test/override',
9696
() => ({
@@ -112,17 +112,10 @@ test.describe('Theme switching', () => {
112112
await expect(ctaLinks).toHaveCount(0);
113113
});
114114

115-
test('Random theme renders without errors', async ({ page, editor }) => {
115+
test('Theme renders without errors', async ({ page, editor }) => {
116116
await addCode(editor, 'const x = 1;');
117-
await openPanel(page, 'Theme');
118-
const themeButtons = page.locator('button[id^="code-block-pro-theme-"]');
119-
const count = await themeButtons.count();
120-
expect(count).toBeGreaterThan(0);
121-
const randomIndex = Math.floor(Math.random() * Math.min(count, 10));
122-
const btn = themeButtons.nth(randomIndex);
123-
await btn.scrollIntoViewIfNeeded();
124-
await btn.click();
125-
// Should not show loading or error text
117+
// Switch to a specific non-default theme
118+
await setTheme(page, 'github-dark');
126119
const block = getBlock(editor);
127120
await expect(block).toContainText('const');
128121
const blockHtml = await block.innerHTML();

tsconfig.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,15 @@
1313
"resolveJsonModule": true,
1414
"isolatedModules": true,
1515
"jsx": "preserve",
16+
"types": ["node"],
1617
"incremental": true
1718
},
18-
"include": ["src/**/*.ts", "src/**/*.tsx", "src/front/front.js"],
19+
"include": [
20+
"src/**/*.ts",
21+
"src/**/*.tsx",
22+
"src/front/front.js",
23+
"playwright.config.ts",
24+
"tests/**/*.ts"
25+
],
1926
"exclude": ["node_modules"]
2027
}

0 commit comments

Comments
 (0)