Testing
The Ellemment Stack provides comprehensive testing capabilities through multiple testing frameworks and tools.
End-to-End Testing with Playwright
Setup and Configuration
Tests are located in the tests
directory. Run tests in development:
npm run test:e2e:dev
Authentication Testing
Use the built-in login fixture for authenticated tests:
import { test, expect } from '@playwright/test'
test('user dashboard', async ({ page, login }) => { const user = await login() await page.goto('/dashboard') await expect(page.getByText(user.username)).toBeVisible() })
Test Isolation
Tests are automatically isolated with:
- Clean database state
- Auto-user deletion
- Independent environments
- Isolated browser contexts
Example E2E Test
test('user profile flow', async ({ page, login }) => { // Login const user = await login() ,[object Object], ,[object Object],
// Verify update await expect(page.getByText('Profile updated')).toBeVisible() })
Component Testing with Vitest
Configuration
// vitest.config.ts import { defineConfig } from 'vitest/config'
export default defineConfig({ test: { globals: true, environment: 'happy-dom', setupFiles: ['./test/setup.ts'], include: ['./app/**/*.test.{ts,tsx}'], }, })
Example Component Test
import { render, screen } from '@testing-library/react' import { describe, test, expect } from 'vitest' import { Button } from './button'
describe('Button', () => { test('renders with correct text', () => { render(<Button>Click me</Button>) expect(screen.getByText('Click me')).toBeInTheDocument() }) })
DOM Testing
Using @testing-library/jest-dom
for enhanced assertions:
test('accessibility features', () => { render(<Button aria-label="Submit">Send</Button>)
const button = screen.getByRole('button') expect(button).toHaveAccessibleName('Submit') })
Type Checking
TypeScript Integration
Run project-wide type checking:
npm run typecheck
Editor Setup
- Install TypeScript plugin
- Configure tsconfig paths
- Enable type checking
- Setup auto-complete
Code Quality Tools
ESLint Configuration
// .eslintrc.js module.exports = { extends: [ '@remix-run/eslint-config', '@remix-run/eslint-config/node', '@remix-run/eslint-config/jest-testing-library', ], rules: { // Custom rules }, }
Prettier Setup
// prettier.config.js module.exports = { semi: false, singleQuote: true, trailingComma: 'all', // Additional options }
Best Practices
Test Organization
- Group by feature
- Maintain test hierarchy
- Use descriptive names
- Keep tests focused
Test Coverage
- Critical paths
- Edge cases
- Error scenarios
- User interactions
Performance
- Parallel execution
- Test isolation
- Resource cleanup
- Efficient assertions
Maintenance
- Regular updates
- Clean test data
- Shared utilities
- Documentation
CI/CD Integration
GitHub Actions
name: Test
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
For more information about deployment configuration, see the deployment documentation. For monitoring setup, refer to the monitoring documentation.