@zimezone/z-command 1.1.1 → 1.1.4

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.
Files changed (288) hide show
  1. package/README.md +13 -1
  2. package/dist/cli.js +1 -1
  3. package/dist/commands/init.d.ts.map +1 -1
  4. package/dist/commands/init.js +42 -10
  5. package/dist/commands/init.js.map +1 -1
  6. package/dist/platforms.d.ts.map +1 -1
  7. package/dist/platforms.js +11 -1
  8. package/dist/platforms.js.map +1 -1
  9. package/dist/types.d.ts +2 -0
  10. package/dist/types.d.ts.map +1 -1
  11. package/package.json +8 -3
  12. package/templates.zip +0 -0
  13. package/templates/agents/accessibility-expert.agent.md +0 -56
  14. package/templates/agents/ai-engineer.agent.md +0 -61
  15. package/templates/agents/angular-architect.agent.md +0 -49
  16. package/templates/agents/api-designer.agent.md +0 -40
  17. package/templates/agents/api-documenter.agent.md +0 -161
  18. package/templates/agents/architect-review.agent.md +0 -146
  19. package/templates/agents/arm-cortex-expert.agent.md +0 -288
  20. package/templates/agents/azure-infra-engineer.agent.md +0 -57
  21. package/templates/agents/backend-architect.agent.md +0 -309
  22. package/templates/agents/backend-developer.agent.md +0 -61
  23. package/templates/agents/backend-security-coder.agent.md +0 -152
  24. package/templates/agents/bash-pro.agent.md +0 -285
  25. package/templates/agents/blockchain-developer.agent.md +0 -57
  26. package/templates/agents/build-engineer.agent.md +0 -56
  27. package/templates/agents/business-analyst.agent.md +0 -47
  28. package/templates/agents/c-pro.agent.md +0 -35
  29. package/templates/agents/c4-code.agent.md +0 -320
  30. package/templates/agents/c4-component.agent.md +0 -227
  31. package/templates/agents/c4-container.agent.md +0 -248
  32. package/templates/agents/c4-context.agent.md +0 -235
  33. package/templates/agents/cli-developer.agent.md +0 -57
  34. package/templates/agents/cloud-architect.agent.md +0 -56
  35. package/templates/agents/code-architect.agent.md +0 -63
  36. package/templates/agents/code-reviewer.agent.md +0 -49
  37. package/templates/agents/competitive-analyst.agent.md +0 -48
  38. package/templates/agents/conductor-validator.agent.md +0 -245
  39. package/templates/agents/context-manager.agent.md +0 -55
  40. package/templates/agents/cpp-pro.agent.md +0 -59
  41. package/templates/agents/csharp-developer.agent.md +0 -57
  42. package/templates/agents/csharp-pro.agent.md +0 -38
  43. package/templates/agents/customer-support.agent.md +0 -148
  44. package/templates/agents/data-engineer.agent.md +0 -55
  45. package/templates/agents/data-researcher.agent.md +0 -55
  46. package/templates/agents/data-scientist.agent.md +0 -56
  47. package/templates/agents/database-admin.agent.md +0 -142
  48. package/templates/agents/database-administrator.agent.md +0 -50
  49. package/templates/agents/database-architect.agent.md +0 -238
  50. package/templates/agents/database-optimizer.agent.md +0 -144
  51. package/templates/agents/debugger.agent.md +0 -30
  52. package/templates/agents/deployment-engineer.agent.md +0 -0
  53. package/templates/agents/devops-engineer.agent.md +0 -59
  54. package/templates/agents/devops-troubleshooter.agent.md +0 -138
  55. package/templates/agents/django-developer.agent.md +0 -50
  56. package/templates/agents/django-pro.agent.md +0 -159
  57. package/templates/agents/docs-architect.agent.md +0 -77
  58. package/templates/agents/documentation-engineer.agent.md +0 -57
  59. package/templates/agents/dotnet-architect.agent.md +0 -175
  60. package/templates/agents/dx-optimizer.agent.md +0 -63
  61. package/templates/agents/electron-pro.agent.md +0 -56
  62. package/templates/agents/elixir-pro.agent.md +0 -38
  63. package/templates/agents/embedded-systems.agent.md +0 -55
  64. package/templates/agents/error-detective.agent.md +0 -32
  65. package/templates/agents/event-sourcing-architect.agent.md +0 -42
  66. package/templates/agents/fastapi-pro.agent.md +0 -171
  67. package/templates/agents/fintech-engineer.agent.md +0 -57
  68. package/templates/agents/firmware-analyst.agent.md +0 -330
  69. package/templates/agents/flutter-expert.agent.md +0 -50
  70. package/templates/agents/frontend-developer.agent.md +0 -59
  71. package/templates/agents/frontend-security-coder.agent.md +0 -149
  72. package/templates/agents/fullstack-developer.agent.md +0 -46
  73. package/templates/agents/git-workflow-manager.agent.md +0 -57
  74. package/templates/agents/golang-pro.agent.md +0 -50
  75. package/templates/agents/graphql-architect.agent.md +0 -48
  76. package/templates/agents/haskell-pro.agent.md +0 -37
  77. package/templates/agents/hr-pro.agent.md +0 -105
  78. package/templates/agents/incident-responder.agent.md +0 -190
  79. package/templates/agents/ios-developer.agent.md +0 -198
  80. package/templates/agents/iot-engineer.agent.md +0 -56
  81. package/templates/agents/java-architect.agent.md +0 -48
  82. package/templates/agents/java-pro.agent.md +0 -156
  83. package/templates/agents/javascript-pro.agent.md +0 -35
  84. package/templates/agents/julia-pro.agent.md +0 -187
  85. package/templates/agents/kotlin-specialist.agent.md +0 -50
  86. package/templates/agents/laravel-specialist.agent.md +0 -50
  87. package/templates/agents/legacy-modernizer.agent.md +0 -56
  88. package/templates/agents/legal-advisor.agent.md +0 -49
  89. package/templates/agents/llm-architect.agent.md +0 -58
  90. package/templates/agents/malware-analyst.agent.md +0 -272
  91. package/templates/agents/mcp-developer.agent.md +0 -54
  92. package/templates/agents/mermaid-expert.agent.md +0 -39
  93. package/templates/agents/microservices-architect.agent.md +0 -47
  94. package/templates/agents/minecraft-bukkit-pro.agent.md +0 -104
  95. package/templates/agents/ml-engineer.agent.md +0 -56
  96. package/templates/agents/mlops-engineer.agent.md +0 -56
  97. package/templates/agents/mobile-developer.agent.md +0 -45
  98. package/templates/agents/mobile-security-coder.agent.md +0 -163
  99. package/templates/agents/monorepo-architect.agent.md +0 -44
  100. package/templates/agents/multi-agent-coordinator.agent.md +0 -55
  101. package/templates/agents/network-engineer.agent.md +0 -57
  102. package/templates/agents/nextjs-developer.agent.md +0 -48
  103. package/templates/agents/nlp-engineer.agent.md +0 -58
  104. package/templates/agents/observability-engineer.agent.md +0 -228
  105. package/templates/agents/payment-integration.agent.md +0 -56
  106. package/templates/agents/performance-engineer.agent.md +0 -167
  107. package/templates/agents/performance-optimizer.agent.md +0 -57
  108. package/templates/agents/php-pro.agent.md +0 -43
  109. package/templates/agents/platform-engineer.agent.md +0 -57
  110. package/templates/agents/posix-shell-pro.agent.md +0 -284
  111. package/templates/agents/postgres-pro.agent.md +0 -58
  112. package/templates/agents/product-manager.agent.md +0 -55
  113. package/templates/agents/project-manager.agent.md +0 -57
  114. package/templates/agents/prompt-engineer.agent.md +0 -58
  115. package/templates/agents/python-pro.agent.md +0 -48
  116. package/templates/agents/quant-analyst.agent.md +0 -32
  117. package/templates/agents/rails-expert.agent.md +0 -50
  118. package/templates/agents/react-specialist.agent.md +0 -49
  119. package/templates/agents/refactoring-specialist.agent.md +0 -56
  120. package/templates/agents/reference-builder.agent.md +0 -167
  121. package/templates/agents/research-analyst.agent.md +0 -63
  122. package/templates/agents/reverse-engineer.agent.md +0 -202
  123. package/templates/agents/risk-manager.agent.md +0 -41
  124. package/templates/agents/ruby-pro.agent.md +0 -35
  125. package/templates/agents/rust-pro.agent.md +0 -156
  126. package/templates/agents/sales-automator.agent.md +0 -35
  127. package/templates/agents/scala-pro.agent.md +0 -60
  128. package/templates/agents/scrum-master.agent.md +0 -54
  129. package/templates/agents/search-specialist.agent.md +0 -59
  130. package/templates/agents/security-analyst.agent.md +0 -57
  131. package/templates/agents/security-auditor.agent.md +0 -138
  132. package/templates/agents/security-engineer.agent.md +0 -57
  133. package/templates/agents/seo-authority-builder.agent.md +0 -116
  134. package/templates/agents/seo-cannibalization-detector.agent.md +0 -103
  135. package/templates/agents/seo-content-auditor.agent.md +0 -63
  136. package/templates/agents/seo-content-planner.agent.md +0 -88
  137. package/templates/agents/seo-content-refresher.agent.md +0 -98
  138. package/templates/agents/seo-content-writer.agent.md +0 -76
  139. package/templates/agents/seo-keyword-strategist.agent.md +0 -75
  140. package/templates/agents/seo-meta-optimizer.agent.md +0 -72
  141. package/templates/agents/seo-snippet-hunter.agent.md +0 -94
  142. package/templates/agents/seo-specialist.agent.md +0 -57
  143. package/templates/agents/seo-structure-architect.agent.md +0 -88
  144. package/templates/agents/service-mesh-expert.agent.md +0 -41
  145. package/templates/agents/sql-pro.agent.md +0 -146
  146. package/templates/agents/sre-engineer.agent.md +0 -58
  147. package/templates/agents/swift-expert.agent.md +0 -49
  148. package/templates/agents/task-distributor.agent.md +0 -47
  149. package/templates/agents/tdd-orchestrator.agent.md +0 -183
  150. package/templates/agents/technical-writer.agent.md +0 -48
  151. package/templates/agents/temporal-python-pro.agent.md +0 -349
  152. package/templates/agents/terraform-engineer.agent.md +0 -57
  153. package/templates/agents/terraform-specialist.agent.md +0 -137
  154. package/templates/agents/test-automator.agent.md +0 -203
  155. package/templates/agents/test-engineer.agent.md +0 -55
  156. package/templates/agents/threat-modeling-expert.agent.md +0 -44
  157. package/templates/agents/trend-analyst.agent.md +0 -47
  158. package/templates/agents/tutorial-engineer.agent.md +0 -118
  159. package/templates/agents/typescript-pro.agent.md +0 -48
  160. package/templates/agents/ui-designer.agent.md +0 -48
  161. package/templates/agents/ui-ux-designer.agent.md +0 -188
  162. package/templates/agents/ui-visual-validator.agent.md +0 -192
  163. package/templates/agents/ux-researcher.agent.md +0 -48
  164. package/templates/agents/vector-database-engineer.agent.md +0 -43
  165. package/templates/agents/vue-expert.agent.md +0 -48
  166. package/templates/agents/websocket-engineer.agent.md +0 -49
  167. package/templates/agents/workflow-orchestrator.agent.md +0 -48
  168. package/templates/skills/angular-migration/SKILL.md +0 -410
  169. package/templates/skills/api-design-principles/SKILL.md +0 -528
  170. package/templates/skills/api-design-principles/assets/api-design-checklist.md +0 -155
  171. package/templates/skills/api-design-principles/assets/rest-api-template.py +0 -182
  172. package/templates/skills/api-design-principles/references/graphql-schema-design.md +0 -583
  173. package/templates/skills/api-design-principles/references/rest-best-practices.md +0 -408
  174. package/templates/skills/architecture-decision-records/SKILL.md +0 -428
  175. package/templates/skills/architecture-patterns/SKILL.md +0 -494
  176. package/templates/skills/async-python-patterns/SKILL.md +0 -694
  177. package/templates/skills/auth-implementation-patterns/SKILL.md +0 -634
  178. package/templates/skills/changelog-automation/SKILL.md +0 -552
  179. package/templates/skills/code-review/SKILL.md +0 -62
  180. package/templates/skills/code-review-excellence/SKILL.md +0 -520
  181. package/templates/skills/competitive-landscape/SKILL.md +0 -479
  182. package/templates/skills/context-driven-development/SKILL.md +0 -385
  183. package/templates/skills/cost-optimization/SKILL.md +0 -274
  184. package/templates/skills/cqrs-implementation/SKILL.md +0 -554
  185. package/templates/skills/data-quality-frameworks/SKILL.md +0 -587
  186. package/templates/skills/data-storytelling/SKILL.md +0 -453
  187. package/templates/skills/database-migration/SKILL.md +0 -424
  188. package/templates/skills/dbt-transformation-patterns/SKILL.md +0 -561
  189. package/templates/skills/debugging-strategies/SKILL.md +0 -527
  190. package/templates/skills/defi-protocol-templates/SKILL.md +0 -454
  191. package/templates/skills/dependency-upgrade/SKILL.md +0 -409
  192. package/templates/skills/deployment-pipeline-design/SKILL.md +0 -359
  193. package/templates/skills/distributed-tracing/SKILL.md +0 -438
  194. package/templates/skills/dotnet-backend-patterns/SKILL.md +0 -815
  195. package/templates/skills/dotnet-backend-patterns/assets/repository-template.cs +0 -523
  196. package/templates/skills/dotnet-backend-patterns/assets/service-template.cs +0 -336
  197. package/templates/skills/dotnet-backend-patterns/references/dapper-patterns.md +0 -544
  198. package/templates/skills/dotnet-backend-patterns/references/ef-core-best-practices.md +0 -355
  199. package/templates/skills/e2e-testing-patterns/SKILL.md +0 -547
  200. package/templates/skills/employment-contract-templates/SKILL.md +0 -507
  201. package/templates/skills/error-handling-patterns/SKILL.md +0 -636
  202. package/templates/skills/event-store-design/SKILL.md +0 -437
  203. package/templates/skills/fastapi-templates/SKILL.md +0 -567
  204. package/templates/skills/git-advanced-workflows/SKILL.md +0 -400
  205. package/templates/skills/github-actions-templates/SKILL.md +0 -333
  206. package/templates/skills/go-concurrency-patterns/SKILL.md +0 -655
  207. package/templates/skills/grafana-dashboards/SKILL.md +0 -369
  208. package/templates/skills/helm-chart-scaffolding/SKILL.md +0 -544
  209. package/templates/skills/helm-chart-scaffolding/assets/Chart.yaml.template +0 -42
  210. package/templates/skills/helm-chart-scaffolding/assets/values.yaml.template +0 -185
  211. package/templates/skills/helm-chart-scaffolding/references/chart-structure.md +0 -500
  212. package/templates/skills/helm-chart-scaffolding/scripts/validate-chart.sh +0 -244
  213. package/templates/skills/javascript-testing-patterns/SKILL.md +0 -1025
  214. package/templates/skills/langchain-architecture/SKILL.md +0 -338
  215. package/templates/skills/llm-evaluation/SKILL.md +0 -471
  216. package/templates/skills/microservices-patterns/SKILL.md +0 -595
  217. package/templates/skills/modern-javascript-patterns/SKILL.md +0 -911
  218. package/templates/skills/monorepo-management/SKILL.md +0 -622
  219. package/templates/skills/nextjs-app-router-patterns/SKILL.md +0 -544
  220. package/templates/skills/nodejs-backend-patterns/SKILL.md +0 -1020
  221. package/templates/skills/nx-workspace-patterns/SKILL.md +0 -452
  222. package/templates/skills/openapi-spec-generation/SKILL.md +0 -1028
  223. package/templates/skills/paypal-integration/SKILL.md +0 -467
  224. package/templates/skills/pci-compliance/SKILL.md +0 -466
  225. package/templates/skills/postgresql/SKILL.md +0 -204
  226. package/templates/skills/projection-patterns/SKILL.md +0 -490
  227. package/templates/skills/prometheus-configuration/SKILL.md +0 -392
  228. package/templates/skills/prompt-engineering-patterns/SKILL.md +0 -201
  229. package/templates/skills/prompt-engineering-patterns/assets/few-shot-examples.json +0 -106
  230. package/templates/skills/prompt-engineering-patterns/assets/prompt-template-library.md +0 -246
  231. package/templates/skills/prompt-engineering-patterns/references/chain-of-thought.md +0 -399
  232. package/templates/skills/prompt-engineering-patterns/references/few-shot-learning.md +0 -369
  233. package/templates/skills/prompt-engineering-patterns/references/prompt-optimization.md +0 -414
  234. package/templates/skills/prompt-engineering-patterns/references/prompt-templates.md +0 -470
  235. package/templates/skills/prompt-engineering-patterns/references/system-prompts.md +0 -189
  236. package/templates/skills/prompt-engineering-patterns/scripts/optimize-prompt.py +0 -279
  237. package/templates/skills/python-packaging/SKILL.md +0 -870
  238. package/templates/skills/python-performance-optimization/SKILL.md +0 -869
  239. package/templates/skills/python-testing-patterns/SKILL.md +0 -907
  240. package/templates/skills/rag-implementation/SKILL.md +0 -403
  241. package/templates/skills/react-modernization/SKILL.md +0 -513
  242. package/templates/skills/react-native-architecture/SKILL.md +0 -671
  243. package/templates/skills/react-state-management/SKILL.md +0 -429
  244. package/templates/skills/risk-metrics-calculation/SKILL.md +0 -555
  245. package/templates/skills/rust-async-patterns/SKILL.md +0 -517
  246. package/templates/skills/secrets-management/SKILL.md +0 -346
  247. package/templates/skills/security-requirement-extraction/SKILL.md +0 -677
  248. package/templates/skills/security-review/SKILL.md +0 -78
  249. package/templates/skills/shellcheck-configuration/SKILL.md +0 -454
  250. package/templates/skills/similarity-search-patterns/SKILL.md +0 -558
  251. package/templates/skills/slo-implementation/SKILL.md +0 -329
  252. package/templates/skills/sql-optimization-patterns/SKILL.md +0 -493
  253. package/templates/skills/stripe-integration/SKILL.md +0 -442
  254. package/templates/skills/systematic-debugging/SKILL.md +0 -57
  255. package/templates/skills/tailwind-design-system/SKILL.md +0 -666
  256. package/templates/skills/temporal-python-testing/SKILL.md +0 -158
  257. package/templates/skills/temporal-python-testing/resources/integration-testing.md +0 -455
  258. package/templates/skills/temporal-python-testing/resources/local-setup.md +0 -553
  259. package/templates/skills/temporal-python-testing/resources/replay-testing.md +0 -462
  260. package/templates/skills/temporal-python-testing/resources/unit-testing.md +0 -328
  261. package/templates/skills/terraform-module-library/SKILL.md +0 -249
  262. package/templates/skills/terraform-module-library/references/aws-modules.md +0 -63
  263. package/templates/skills/test-driven-development/SKILL.md +0 -46
  264. package/templates/skills/threat-mitigation-mapping/SKILL.md +0 -745
  265. package/templates/skills/track-management/SKILL.md +0 -593
  266. package/templates/skills/typescript-advanced-types/SKILL.md +0 -717
  267. package/templates/skills/ui-ux-pro-max/SKILL.md +0 -352
  268. package/templates/skills/ui-ux-pro-max/data/charts.csv +0 -26
  269. package/templates/skills/ui-ux-pro-max/data/colors.csv +0 -97
  270. package/templates/skills/ui-ux-pro-max/data/icons.csv +0 -101
  271. package/templates/skills/ui-ux-pro-max/data/landing.csv +0 -31
  272. package/templates/skills/ui-ux-pro-max/data/products.csv +0 -97
  273. package/templates/skills/ui-ux-pro-max/data/prompts.csv +0 -24
  274. package/templates/skills/ui-ux-pro-max/data/react-performance.csv +0 -45
  275. package/templates/skills/ui-ux-pro-max/data/styles.csv +0 -59
  276. package/templates/skills/ui-ux-pro-max/data/typography.csv +0 -58
  277. package/templates/skills/ui-ux-pro-max/data/ui-reasoning.csv +0 -101
  278. package/templates/skills/ui-ux-pro-max/data/ux-guidelines.csv +0 -100
  279. package/templates/skills/ui-ux-pro-max/data/web-interface.csv +0 -31
  280. package/templates/skills/ui-ux-pro-max/scripts/core.py +0 -258
  281. package/templates/skills/ui-ux-pro-max/scripts/design_system.py +0 -547
  282. package/templates/skills/ui-ux-pro-max/scripts/search.py +0 -76
  283. package/templates/skills/uv-package-manager/SKILL.md +0 -831
  284. package/templates/skills/vector-index-tuning/SKILL.md +0 -521
  285. package/templates/skills/wcag-audit-patterns/SKILL.md +0 -555
  286. package/templates/skills/workflow-orchestration-patterns/SKILL.md +0 -316
  287. package/templates/skills/workflow-patterns/SKILL.md +0 -623
  288. package/templates/skills/writing-plans/SKILL.md +0 -64
