@el-j/magic-helix-core 4.0.0-beta.2 → 4.0.0-beta.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 (165) hide show
  1. package/dist/index-B88j4AyE.js +13 -0
  2. package/dist/index-B88j4AyE.js.map +1 -0
  3. package/dist/index-CY-pQbuu.cjs +2 -0
  4. package/dist/index-CY-pQbuu.cjs.map +1 -0
  5. package/dist/index.cjs +75 -1
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.d.ts +0 -1
  8. package/dist/index.mjs +2214 -51
  9. package/dist/index.mjs.map +1 -1
  10. package/dist/pattern-combiner.d.ts +1 -1
  11. package/dist/plugin-loader.d.ts +2 -1
  12. package/package.json +4 -4
  13. package/dist/BasePlugin-6wv0hYJ9.js +0 -98
  14. package/dist/BasePlugin-6wv0hYJ9.js.map +0 -1
  15. package/dist/BasePlugin-odQJAKA-.cjs +0 -2
  16. package/dist/BasePlugin-odQJAKA-.cjs.map +0 -1
  17. package/dist/builtin-plugins/base/BasePlugin.d.ts +0 -69
  18. package/dist/builtin-plugins/cpp/index.d.ts +0 -46
  19. package/dist/builtin-plugins/csharp/index.d.ts +0 -20
  20. package/dist/builtin-plugins/go/index.d.ts +0 -23
  21. package/dist/builtin-plugins/index.d.ts +0 -16
  22. package/dist/builtin-plugins/java/index.d.ts +0 -22
  23. package/dist/builtin-plugins/nodejs/index.d.ts +0 -44
  24. package/dist/builtin-plugins/php/index.d.ts +0 -20
  25. package/dist/builtin-plugins/python/index.d.ts +0 -27
  26. package/dist/builtin-plugins/ruby/index.d.ts +0 -20
  27. package/dist/builtin-plugins/rust/index.d.ts +0 -53
  28. package/dist/builtin-plugins/swift/index.d.ts +0 -22
  29. package/dist/default_templates/angular/angular-core.md +0 -19
  30. package/dist/default_templates/architecture/codeowners.md +0 -123
  31. package/dist/default_templates/architecture/monorepo.md +0 -146
  32. package/dist/default_templates/architecture/nx.md +0 -122
  33. package/dist/default_templates/architecture/turborepo.md +0 -114
  34. package/dist/default_templates/ci/github-actions.md +0 -268
  35. package/dist/default_templates/ci/gitlab-ci.md +0 -330
  36. package/dist/default_templates/containers/docker-multistage.md +0 -120
  37. package/dist/default_templates/containers/kubernetes-deploy.md +0 -210
  38. package/dist/default_templates/devops/docker-compose.md +0 -111
  39. package/dist/default_templates/devops/docker-dockerfile.md +0 -94
  40. package/dist/default_templates/devops/github-actions.md +0 -160
  41. package/dist/default_templates/devops/gitlab-ci.md +0 -210
  42. package/dist/default_templates/dotnet/framework-aspnetcore.md +0 -205
  43. package/dist/default_templates/dotnet/framework-blazor.md +0 -271
  44. package/dist/default_templates/dotnet/lang-csharp.md +0 -162
  45. package/dist/default_templates/generic/lang-typescript.md +0 -57
  46. package/dist/default_templates/generic/state-redux.md +0 -21
  47. package/dist/default_templates/generic/state-rxjs.md +0 -6
  48. package/dist/default_templates/generic/style-mui.md +0 -23
  49. package/dist/default_templates/generic/style-tailwind.md +0 -76
  50. package/dist/default_templates/generic/test-cypress.md +0 -21
  51. package/dist/default_templates/generic/test-jest.md +0 -20
  52. package/dist/default_templates/generic/test-playwright.md +0 -21
  53. package/dist/default_templates/generic/test-vitest.md +0 -131
  54. package/dist/default_templates/go/lang-go.md +0 -571
  55. package/dist/default_templates/java/build-gradle.md +0 -102
  56. package/dist/default_templates/java/build-maven.md +0 -86
  57. package/dist/default_templates/java/framework-spring-boot.md +0 -179
  58. package/dist/default_templates/java/lang-java.md +0 -78
  59. package/dist/default_templates/java/lang-kotlin.md +0 -88
  60. package/dist/default_templates/meta/magic-helix-meta.md +0 -213
  61. package/dist/default_templates/meta/meta-debug.md +0 -459
  62. package/dist/default_templates/meta/meta-implement.md +0 -450
  63. package/dist/default_templates/meta/meta-roadmap.md +0 -265
  64. package/dist/default_templates/nestjs/nestjs-core.md +0 -7
  65. package/dist/default_templates/patterns/architecture/clean-architecture.md +0 -469
  66. package/dist/default_templates/patterns/architecture/dependency-injection.md +0 -517
  67. package/dist/default_templates/patterns/architecture/domain-driven-design.md +0 -621
  68. package/dist/default_templates/patterns/architecture/layered-architecture.md +0 -382
  69. package/dist/default_templates/patterns/architecture/repository-pattern.md +0 -408
  70. package/dist/default_templates/patterns/domain-expertise/nextjs-rules.md +0 -115
  71. package/dist/default_templates/patterns/domain-expertise/react-patterns.md +0 -181
  72. package/dist/default_templates/patterns/domain-expertise/server-components.md +0 -212
  73. package/dist/default_templates/patterns/domain-expertise/shadcn-ui.md +0 -52
  74. package/dist/default_templates/patterns/domain-expertise/tailwind-patterns.md +0 -52
  75. package/dist/default_templates/patterns/environment/container-awareness.md +0 -17
  76. package/dist/default_templates/patterns/environment/ide-features.md +0 -17
  77. package/dist/default_templates/patterns/environment/os-commands.md +0 -17
  78. package/dist/default_templates/patterns/organization/heading-hierarchy.md +0 -103
  79. package/dist/default_templates/patterns/organization/sequential-workflows.md +0 -102
  80. package/dist/default_templates/patterns/organization/xml-rule-groups.md +0 -64
  81. package/dist/default_templates/patterns/reasoning/agent-loop.md +0 -151
  82. package/dist/default_templates/patterns/reasoning/confirmation-gates.md +0 -141
  83. package/dist/default_templates/patterns/reasoning/dependency-analysis.md +0 -132
  84. package/dist/default_templates/patterns/reasoning/one-tool-per-iteration.md +0 -152
  85. package/dist/default_templates/patterns/reasoning/preview-before-action.md +0 -194
  86. package/dist/default_templates/patterns/reasoning/reflection-checkpoints.md +0 -166
  87. package/dist/default_templates/patterns/reasoning/result-verification.md +0 -157
  88. package/dist/default_templates/patterns/reasoning/subtask-breakdown.md +0 -131
  89. package/dist/default_templates/patterns/reasoning/thinking-tags.md +0 -100
  90. package/dist/default_templates/patterns/role-definition/capability-declarations.md +0 -72
  91. package/dist/default_templates/patterns/role-definition/expert-identity.md +0 -45
  92. package/dist/default_templates/patterns/role-definition/scope-boundaries.md +0 -61
  93. package/dist/default_templates/patterns/safety/code-safety-rules.md +0 -17
  94. package/dist/default_templates/patterns/safety/credential-handling.md +0 -17
  95. package/dist/default_templates/patterns/safety/destructive-warnings.md +0 -17
  96. package/dist/default_templates/patterns/safety/refusal-messages.md +0 -17
  97. package/dist/default_templates/patterns/tone/adaptive-tone.md +0 -17
  98. package/dist/default_templates/patterns/tone/concise-communication.md +0 -17
  99. package/dist/default_templates/patterns/tone/forbidden-phrases.md +0 -17
  100. package/dist/default_templates/patterns/tool-guidelines/function-schemas.md +0 -143
  101. package/dist/default_templates/patterns/tool-guidelines/parameter-examples.md +0 -137
  102. package/dist/default_templates/patterns/tool-guidelines/usage-policies.md +0 -105
  103. package/dist/default_templates/php/framework-laravel.md +0 -112
  104. package/dist/default_templates/php/lang-php.md +0 -94
  105. package/dist/default_templates/python/lang-python.md +0 -508
  106. package/dist/default_templates/react/react-core.md +0 -677
  107. package/dist/default_templates/react/react-zustand.md +0 -7
  108. package/dist/default_templates/ruby/framework-rails.md +0 -309
  109. package/dist/default_templates/ruby/framework-sinatra.md +0 -227
  110. package/dist/default_templates/ruby/lang-ruby.md +0 -216
  111. package/dist/default_templates/rust/lang-rust.md +0 -89
  112. package/dist/default_templates/swift/framework-vapor.md +0 -352
  113. package/dist/default_templates/swift/lang-swift.md +0 -291
  114. package/dist/default_templates/vue/style-primevue.md +0 -6
  115. package/dist/default_templates/vue/style-quasar.md +0 -22
  116. package/dist/default_templates/vue/vue-core.md +0 -108
  117. package/dist/default_templates/vue/vue-pinia.md +0 -5
  118. package/dist/index-0GK4RlUx.js +0 -1748
  119. package/dist/index-0GK4RlUx.js.map +0 -1
  120. package/dist/index-AkVwRl-r.js +0 -92
  121. package/dist/index-AkVwRl-r.js.map +0 -1
  122. package/dist/index-B6BeG1yT.cjs +0 -68
  123. package/dist/index-B6BeG1yT.cjs.map +0 -1
  124. package/dist/index-B8pyjKdF.js +0 -94
  125. package/dist/index-B8pyjKdF.js.map +0 -1
  126. package/dist/index-BQ6v041y.js +0 -13
  127. package/dist/index-BQ6v041y.js.map +0 -1
  128. package/dist/index-Baxb1vI_.js +0 -210
  129. package/dist/index-Baxb1vI_.js.map +0 -1
  130. package/dist/index-Bg8DD8ku.js +0 -216
  131. package/dist/index-Bg8DD8ku.js.map +0 -1
  132. package/dist/index-BqTqxCpG.cjs +0 -89
  133. package/dist/index-BqTqxCpG.cjs.map +0 -1
  134. package/dist/index-Bv4Q1Pr7.cjs +0 -33
  135. package/dist/index-Bv4Q1Pr7.cjs.map +0 -1
  136. package/dist/index-CN8J45Nc.cjs +0 -24
  137. package/dist/index-CN8J45Nc.cjs.map +0 -1
  138. package/dist/index-CPbv2Od1.js +0 -62
  139. package/dist/index-CPbv2Od1.js.map +0 -1
  140. package/dist/index-Cf-MC6Al.js +0 -63
  141. package/dist/index-Cf-MC6Al.js.map +0 -1
  142. package/dist/index-DDPXXXDy.cjs +0 -19
  143. package/dist/index-DDPXXXDy.cjs.map +0 -1
  144. package/dist/index-DO30AzDe.cjs +0 -19
  145. package/dist/index-DO30AzDe.cjs.map +0 -1
  146. package/dist/index-DkvW5yBY.js +0 -2249
  147. package/dist/index-DkvW5yBY.js.map +0 -1
  148. package/dist/index-Dn1ehjIj.cjs +0 -80
  149. package/dist/index-Dn1ehjIj.cjs.map +0 -1
  150. package/dist/index-DqHvgoXJ.cjs +0 -19
  151. package/dist/index-DqHvgoXJ.cjs.map +0 -1
  152. package/dist/index-K39pdw94.cjs +0 -31
  153. package/dist/index-K39pdw94.cjs.map +0 -1
  154. package/dist/index-OT2XAJkc.js +0 -117
  155. package/dist/index-OT2XAJkc.js.map +0 -1
  156. package/dist/index-TPAX4XKg.cjs +0 -30
  157. package/dist/index-TPAX4XKg.cjs.map +0 -1
  158. package/dist/index-WmVSB57y.js +0 -107
  159. package/dist/index-WmVSB57y.js.map +0 -1
  160. package/dist/index-mYXvc3Fs.js +0 -68
  161. package/dist/index-mYXvc3Fs.js.map +0 -1
  162. package/dist/index-nioXOg4m.cjs +0 -76
  163. package/dist/index-nioXOg4m.cjs.map +0 -1
  164. package/dist/index-okhY3fWD.cjs +0 -2
  165. package/dist/index-okhY3fWD.cjs.map +0 -1
