-
Notifications
You must be signed in to change notification settings - Fork 0
chore: sync AI rules/docs with Bun testing setup #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| --- | ||
| description: Monorepo structure, package boundaries, and workspace conventions | ||
| globs: **/* | ||
| alwaysApply: true | ||
| --- | ||
|
|
||
| # Monorepo Rules | ||
|
|
||
| ## Package Structure | ||
| - `apps/` - Applications (todo-app) | ||
| - `packages/` - Shared packages (ui, utils) | ||
| - Each package has its own package.json with proper exports | ||
|
|
||
| ## Workspace Dependencies | ||
| - Use `workspace:*` for internal package dependencies | ||
| - Keep external dependencies in sync across packages | ||
| - Use peerDependencies for shared libraries like React | ||
|
|
||
| ## Import Patterns | ||
| ```tsx | ||
| // Import from workspace packages | ||
| import { Button } from '@todo-starter/ui'; | ||
| import { cn, type Todo } from '@todo-starter/utils'; | ||
|
|
||
| // Import from local files | ||
| import { TodoItem } from '~/components/todo-item'; | ||
| import type { Route } from './+types/home'; | ||
| ``` | ||
|
|
||
| ## Package Naming | ||
| - Use scoped packages: `@todo-starter/package-name` | ||
| - Keep names descriptive and consistent | ||
| - Use kebab-case for package names | ||
|
|
||
| ## Scripts and Tasks | ||
| - Define scripts at both root and package level | ||
| - Use Turbo for orchestrating build tasks | ||
| - Prefer package-specific scripts for development | ||
|
|
||
| ## TypeScript Configuration | ||
| - Use Tailwind CSS v4's CSS-first configuration with `@theme` directive | ||
| - Use path mapping for workspace packages | ||
| - Keep tsconfig.json files minimal and focused | ||
|
|
||
| ## Best Practices | ||
| - Keep packages focused and single-purpose | ||
| - Avoid circular dependencies between packages | ||
| - Use proper exports in package.json | ||
| - Document package APIs and usage patterns |
File renamed without changes.
File renamed without changes.
78 changes: 78 additions & 0 deletions
78
.cursor/rules/ai-rules-generated-testing-best-practices.mdc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| --- | ||
| description: Bun test and React Testing Library patterns for React Router apps | ||
| globs: apps/**/*.test.{ts, tsx}, apps/**/*.spec.{ts, tsx}, apps/**/test/**/* | ||
| alwaysApply: false | ||
| --- | ||
|
|
||
| # Testing Best Practices | ||
|
|
||
| ## Stack | ||
|
|
||
| - **Runner:** Bun test (`bun:test`) with JSDOM bootstrap in `test/setup.ts` (loaded via `bunfig.toml`) | ||
| - **Component/DOM:** React Testing Library | ||
| - **Router:** `createMemoryRouter` + `RouterProvider` via shared `renderWithRouter` helper | ||
|
|
||
| ## Test Layout (todo-app) | ||
|
|
||
| | Pattern | Location | Purpose | | ||
| |---------------|-----------------------------------|--------| | ||
| | Unit | `app/lib/__tests__/*.test.ts` | Pure utilities, helpers | | ||
| | Component | `app/components/__tests__/*.test.tsx` | UI with router/context mocking | | ||
| | Integration | `app/routes/__tests__/*.integration.test.tsx` | Full route + provider flows | | ||
|
|
||
| Shared setup: `test/setup.ts` (jest-dom, RTL cleanup). Shared helpers: `test/test-utils.tsx`. | ||
|
|
||
| ## Router-Dependent Components | ||
|
|
||
| Use `renderWithRouter` for any component that uses `Link`, `useNavigate`, `useFetcher`, or `useHref`: | ||
|
|
||
| ```tsx | ||
| import { renderWithRouter } from '../../../test/test-utils'; | ||
|
|
||
| it('renders and submits', () => { | ||
| renderWithRouter(<MyComponent />); | ||
| }); | ||
|
|
||
| it('renders at /contact', () => { | ||
| renderWithRouter(<Page />, { initialEntries: ['/contact'] }); | ||
| }); | ||
| ``` | ||
|
|
||
| For full route trees (loaders, nested layouts), use `createTestRouter` or pass `routes` into `renderWithRouter`. | ||
|
|
||
| ## Integration Tests | ||
|
|
||
| Wrap route components with the same providers as the app (e.g. TodoProvider), then assert user flows: | ||
|
|
||
| ```tsx | ||
| import { renderWithRouter } from '../../test/test-utils'; | ||
| import { TodoProvider } from '../../lib/todo-context'; | ||
| import Home from '../home'; | ||
|
|
||
| renderWithRouter( | ||
| <TodoProvider> | ||
| <Home /> | ||
| </TodoProvider> | ||
| ); | ||
| // fire events, assert DOM/state | ||
| ``` | ||
|
|
||
| ## Bun Config (reference) | ||
|
|
||
| - **preload:** `test/setup.ts` via `bunfig.toml` | ||
| - **jsdom:** initialized in `test/setup.ts` (globals + `@testing-library/jest-dom`) | ||
| - **testTimeout:** Bun default is `5000`; adjust with `bun test --timeout <ms>` when needed | ||
|
|
||
| ## Commands | ||
|
|
||
| - `bun run test` – run tests | ||
| - `bun run test:watch` – watch mode | ||
| - `bun run test:run` / `bun run test:ci` – single run (CI) | ||
|
|
||
| ## Best Practices | ||
|
|
||
| - Prefer `getByRole`, `getByLabelText`, `getByPlaceholderText` over brittle selectors | ||
| - Use `jest.fn()` from `bun:test` for callbacks; assert calls and args | ||
| - Hoist repeated regex/selectors to describe scope to satisfy lint rules | ||
| - Keep tests focused; use multiple `it` blocks instead of one large test | ||
| - For forms: test validation, submit behavior, and error display (see lambda-curry-forms rules for FormError) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| --- | ||
| description: UI component conventions and shadcn/ui patterns | ||
| globs: packages/ui/**/*.tsx, packages/ui/**/*.ts, apps/**/app/**/*.tsx | ||
| alwaysApply: true | ||
| --- | ||
|
|
||
| # UI Component Rules | ||
|
|
||
| ## Component Structure | ||
| - Use forwardRef for components that need ref forwarding | ||
| - Implement proper TypeScript interfaces | ||
| - Use class-variance-authority for variant-based styling | ||
|
|
||
| ## shadcn/ui Patterns | ||
| ```tsx | ||
| // Component example | ||
| import * as React from 'react'; | ||
| import { cva, type VariantProps } from 'class-variance-authority'; | ||
| import { cn } from '@todo-starter/utils'; | ||
|
|
||
| const buttonVariants = cva( | ||
| 'base-classes', | ||
| { | ||
| variants: { | ||
| variant: { | ||
| default: 'default-classes', | ||
| destructive: 'destructive-classes' | ||
| }, | ||
| size: { | ||
| default: 'default-size', | ||
| sm: 'small-size' | ||
| } | ||
| }, | ||
| defaultVariants: { | ||
| variant: 'default', | ||
| size: 'default' | ||
| } | ||
| } | ||
| ); | ||
|
|
||
| export interface ButtonProps | ||
| extends React.ButtonHTMLAttributes<HTMLButtonElement>, | ||
| VariantProps<typeof buttonVariants> { | ||
| asChild?: boolean; | ||
| } | ||
|
|
||
| const Button = React.forwardRef<HTMLButtonElement, ButtonProps>( | ||
| ({ className, variant, size, asChild = false, ...props }, ref) => { | ||
| const Comp = asChild ? Slot : 'button'; | ||
| return ( | ||
| <Comp | ||
| className={cn(buttonVariants({ variant, size, className }))} | ||
| ref={ref} | ||
| {...props} | ||
| /> | ||
| ); | ||
| } | ||
| ); | ||
| Button.displayName = 'Button'; | ||
| ``` | ||
|
|
||
| ## Styling Guidelines | ||
| - Use Tailwind CSS classes for styling | ||
| - Leverage CSS variables for theming | ||
| - Use cn() utility for conditional classes | ||
| - Follow shadcn/ui color and spacing conventions | ||
|
|
||
| ## Accessibility | ||
| - Include proper ARIA attributes | ||
| - Ensure keyboard navigation works | ||
| - Use semantic HTML elements | ||
| - Test with screen readers | ||
|
|
||
| ## Component Organization | ||
| - Keep components in `packages/ui/src/components/ui/` | ||
| - Export all components from main index file | ||
| - Group related components together | ||
| - Use consistent naming conventions | ||
|
|
||
| ## Best Practices | ||
| - Prefer composition over complex props | ||
| - Keep components focused and reusable | ||
| - Document component APIs with TypeScript | ||
| - Test components in isolation |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix typo in project description.
Line 11: “reportory” is a typo and the phrasing is awkward.
✏️ Proposed wording fix
📝 Committable suggestion
🤖 Prompt for AI Agents