@@ -1,547 +0,0 @@
1
- ---
2
- name: e2e-testing-patterns
3
- description: Master end-to-end testing with Playwright and Cypress to build reliable test suites that catch bugs, improve confidence, and enable fast deployment. Use when implementing E2E tests, debugging flaky tests, or establishing testing standards.
4
- ---
5
-
6
- # E2E Testing Patterns
7
-
8
- Build reliable, fast, and maintainable end-to-end test suites that provide confidence to ship code quickly and catch regressions before users do.
9
-
10
- ## When to Use This Skill
11
-
12
- - Implementing end-to-end test automation
13
- - Debugging flaky or unreliable tests
14
- - Testing critical user workflows
15
- - Setting up CI/CD test pipelines
16
- - Testing across multiple browsers
17
- - Validating accessibility requirements
18
- - Testing responsive designs
19
- - Establishing E2E testing standards
20
-
21
- ## Core Concepts
22
-
23
- ### 1. E2E Testing Fundamentals
24
-
25
- **What to Test with E2E:**
26
- - Critical user journeys (login, checkout, signup)
27
- - Complex interactions (drag-and-drop, multi-step forms)
28
- - Cross-browser compatibility
29
- - Real API integration
30
- - Authentication flows
31
-
32
- **What NOT to Test with E2E:**
33
- - Unit-level logic (use unit tests)
34
- - API contracts (use integration tests)
35
- - Edge cases (too slow)
36
- - Internal implementation details
37
-
38
- ### 2. Test Philosophy
39
-
40
- **The Testing Pyramid:**
41
- ```
42
- /\
43
- /E2E\ ← Few, focused on critical paths
44
- /─────\
45
- /Integr\ ← More, test component interactions
46
- /────────\
47
- /Unit Tests\ ← Many, fast, isolated
48
- /────────────\
49
- ```
50
-
51
- **Best Practices:**
52
- - Test user behavior, not implementation
53
- - Keep tests independent
54
- - Make tests deterministic
55
- - Optimize for speed
56
- - Use data-testid, not CSS selectors
57
-
58
- ## Playwright Patterns
59
-
60
- ### Setup and Configuration
61
-
62
- ```typescript
63
- // playwright.config.ts
64
- import { defineConfig, devices } from '@playwright/test';
65
-
66
- export default defineConfig({
67
- testDir: './e2e',
68
- timeout: 30000,
69
- expect: {
70
- timeout: 5000,
71
- },
72
- fullyParallel: true,
73
- forbidOnly: !!process.env.CI,
74
- retries: process.env.CI ? 2 : 0,
75
- workers: process.env.CI ? 1 : undefined,
76
- reporter: [
77
- ['html'],
78
- ['junit', { outputFile: 'results.xml' }],
79
- ],
80
- use: {
81
- baseURL: 'http://localhost:3000',
82
- trace: 'on-first-retry',
83
- screenshot: 'only-on-failure',
84
- video: 'retain-on-failure',
85
- },
86
- projects: [
87
- { name: 'chromium', use: { ...devices['Desktop Chrome'] } },
88
- { name: 'firefox', use: { ...devices['Desktop Firefox'] } },
89
- { name: 'webkit', use: { ...devices['Desktop Safari'] } },
90
- { name: 'mobile', use: { ...devices['iPhone 13'] } },
91
- ],
92
- });
93
- ```
94
-
95
- ### Pattern 1: Page Object Model
96
-
97
- ```typescript
98
- // pages/LoginPage.ts
99
- import { Page, Locator } from '@playwright/test';
100
-
101
- export class LoginPage {
102
- readonly page: Page;
103
- readonly emailInput: Locator;
104
- readonly passwordInput: Locator;
105
- readonly loginButton: Locator;
106
- readonly errorMessage: Locator;
107
-
108
- constructor(page: Page) {
109
- this.page = page;
110
- this.emailInput = page.getByLabel('Email');
111
- this.passwordInput = page.getByLabel('Password');
112
- this.loginButton = page.getByRole('button', { name: 'Login' });
113
- this.errorMessage = page.getByRole('alert');
114
- }
115
-
116
- async goto() {
117
- await this.page.goto('/login');
118
- }
119
-
120
- async login(email: string, password: string) {
121
- await this.emailInput.fill(email);
122
- await this.passwordInput.fill(password);
123
- await this.loginButton.click();
124
- }
125
-
126
- async getErrorMessage(): Promise<string> {
127
- return await this.errorMessage.textContent() ?? '';
128
- }
129
- }
130
-
131
- // Test using Page Object
132
- import { test, expect } from '@playwright/test';
133
- import { LoginPage } from './pages/LoginPage';
134
-
135
- test('successful login', async ({ page }) => {
136
- const loginPage = new LoginPage(page);
137
- await loginPage.goto();
138
- await loginPage.login('user@example.com', 'password123');
139
-
140
- await expect(page).toHaveURL('/dashboard');
141
- await expect(page.getByRole('heading', { name: 'Dashboard' }))
142
- .toBeVisible();
143
- });
144
-
145
- test('failed login shows error', async ({ page }) => {
146
- const loginPage = new LoginPage(page);
147
- await loginPage.goto();
148
- await loginPage.login('invalid@example.com', 'wrong');
149
-
150
- const error = await loginPage.getErrorMessage();
151
- expect(error).toContain('Invalid credentials');
152
- });
153
- ```
154
-
155
- ### Pattern 2: Fixtures for Test Data
156
-
157
- ```typescript
158
- // fixtures/test-data.ts
159
- import { test as base } from '@playwright/test';
160
-
161
- type TestData = {
162
- testUser: {
163
- email: string;
164
- password: string;
165
- name: string;
166
- };
167
- adminUser: {
168
- email: string;
169
- password: string;
170
- };
171
- };
172
-
173
- export const test = base.extend<TestData>({
174
- testUser: async ({}, use) => {
175
- const user = {
176
- email: `test-${Date.now()}@example.com`,
177
- password: 'Test123!@#',
178
- name: 'Test User',
179
- };
180
- // Setup: Create user in database
181
- await createTestUser(user);
182
- await use(user);
183
- // Teardown: Clean up user
184
- await deleteTestUser(user.email);
185
- },
186
-
187
- adminUser: async ({}, use) => {
188
- await use({
189
- email: 'admin@example.com',
190
- password: process.env.ADMIN_PASSWORD!,
191
- });
192
- },
193
- });
194
-
195
- // Usage in tests
196
- import { test } from './fixtures/test-data';
197
-
198
- test('user can update profile', async ({ page, testUser }) => {
199
- await page.goto('/login');
200
- await page.getByLabel('Email').fill(testUser.email);
201
- await page.getByLabel('Password').fill(testUser.password);
202
- await page.getByRole('button', { name: 'Login' }).click();
203
-
204
- await page.goto('/profile');
205
- await page.getByLabel('Name').fill('Updated Name');
206
- await page.getByRole('button', { name: 'Save' }).click();
207
-
208
- await expect(page.getByText('Profile updated')).toBeVisible();
209
- });
210
- ```
211
-
212
- ### Pattern 3: Waiting Strategies
213
-
214
- ```typescript
215
- // ❌ Bad: Fixed timeouts
216
- await page.waitForTimeout(3000); // Flaky!
217
-
218
- // ✅ Good: Wait for specific conditions
219
- await page.waitForLoadState('networkidle');
220
- await page.waitForURL('/dashboard');
221
- await page.waitForSelector('[data-testid="user-profile"]');
222
-
223
- // ✅ Better: Auto-waiting with assertions
224
- await expect(page.getByText('Welcome')).toBeVisible();
225
- await expect(page.getByRole('button', { name: 'Submit' }))
226
- .toBeEnabled();
227
-
228
- // Wait for API response
229
- const responsePromise = page.waitForResponse(
230
- response => response.url().includes('/api/users') && response.status() === 200
231
- );
232
- await page.getByRole('button', { name: 'Load Users' }).click();
233
- const response = await responsePromise;
234
- const data = await response.json();
235
- expect(data.users).toHaveLength(10);
236
-
237
- // Wait for multiple conditions
238
- await Promise.all([
239
- page.waitForURL('/success'),
240
- page.waitForLoadState('networkidle'),
241
- expect(page.getByText('Payment successful')).toBeVisible(),
242
- ]);
243
- ```
244
-
245
- ### Pattern 4: Network Mocking and Interception
246
-
247
- ```typescript
248
- // Mock API responses
249
- test('displays error when API fails', async ({ page }) => {
250
- await page.route('**/api/users', route => {
251
- route.fulfill({
252
- status: 500,
253
- contentType: 'application/json',
254
- body: JSON.stringify({ error: 'Internal Server Error' }),
255
- });
256
- });
257
-
258
- await page.goto('/users');
259
- await expect(page.getByText('Failed to load users')).toBeVisible();
260
- });
261
-
262
- // Intercept and modify requests
263
- test('can modify API request', async ({ page }) => {
264
- await page.route('**/api/users', async route => {
265
- const request = route.request();
266
- const postData = JSON.parse(request.postData() || '{}');
267
-
268
- // Modify request
269
- postData.role = 'admin';
270
-
271
- await route.continue({
272
- postData: JSON.stringify(postData),
273
- });
274
- });
275
-
276
- // Test continues...
277
- });
278
-
279
- // Mock third-party services
280
- test('payment flow with mocked Stripe', async ({ page }) => {
281
- await page.route('**/api/stripe/**', route => {
282
- route.fulfill({
283
- status: 200,
284
- body: JSON.stringify({
285
- id: 'mock_payment_id',
286
- status: 'succeeded',
287
- }),
288
- });
289
- });
290
-
291
- // Test payment flow with mocked response
292
- });
293
- ```
294
-
295
- ## Cypress Patterns
296
-
297
- ### Setup and Configuration
298
-
299
- ```typescript
300
- // cypress.config.ts
301
- import { defineConfig } from 'cypress';
302
-
303
- export default defineConfig({
304
- e2e: {
305
- baseUrl: 'http://localhost:3000',
306
- viewportWidth: 1280,
307
- viewportHeight: 720,
308
- video: false,
309
- screenshotOnRunFailure: true,
310
- defaultCommandTimeout: 10000,
311
- requestTimeout: 10000,
312
- setupNodeEvents(on, config) {
313
- // Implement node event listeners
314
- },
315
- },
316
- });
317
- ```
318
-
319
- ### Pattern 1: Custom Commands
320
-
321
- ```typescript
322
- // cypress/support/commands.ts
323
- declare global {
324
- namespace Cypress {
325
- interface Chainable {
326
- login(email: string, password: string): Chainable<void>;
327
- createUser(userData: UserData): Chainable<User>;
328
- dataCy(value: string): Chainable<JQuery<HTMLElement>>;
329
- }
330
- }
331
- }
332
-
333
- Cypress.Commands.add('login', (email: string, password: string) => {
334
- cy.visit('/login');
335
- cy.get('[data-testid="email"]').type(email);
336
- cy.get('[data-testid="password"]').type(password);
337
- cy.get('[data-testid="login-button"]').click();
338
- cy.url().should('include', '/dashboard');
339
- });
340
-
341
- Cypress.Commands.add('createUser', (userData: UserData) => {
342
- return cy.request('POST', '/api/users', userData)
343
- .its('body');
344
- });
345
-
346
- Cypress.Commands.add('dataCy', (value: string) => {
347
- return cy.get(`[data-cy="${value}"]`);
348
- });
349
-
350
- // Usage
351
- cy.login('user@example.com', 'password');
352
- cy.dataCy('submit-button').click();
353
- ```
354
-
355
- ### Pattern 2: Cypress Intercept
356
-
357
- ```typescript
358
- // Mock API calls
359
- cy.intercept('GET', '/api/users', {
360
- statusCode: 200,
361
- body: [
362
- { id: 1, name: 'John' },
363
- { id: 2, name: 'Jane' },
364
- ],
365
- }).as('getUsers');
366
-
367
- cy.visit('/users');
368
- cy.wait('@getUsers');
369
- cy.get('[data-testid="user-list"]').children().should('have.length', 2);
370
-
371
- // Modify responses
372
- cy.intercept('GET', '/api/users', (req) => {
373
- req.reply((res) => {
374
- // Modify response
375
- res.body.users = res.body.users.slice(0, 5);
376
- res.send();
377
- });
378
- });
379
-
380
- // Simulate slow network
381
- cy.intercept('GET', '/api/data', (req) => {
382
- req.reply((res) => {
383
- res.delay(3000); // 3 second delay
384
- res.send();
385
- });
386
- });
387
- ```
388
-
389
- ## Advanced Patterns
390
-
391
- ### Pattern 1: Visual Regression Testing
392
-
393
- ```typescript
394
- // With Playwright
395
- import { test, expect } from '@playwright/test';
396
-
397
- test('homepage looks correct', async ({ page }) => {
398
- await page.goto('/');
399
- await expect(page).toHaveScreenshot('homepage.png', {
400
- fullPage: true,
401
- maxDiffPixels: 100,
402
- });
403
- });
404
-
405
- test('button in all states', async ({ page }) => {
406
- await page.goto('/components');
407
-
408
- const button = page.getByRole('button', { name: 'Submit' });
409
-
410
- // Default state
411
- await expect(button).toHaveScreenshot('button-default.png');
412
-
413
- // Hover state
414
- await button.hover();
415
- await expect(button).toHaveScreenshot('button-hover.png');
416
-
417
- // Disabled state
418
- await button.evaluate(el => el.setAttribute('disabled', 'true'));
419
- await expect(button).toHaveScreenshot('button-disabled.png');
420
- });
421
- ```
422
-
423
- ### Pattern 2: Parallel Testing with Sharding
424
-
425
- ```typescript
426
- // playwright.config.ts
427
- export default defineConfig({
428
- projects: [
429
- {
430
- name: 'shard-1',
431
- use: { ...devices['Desktop Chrome'] },
432
- grepInvert: /@slow/,
433
- shard: { current: 1, total: 4 },
434
- },
435
- {
436
- name: 'shard-2',
437
- use: { ...devices['Desktop Chrome'] },
438
- shard: { current: 2, total: 4 },
439
- },
440
- // ... more shards
441
- ],
442
- });
443
-
444
- // Run in CI
445
- // npx playwright test --shard=1/4
446
- // npx playwright test --shard=2/4
447
- ```
448
-
449
- ### Pattern 3: Accessibility Testing
450
-
451
- ```typescript
452
- // Install: npm install @axe-core/playwright
453
- import { test, expect } from '@playwright/test';
454
- import AxeBuilder from '@axe-core/playwright';
455
-
456
- test('page should not have accessibility violations', async ({ page }) => {
457
- await page.goto('/');
458
-
459
- const accessibilityScanResults = await new AxeBuilder({ page })
460
- .exclude('#third-party-widget')
461
- .analyze();
462
-
463
- expect(accessibilityScanResults.violations).toEqual([]);
464
- });
465
-
466
- test('form is accessible', async ({ page }) => {
467
- await page.goto('/signup');
468
-
469
- const results = await new AxeBuilder({ page })
470
- .include('form')
471
- .analyze();
472
-
473
- expect(results.violations).toEqual([]);
474
- });
475
- ```
476
-
477
- ## Best Practices
478
-
479
- 1. **Use Data Attributes**: `data-testid` or `data-cy` for stable selectors
480
- 2. **Avoid Brittle Selectors**: Don't rely on CSS classes or DOM structure
481
- 3. **Test User Behavior**: Click, type, see - not implementation details
482
- 4. **Keep Tests Independent**: Each test should run in isolation
483
- 5. **Clean Up Test Data**: Create and destroy test data in each test
484
- 6. **Use Page Objects**: Encapsulate page logic
485
- 7. **Meaningful Assertions**: Check actual user-visible behavior
486
- 8. **Optimize for Speed**: Mock when possible, parallel execution
487
-
488
- ```typescript
489
- // ❌ Bad selectors
490
- cy.get('.btn.btn-primary.submit-button').click();
491
- cy.get('div > form > div:nth-child(2) > input').type('text');
492
-
493
- // ✅ Good selectors
494
- cy.getByRole('button', { name: 'Submit' }).click();
495
- cy.getByLabel('Email address').type('user@example.com');
496
- cy.get('[data-testid="email-input"]').type('user@example.com');
497
- ```
498
-
499
- ## Common Pitfalls
500
-
501
- - **Flaky Tests**: Use proper waits, not fixed timeouts
502
- - **Slow Tests**: Mock external APIs, use parallel execution
503
- - **Over-Testing**: Don't test every edge case with E2E
504
- - **Coupled Tests**: Tests should not depend on each other
505
- - **Poor Selectors**: Avoid CSS classes and nth-child
506
- - **No Cleanup**: Clean up test data after each test
507
- - **Testing Implementation**: Test user behavior, not internals
508
-
509
- ## Debugging Failing Tests
510
-
511
- ```typescript
512
- // Playwright debugging
513
- // 1. Run in headed mode
514
- npx playwright test --headed
515
-
516
- // 2. Run in debug mode
517
- npx playwright test --debug
518
-
519
- // 3. Use trace viewer
520
- await page.screenshot({ path: 'screenshot.png' });
521
- await page.video()?.saveAs('video.webm');
522
-
523
- // 4. Add test.step for better reporting
524
- test('checkout flow', async ({ page }) => {
525
- await test.step('Add item to cart', async () => {
526
- await page.goto('/products');
527
- await page.getByRole('button', { name: 'Add to Cart' }).click();
528
- });
529
-
530
- await test.step('Proceed to checkout', async () => {
531
- await page.goto('/cart');
532
- await page.getByRole('button', { name: 'Checkout' }).click();
533
- });
534
- });
535
-
536
- // 5. Inspect page state
537
- await page.pause(); // Pauses execution, opens inspector
538
- ```
539
-
540
- ## Resources
541
-
542
- - **references/playwright-best-practices.md**: Playwright-specific patterns
543
- - **references/cypress-best-practices.md**: Cypress-specific patterns
544
- - **references/flaky-test-debugging.md**: Debugging unreliable tests
545
- - **assets/e2e-testing-checklist.md**: What to test with E2E
546
- - **assets/selector-strategies.md**: Finding reliable selectors
547
- - **scripts/test-analyzer.ts**: Analyze test flakiness and duration