openspec-playwright 0.3.6 → 0.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -32,10 +32,64 @@ Two modes, same pipeline:
32
32
  | Change | `/opsx:e2e <name>` | OpenSpec specs | `changes/<name>/<name>.spec.ts` |
33
33
  | All | `/opsx:e2e all` | sitemap + homepage crawl | `pages/*.ts` (Page Objects) |
34
34
 
35
- Both modes update `app-knowledge.md` and `app-exploration.md`. All `.spec.ts` files run together as regression suite.
35
+ Both modes update `app-knowledge.md` and `app-exploration.md`. Spec files are independent per change — `openspec-pw run <name>` runs only `changes/<name>/<name>.spec.ts`.
36
+
37
+ > **⚠️ Full regression is opt-in only.** Default: `openspec-pw run <name>` → one spec file. Do NOT run `npx playwright test` (no file), `--only-changed`, or any command that executes multiple `.spec.ts` files unless the user explicitly requests it. This includes running the same command twice across different changes to simulate regression.
36
38
 
37
39
  > **Role mapping**: Planner (Step 4–5) → test-plan.md; Generator (Step 6) → `.spec.ts` + Page Objects; Healer (Step 9) → repairs failures via MCP.
38
40
 
41
+ ## Setup / Teardown
42
+
43
+ Playwright supports two approaches for global lifecycle hooks. **openspec-playwright uses project dependencies** (the recommended approach) for full feature support.
44
+
45
+ ### Comparison
46
+
47
+ | Feature | Project Dependencies | globalSetup/globalTeardown |
48
+ |---------|---------------------|---------------------------|
49
+ | HTML report visibility | ✅ Shown as project | ❌ Not shown |
50
+ | Trace recording | ✅ Full support | ❌ Not supported |
51
+ | Playwright fixtures | ✅ Fully supported | ❌ Not supported |
52
+ | Browser via fixture | ✅ Automatic | ❌ Manual launch |
53
+
54
+ ### Current Implementation
55
+
56
+ **Setup project** (enabled by default):
57
+ - `tests/playwright/auth.setup.ts` — authenticates once, saves session to `./playwright/.auth/user.json`
58
+ - All test projects depend on setup via `dependencies: ['setup']`
59
+
60
+ **Teardown project** (optional, disabled by default):
61
+ - `tests/playwright/global.teardown.ts` — runs AFTER all tests complete
62
+ - Use for: database cleanup, uploaded file removal, cache invalidation
63
+ - Enable by uncommenting in `playwright.config.ts`
64
+
65
+ ### When to Enable Teardown
66
+
67
+ Enable teardown when your tests create persistent data that should be cleaned up:
68
+
69
+ | Scenario | Action |
70
+ |----------|--------|
71
+ | Tests create database records | ✅ Enable teardown, add DB cleanup |
72
+ | Tests upload files | ✅ Enable teardown, add file cleanup |
73
+ | Tests only read data | ❌ No teardown needed |
74
+ | Tests use ephemeral/isolated environments | ❌ No teardown needed |
75
+
76
+ ### Enabling Teardown
77
+
78
+ 1. Copy template: `cp templates/global.teardown.ts tests/playwright/global.teardown.ts`
79
+ 2. Customize cleanup logic in the file
80
+ 3. Uncomment in `playwright.config.ts`:
81
+ ```typescript
82
+ projects: [
83
+ { name: 'setup', testMatch: /.*\.setup\.ts/ },
84
+ { name: 'teardown', testMatch: /global\.teardown\.ts/ }, // Uncomment
85
+ {
86
+ name: 'chromium',
87
+ // ...
88
+ teardown: 'teardown', // Uncomment
89
+ },
90
+ ],
91
+ ```
92
+
39
93
  ## Testing principles
40
94
 
41
95
  **UI first** — Test every user flow through the browser UI. E2E validates that users can accomplish tasks in the real interface, not just that the backend responds correctly.
package/README.md CHANGED
@@ -149,7 +149,7 @@ Edit `tests/playwright/credentials.yaml`:
149
149
 
150
150
  ```
151
151
  Templates (in npm package, installed to .claude/skills/openspec-e2e/templates/)
152
- └── test-plan.md, report.md, playwright.config.ts, e2e-test.ts, app-exploration.md
152
+ └── test-plan.md, report.md, playwright.config.ts, e2e-test.ts, global.teardown.ts, app-exploration.md
153
153
 
154
154
  CLI (openspec-pw)
155
155
  ├── init → Installs commands, skill & templates to .claude/
@@ -166,10 +166,11 @@ Claude Code (/opsx:e2e)
166
166
  └── @playwright/mcp → Healer Agent tools
167
167
 
168
168
  Test Assets (tests/playwright/)
169
- ├── seed.spec.ts → Env validation
170
- ├── auth.setup.ts → Session recording
171
- ├── credentials.yamlTest users
172
- └── app-knowledge.md Project-level selector patterns (cross-change)
169
+ ├── seed.spec.ts → Env validation
170
+ ├── auth.setup.ts → Session recording
171
+ ├── global.teardown.tsPost-test cleanup (optional)
172
+ ├── credentials.yaml Test users
173
+ └── app-knowledge.md → Project-level selector patterns (cross-change)
173
174
 
174
175
  Exploration (openspec/changes/<name>/specs/playwright/)
175
176
  ├── app-exploration.md → This change's routes + verified selectors
@@ -51,7 +51,7 @@ E2E 工作流前提(由用户确保,非 AI 操作):
51
51
  ```
52
52
  1. 探索与提案
53
53
  2. 产品与架构评审(按需触发)