@@ -1,6 +0,0 @@
1
- # State: RxJS
2
- - **ALWAYS** suffix Observable variables with a `$` (e.g., `users$`).
3
- - **ALWAYS** use `BehaviorSubject` for state that needs to be "replayed" to new subscribers.
4
- - **ALWAYS** `pipe()` operators. Do not use chained `.` operators.
5
- - **NEVER** forget to `unsubscribe()`. Manage subscriptions in a central way, e.g., a `destroy$` Subject that completes `onComponentDestroy`.
6
- - **PREFER** `switchMap` for handling new inner observables (like HTTP requests) and `mergeMap` for parallel operations.
@@ -1,23 +0,0 @@
1
- # Styling: Material-UI (MUI)
2
- - **ALWAYS** use `@mui/material` v5+ with Emotion styling engine.
3
- - **ALWAYS** use `sx` prop for component-level styling.
4
- - **ALWAYS** use `ThemeProvider` for consistent theming.
5
- - **ALWAYS** use `createTheme()` for custom theme configuration.
6
- - **ALWAYS** use semantic color tokens from the theme palette.
7
- - **ALWAYS** use `Box` component as a generic layout primitive.
8
- - **ALWAYS** use `Container` for max-width layouts and centering.
9
- - **ALWAYS** use `Grid` v2 (`Grid2`) for responsive layouts.
10
- - **ALWAYS** use `Typography` component for all text elements.
11
- - **ALWAYS** use `Button` variants (`contained`, `outlined`, `text`) appropriately.
12
- - **ALWAYS** use `IconButton` for icon-only actions.
13
- - **ALWAYS** use `TextField` with proper `label` and `helperText` props.
14
- - **ALWAYS** use `FormControl` and `FormLabel` for form organization.
15
- - **ALWAYS** use `Dialog` for modals with proper accessibility.
16
- - **ALWAYS** use `Menu` and `MenuItem` for dropdown menus.
17
- - **ALWAYS** use `Chip` for tags, filters, and small status indicators.
18
- - **ALWAYS** use `Avatar` for user profile images.
19
- - **ALWAYS** use `Card`, `CardContent`, and `CardActions` for content containers.
20
- - **ALWAYS** use `List`, `ListItem`, and `ListItemText` for list displays.
21
- - **ALWAYS** use `Table` components for tabular data.
22
- - **ALWAYS** use `useMediaQuery` hook for responsive behavior.
23
- - **ALWAYS** use `styled()` API for custom component styling when needed.
@@ -1,76 +0,0 @@
1
- # Styling: Tailwind CSS
2
-
3
- ## Expert Identity
4
- You are an expert in utility-first CSS with Tailwind, focusing on responsive design, maintainable styling, and optimal class composition.
5
-
6
- ## Core Capabilities
7
- - Build responsive layouts using Tailwind utility classes
8
- - Apply consistent spacing, typography, and color systems
9
- - Optimize for mobile-first responsive design
10
- - Implement accessible UI components with proper contrast and focus states
11
-
12
- ## Coding Standards
13
-
14
- ### Utility-First Approach
15
- - **ALWAYS** use Tailwind utility classes for all styling.
16
- - **NEVER** write custom CSS in `<style>` blocks or `.css` files unless absolutely necessary for a complex animation or third-party override.
17
- - **NAMING**: Do not use `@apply`. Stick to utility classes in the HTML/JSX.
18
-
19
- ### Layout
20
- - **LAYOUT**: Use `flex` and `grid` for all page and component layouts.
21
- - **RESPONSIVE**: Use responsive prefixes (`sm:`, `md:`, `lg:`, `xl:`) for all layouts following mobile-first design.
22
-
23
- ### Accessibility
24
- - **ALWAYS** include focus states for interactive elements using `focus:` prefix
25
- - **ALWAYS** ensure proper color contrast for text readability
26
- - **ALWAYS** use semantic HTML with Tailwind classes
27
-
28
- ## Examples
29
-
30
- ### Responsive Card Component
31
- ```html
32
- <!-- ✅ Good: Mobile-first responsive card -->
33
- <div class="bg-white rounded-lg shadow-md p-4 sm:p-6 lg:p-8">
34
- <h2 class="text-xl sm:text-2xl font-bold text-gray-900 mb-4">
35
- Card Title
36
- </h2>
37
- <p class="text-gray-600 text-sm sm:text-base">
38
- Card content that adapts to screen size.
39
- </p>
40
- <button class="mt-4 px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2">
41
- Action
42
- </button>
43
- </div>
44
- ```
45
-
46
- ### Flexbox Layout
47
- ```html
48
- <!-- ✅ Good: Flex layout with responsive behavior -->
49
- <div class="flex flex-col sm:flex-row gap-4 items-stretch sm:items-center">
50
- <div class="flex-1 bg-gray-100 p-4 rounded">Item 1</div>
51
- <div class="flex-1 bg-gray-100 p-4 rounded">Item 2</div>
52
- <div class="flex-1 bg-gray-100 p-4 rounded">Item 3</div>
53
- </div>
54
- ```
55
-
56
- ### Grid Layout
57
- ```html
58
- <!-- ✅ Good: Responsive grid -->
59
- <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6">
60
- <div class="bg-white p-6 rounded-lg shadow">Grid Item 1</div>
61
- <div class="bg-white p-6 rounded-lg shadow">Grid Item 2</div>
62
- <div class="bg-white p-6 rounded-lg shadow">Grid Item 3</div>
63
- </div>
64
- ```
65
-
66
- ## Tool Usage
67
- When editing HTML/JSX files:
68
- - Apply Tailwind classes directly in className or class attributes
69
- - Use the `replace_string_in_file` tool to update styling
70
- - Verify responsive breakpoints are correctly applied
71
-
72
- ## Safety Guidelines
73
- - Never remove accessibility-related classes (focus states, ARIA attributes) when refactoring
74
- - Refuse to implement designs that violate WCAG contrast requirements
75
- - Always maintain mobile-first responsive design principles
76
- - Do not use `!important` in custom CSS unless explicitly requested
@@ -1,21 +0,0 @@
1
- # Testing: Cypress
2
- - **ALWAYS** use `data-cy` attributes for element selection.
3
- - **ALWAYS** avoid using CSS selectors - prefer `data-cy` attributes.
4
- - **ALWAYS** use page object pattern for reusable selectors.
5
- - **ALWAYS** use `cy.intercept()` for API mocking and spying.
6
- - **ALWAYS** use `cy.wait()` sparingly - prefer assertions over arbitrary waits.
7
- - **ALWAYS** use `should()` for assertions instead of `then()`.
8
- - **ALWAYS** test user journeys, not implementation details.
9
- - **ALWAYS** use `cy.session()` for authentication state management.
10
- - **ALWAYS** organize tests in `cypress/e2e/` directory.
11
- - **ALWAYS** use `describe()` and `it()` for test organization.
12
- - **ALWAYS** use `beforeEach()` for test setup and navigation.
13
- - **ALWAYS** test both happy path and error scenarios.
14
- - **ALWAYS** use `cy.fixture()` for test data management.
15
- - **ALWAYS** use `cy.viewport()` to test responsive design.
16
- - **ALWAYS** use `cy.pause()` during development, remove for CI.
17
- - **ALWAYS** use `cy.debug()` for debugging, remove for production.
18
- - **ALWAYS** run tests in headless mode for CI/CD.
19
- - **ALWAYS** use `cy.request()` for API testing when UI testing isn't needed.
20
- - **ALWAYS** use custom commands for reusable actions.
21
- - **ALWAYS** maintain test execution time under 2 minutes per spec.
@@ -1,20 +0,0 @@
1
- # Testing: Jest
2
- - **ALWAYS** use descriptive test names that explain what is being tested.
3
- - **ALWAYS** follow the "Arrange, Act, Assert" pattern in tests.
4
- - **ALWAYS** use `describe` blocks to group related tests.
5
- - **ALWAYS** use `beforeEach` and `afterEach` for test setup and teardown.
6
- - **ALWAYS** mock external dependencies with `jest.mock()` or `jest.fn()`.
7
- - **ALWAYS** use `expect.assertions()` to ensure assertions are called.
8
- - **ALWAYS** test both success and error cases.
9
- - **ALWAYS** use `test.each` for parameterized tests.
10
- - **ALWAYS** avoid testing implementation details - test behavior.
11
- - **ALWAYS** use `jest.clearAllMocks()` in `beforeEach` for clean tests.
12
- - **ALWAYS** use meaningful assertion messages with `expect().toBe(expected, message)`.
13
- - **ALWAYS** test async code with `async/await` and proper error handling.
14
- - **ALWAYS** use `jest.spyOn()` for spying on object methods.
15
- - **ALWAYS** group mocks in a `mocks` directory with descriptive names.
16
- - **ALWAYS** use `jest.setTimeout()` for long-running async tests.
17
- - **ALWAYS** test edge cases and boundary conditions.
18
- - **ALWAYS** use `test.todo()` for planned tests.
19
- - **ALWAYS** maintain test coverage above 80%.
20
- - **ALWAYS** run tests in CI/CD pipelines with `--coverage` flag.
@@ -1,21 +0,0 @@
1
- # Testing: Playwright
2
- - **ALWAYS** use semantic locators like `getByRole()`, `getByLabel()`, `getByText()`.
3
- - **ALWAYS** use `data-testid` attributes as fallback for complex selectors.
4
- - **ALWAYS** use page object model for reusable selectors and actions.
5
- - **ALWAYS** use `page.route()` for API mocking and network interception.
6
- - **ALWAYS** use `expect().toBeVisible()` and `expect().toBeHidden()` for visibility checks.
7
- - **ALWAYS** use `page.waitForLoadState('networkidle')` for page load completion.
8
- - **ALWAYS** test cross-browser compatibility with different browser contexts.
9
- - **ALWAYS** use `test.describe()` for grouping related tests.
10
- - **ALWAYS** use `test.beforeEach()` for test setup and navigation.
11
- - **ALWAYS** use `page.context().storageState()` for authentication persistence.
12
- - **ALWAYS** use `page.screenshot()` for visual regression testing.
13
- - **ALWAYS** use `test.use()` for configuring test fixtures.
14
- - **ALWAYS** use `page.pause()` during development for debugging.
15
- - **ALWAYS** use `test.skip()` and `test.only()` for test management.
16
- - **ALWAYS** use `expect().toMatchSnapshot()` for visual comparisons.
17
- - **ALWAYS** use `page.keyboard` and `page.mouse` for complex interactions.
18
- - **ALWAYS** use `page.waitForFunction()` for custom wait conditions.
19
- - **ALWAYS** run tests in parallel with `workers` configuration.
20
- - **ALWAYS** use `testInfo.attachments` for test artifacts.
21
- - **ALWAYS** maintain test execution time under 30 seconds per test.
@@ -1,131 +0,0 @@
1
- # Testing: Vitest
2
-
3
- ## Expert Identity
4
- You are an expert in writing comprehensive test suites using Vitest, with deep knowledge of test-driven development, mocking strategies, and code coverage.
5
-
6
- ## Core Capabilities
7
- - Write clear, maintainable unit tests with descriptive test names
8
- - Mock external dependencies and modules effectively
9
- - Achieve high code coverage with meaningful assertions
10
- - Debug failing tests and identify root causes
11
- - Set up proper test fixtures and teardown
12
-
13
- ## Coding Standards
14
-
15
- ### Test Structure
16
- - **ALWAYS** use `describe`, `it`, and `expect` syntax.
17
- - **ALWAYS** group related tests in `describe` blocks.
18
- - **ALWAYS** write descriptive test names that explain the expected behavior.
19
-
20
- ### Mocking
21
- - **ALWAYS** mock dependencies using `vi.mock()`.
22
- - **ALWAYS** clean up mocks after each test using `afterEach(() => { vi.restoreAllMocks(); })`.
23
- - **PREFER** `vi.fn()` for function mocks and `vi.spyOn()` for spying on existing methods.
24
-
25
- ### Best Practices
26
- - Use `it.todo('should do a thing')` for pending tests.
27
- - For component testing, prefer `@vitest/ui` for a visual test runner.
28
- - **ALWAYS** use `beforeEach` for setup and `afterEach` for cleanup.
29
- - **AVOID** test interdependence - each test should run independently.
30
-
31
- ## Examples
32
-
33
- ### Basic Unit Test
34
- ```typescript
35
- import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
36
- import { calculateTotal } from './calculator';
37
-
38
- describe('calculateTotal', () => {
39
- it('should sum an array of numbers correctly', () => {
40
- const result = calculateTotal([1, 2, 3, 4, 5]);
41
- expect(result).toBe(15);
42
- });
43
-
44
- it('should return 0 for an empty array', () => {
45
- const result = calculateTotal([]);
46
- expect(result).toBe(0);
47
- });
48
-
49
- it('should handle negative numbers', () => {
50
- const result = calculateTotal([-1, -2, 3]);
51
- expect(result).toBe(0);
52
- });
53
- });
54
- ```
55
-
56
- ### Mocking Dependencies
57
- ```typescript
58
- import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
59
- import { fetchUserData } from './api';
60
- import { getUserProfile } from './userService';
61
-
62
- vi.mock('./api');
63
-
64
- describe('getUserProfile', () => {
65
- beforeEach(() => {
66
- vi.clearAllMocks();
67
- });
68
-
69
- afterEach(() => {
70
- vi.restoreAllMocks();
71
- });
72
-
73
- it('should fetch and return user profile', async () => {
74
- const mockUser = { id: 1, name: 'John Doe', email: 'john@example.com' };
75
- vi.mocked(fetchUserData).mockResolvedValue(mockUser);
76
-
77
- const result = await getUserProfile(1);
78
-
79
- expect(fetchUserData).toHaveBeenCalledWith(1);
80
- expect(result).toEqual(mockUser);
81
- });
82
-
83
- it('should handle API errors gracefully', async () => {
84
- vi.mocked(fetchUserData).mockRejectedValue(new Error('API Error'));
85
-
86
- await expect(getUserProfile(1)).rejects.toThrow('API Error');
87
- });
88
- });
89
- ```
90
-
91
- ### Component Testing (Vue)
92
- ```typescript
93
- import { describe, it, expect } from 'vitest';
94
- import { mount } from '@vue/test-utils';
95
- import MyButton from './MyButton.vue';
96
-
97
- describe('MyButton', () => {
98
- it('should render with correct text', () => {
99
- const wrapper = mount(MyButton, {
100
- props: { label: 'Click me' },
101
- });
102
-
103
- expect(wrapper.text()).toBe('Click me');
104
- });
105
-
106
- it('should emit click event when clicked', async () => {
107
- const wrapper = mount(MyButton);
108
- await wrapper.trigger('click');
109
-
110
- expect(wrapper.emitted('click')).toHaveLength(1);
111
- });
112
- });
113
- ```
114
-
115
- ## Tool Usage
116
- When using the `runTests` tool:
117
- - Specify test file paths to run focused tests
118
- - Use coverage mode to verify code coverage
119
- - Review test output for failures and adjust assertions
120
-
121
- When creating test files:
122
- - Place tests in `__tests__` directories or `.test.ts` / `.spec.ts` files
123
- - Mirror the source file structure in test organization
124
- - Use the `create_file` tool to generate new test files
125
-
126
- ## Safety Guidelines
127
- - Never skip or disable tests without documenting the reason
128
- - Refuse to write tests that don't actually validate behavior (e.g., `expect(true).toBe(true)`)
129
- - Always clean up side effects (timers, mocks, DOM changes) in `afterEach`
130
- - Ensure tests are deterministic and don't rely on external state or timing
131
- - Avoid testing implementation details - focus on behavior and public API