Skip to main content

playwright-testing

Use when creating or modifying Playwright end-to-end tests, especially when injecting mock plugins to test platform features.

来源信息

仓库
silvertakana/worldwideview
最近来源活动
2026年5月16日 00:29
检测到的 SKILL.md 语言
英语
星标
1,916
分支
424

安装方式

默认使用会先检查来源的 Prompt;你也可以切换为直接命令,或下载本地副本。

检查来源文件

决定是否安装前,请先阅读 SKILL.md,以及 SkillsMP 当前展示的配套文件。

正在显示 SKILL.md

SKILL.md
来源说明 · 只读预览
name
playwright-testing
description
Use when creating or modifying Playwright end-to-end tests, especially when injecting mock plugins to test platform features.
# Playwright E2E Testing & Mock Plugin Guide When you are tasked with testing a new feature or plugin in WorldWideView using Playwright, you must use this skill to ensure you follow the strict architecture rules of the platform. ## 1. Mock Plugin Requirements When creating a mock plugin (e.g., `public/e2e-fixtures/my-mock-plugin.js`) to test a specific UI feature, **you MUST implement the full Data Plugin interface**. WorldWideView's `PluginManager` throws fatal runtime errors if a plugin is missing core data fetching methods, even if your plugin only tests a UI component like a bottom panel. **Required Methods for EVERY Mock Plugin:** ```javascript export default { id: "my-mock-plugin", name: "My Mock Plugin", // ... // MUST BE INCLUDED: fetch: async (timeRange) => { return []; }, getPollingInterval: () => { return 60000; }, getLayerConfig: () => { return { color: "#FFF", clusterEnabled: false, clusterDistance: 50 }; }, renderEntity: (entity) => { return { type: "point", color: "#FFF", size: 5 }; }, // Your UI testing component (e.g., Sidebar, Bottom Panel) getBottomPanelComponent: () => { ... } } ``` ## 2. Mock Plugin Manifest Capabilities If your mock plugin needs to be toggled by the user in the Layers list, you MUST include the `"ui:sidebar"` capability in its `manifest.json`. ```json { "capabilities": ["ui:bottom-panel", "ui:sidebar"], "extends": ["sidebar"] } ``` ## 3. Database Injection The frontend reads plugins from the database. You MUST inject your mock plugin during `tests/global.setup.ts` using Prisma: ```typescript const manifestPath = path.join(process.cwd(), 'public', 'e2e-fixtures', 'my-mock-plugin-manifest.json'); const manifestStr = fs.readFileSync(manifestPath, 'utf-8'); await prisma.installedPlugin.create({ data: { pluginId: 'my-mock-plugin', version: '1.0.0', config: manifestStr, enabled: true } }); ``` Make sure to add your new mock plugin ID to the cleanup logic in `global.setup.ts` as well: ```typescript await prisma.installedPlugin.deleteMany({ where: { pluginId: { in: ['e2e-mock-plugin', 'my-mock-plugin'] } } }); ``` ## 4. UI Selectors **DO NOT use CSS classes for your locators.** CSS classes change frequently (e.g., `.dock-btn`, `.layer-item__toggle`). You MUST either: 1. Add explicit `data-testid` attributes to the React components you are testing. 2. Use stable accessibility locators (e.g., `getByRole('button', { name: /Text/ })`). ## 5. Execution Environment - Ensure `pnpm run dev:backends` is running before you execute tests locally. - Run tests using `pnpm run test:e2e` or `npx playwright test tests/your-test.spec.ts`. - **PowerShell Warning**: Remember you are running in Windows PowerShell. Do NOT chain commands with `&&`. Use `;` instead.
在 GitHub 查看