54
- 3. 设计审查
54
+ 3. 设计审查 → /plan-design-review + /frontend-design
55
55
  4. 实现 → /opsx:apply
56
56
  5. 自审 → /opsx:verify
57
57
  6. E2E 测试 → /opsx:e2e <change-name> → /browse 探索 + /qa 验证
@@ -68,6 +68,7 @@ E2E 工作流前提(由用户确保,非 AI 操作):
68
68
  - `/plan-eng-review`:架构影响(新增服务、API 契约变更、数据模型重构)时
69
69
 
70
70
  **3. 设计审查**:在实现前进行设计评审,确保方案合理。评审通过后开始实现。
71
+ - `/plan-design-review`:UI/UX 方案审查,评分各设计维度,确保用户体验达标
71
72
 
72
73
  **4. 实现**:执行 `/opsx:apply` 进行实现 → `lint + typecheck` 通过才算成功。
73
74
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openspec-playwright",
3
- "version": "0.3.6",
3
+ "version": "0.3.7",
4
4
  "description": "OpenSpec + Playwright E2E verification setup tool for Claude Code",
5
5
  "type": "module",
6
6
  "bin": {
@@ -0,0 +1,74 @@
1
+ // Global Teardown for Playwright Test Agents
2
+ // This file runs AFTER all tests complete — use it to clean up test data.
3
+ //
4
+ // Setup:
5
+ // 1. Uncomment the teardown project in playwright.config.ts
6
+ // 2. Customize the cleanup logic below for your project
7
+ // 3. Run: npx playwright test (teardown runs automatically after all tests)
8
+ //
9
+ // Common use cases:
10
+ // - Database cleanup: DELETE test records created during E2E runs
11
+ // - API cleanup: Call /api/test/cleanup endpoint
12
+ // - File cleanup: Remove uploaded test files or artifacts
13
+ // - Cache invalidation: Clear Redis/Memcached test keys
14
+
15
+ import { test as teardown } from '@playwright/test';
16
+
17
+ teardown('cleanup test data', async ({ request }) => {
18
+ const baseUrl = process.env.BASE_URL || 'http://localhost:3000';
19
+
20
+ // ─── Option 1: API-based cleanup (recommended) ───────────────────────────
21
+ // If your app has a test cleanup endpoint, call it here.
22
+ // Example: POST /api/test/cleanup with a secret token
23
+ //
24
+ // const cleanupToken = process.env.E2E_CLEANUP_TOKEN;
25
+ // if (cleanupToken) {
26
+ // const res = await request.post(`${baseUrl}/api/test/cleanup`, {
27
+ // headers: { 'X-Cleanup-Token': cleanupToken },
28
+ // });
29
+ // if (!res.ok()) {
30
+ // console.warn(`Cleanup API returned ${res.status()}`);
31
+ // }
32
+ // }
33
+
34
+ // ─── Option 2: Database cleanup (direct connection) ──────────────────────
35
+ // If you have direct DB access, clean up test records.
36
+ // Example using pg (PostgreSQL):
37
+ //
38
+ // import { Pool } from 'pg';
39
+ // const pool = new Pool({ connectionString: process.env.DATABASE_URL });
40
+ // await pool.query(`
41
+ // DELETE FROM orders WHERE email LIKE '%@test.example.com';
42
+ // DELETE FROM users WHERE email LIKE '%@test.example.com';
43
+ // `);
44
+ // await pool.end();
45
+
46
+ // ─── Option 3: File cleanup ──────────────────────────────────────────────
47
+ // Remove test-generated files or uploads.
48
+ //
49
+ // import { rm } from 'fs/promises';
50
+ // await rm('./uploads/test-*', { recursive: true, force: true });
51
+
52
+ // ─── Option 4: Session/cache cleanup ─────────────────────────────────────
53
+ // Invalidate test sessions or cache entries.
54
+ //
55
+ // import Redis from 'ioredis';
56
+ // const redis = new Redis(process.env.REDIS_URL);
57
+ // const keys = await redis.keys('session:test-*');
58
+ // if (keys.length) await redis.del(...keys);
59
+ // await redis.quit();
60
+
61
+ console.log('✓ Global teardown completed');
62
+ });
63
+
64
+ // ─── Additional teardown tasks (optional) ──────────────────────────────────
65
+ // Add more teardown blocks if you need to clean up different resources
66
+ // in a specific order.
67
+
68
+ // teardown('cleanup uploaded files', async ({ }) => {
69
+ // // File cleanup logic
70
+ // });
71
+
72
+ // teardown('invalidate cache', async ({ }) => {
73
+ // // Cache cleanup logic
74
+ // });
@@ -90,9 +90,11 @@ export default defineConfig({
90
90
  reuseExistingServer: true,
91
91
  },
92
92
 
93
- // Setup project for authentication (configured by openspec-pw run)
93
+ // Setup project (configured by openspec-pw run)
94
+ // Teardown project (optional): uncomment the two lines below + create tests/playwright/global.teardown.ts
94
95
  projects: [
95
96
  { name: 'setup', testMatch: /.*\.setup\.ts/ },
97
+ // { name: 'teardown', testMatch: /global\.teardown\.ts/ }, // Uncomment + create file
96
98
  {
97
99
  name: 'chromium',
98
100
  use: {
@@ -100,6 +102,7 @@ export default defineConfig({
100
102
  storageState: './playwright/.auth/user.json',
101
103
  },
102
104
  dependencies: ['setup'],
105
+ // teardown: 'teardown', // Uncomment when teardown project is enabled
103
106
  },
104
107
  ],
105
108
  });